Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Override camera world matrix

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 1st Dec 2012 00:10
Hello everyone,

I'm trying to override the camera's world matrix. The problem is that it doesn't seem to do very much (although it's rotating a little).

I know my matrices are correct, because I'm overriding my objects' world matrices using them, eg.


Now, I want to apply the exact same world matrix to the camera, which should position and rotate the camera to the object.

I'm using this camera struct which Diggsey posted some time ago:



And I'm applying the world matrix as such:



As I said, I'm getting some slight rotation, though very little. The position doesn't seem to be changing at all.

I've tried manually positioning and rotating the camera to the object, however converting the rotation matrix to euler angles seems to break it. Using dbSetCameraToObjectOrientation() doesn't work either, as the objects' internal data is overridden.

Does anyone have any ideas as how to make this work?

Thanks in advance

"everyone forgets a semi-colon sometimes." - Phaelax
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Dec 2012 03:48
The view matrix of a camera is the inverse of the world matrix that would put an object at the same position and orientation as that camera. Try inverting the matrix before you assign it

[b]
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 1st Dec 2012 15:35
By the wording of your reply it sounds like you're trying to position an object at the camera, not the other way around. But I tried it anyway, it doesn't work, so I've got something wrong somewhere.

Here's what I've done:


The only way I get any effect on the camera is if I apply it to the camera's matOverride field; I tried that as well, but I get a similar result to last time.

"everyone forgets a semi-colon sometimes." - Phaelax
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Dec 2012 03:31 Edited at: 2nd Dec 2012 03:31
No, I'm saying that the "matOverride" field is a view matrix not a world matrix, and the view matrix is the inverse of the equivalent world matrix.

You said it has some effect but not much? What happens if you set the matrix to some test values (ie. looking down X axis, looking down Z axis, etc.)

[b]
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 2nd Dec 2012 10:10
I'm not sure what you are trying to accomplish, but the camera's view matrix is not as simple as an inverse world matrix. If you are going to override the camera, you can use Diggsey's structure as above, but you need to build the view matrix. There are plenty of methods on the net describing this process. If you are trying to override because you want to use quaternion instead of eular rotation, you should look at this:
http://www.silverwaregames.com/blog/?p=195
It's a place to start. I don't remember the PAINSTAKING process I had to go through to find one that I could use, but this might help you. The output of the "GetViewMatrix( )" function will give you what you will need to update the camera.

The fastest code is the code never written.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 2nd Dec 2012 15:13
Quote: "I'm not sure what you are trying to accomplish, but the camera's view matrix is not as simple as an inverse world matrix."


I'm sorry but that's exactly what a view matrix is.

There are three matrices Direct3D uses: world, view, projection. These are multiplied together to give a single matrix used to transform 3d vertex positions into screen space coordinates.

The world matrix transforms from coordinates local to an object into coordinates in the 3d world.

The view matrix then transforms coordinates from the 3d world to local to a camera (hence being the inverse of a world matrix).

Finally the projection matrix converts coordinates local to a camera to screen coordinates (ie. a standard perspective projection makes things further away appear smaller)

[b]
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 3rd Dec 2012 08:37
The world matrix is for objects.
The view matrix is for the camera orientation.
The projection matrix is how the camera "sees" the world.

To say the world matrix is the inverse of the view matrix is functionally incorect. Yes, the view matrix has some aspects of its own world matrix (inverted), but they are not the same animal.

It takes all 3 to render an object to the screen. The initial problem was not the semantics of what the different matrices are, but how to manipulate the camera. Zotoaster still hasn't clarified how he wants to manipulate the camera.......

The fastest code is the code never written.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Dec 2012 09:41
Quote: "I know my matrices are correct, because I'm overriding my objects' world matrices using them, eg."


Quote: "Now, I want to apply the exact same world matrix to the camera, which should position and rotate the camera to the object."


The view matrix to get the camera to appear at the same position and orientation as an object is exactly the same as the inverse of the world matrix of that object. How the camera is going to be manipulated is irrelevant.

Quote: "To say the world matrix is the inverse of the view matrix is functionally incorect. Yes, the view matrix has some aspects of its own world matrix (inverted), but they are not the same animal."


The view matrix has every aspect of an inverted world matrix, not just "some", and it doesn't have any other aspects. The only difference between them is that one is used with a camera and the other is used with an object

[b]
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 3rd Dec 2012 15:00
If that's all he wanted, then why doesn't he use the camera as normal?

The fastest code is the code never written.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 3rd Dec 2012 20:23
Hello everyone, sorry for not responding in a while.

I'm on my Macbook just now so I'll have to mess around with the view matrix later on.

Hawkblood, originally that was my idea. But getting euler angles from a world matrix isn't that simple, however, DX gives you a command that can decompose it into position, rotation and scale. The rotation is a quaternion which takes some pretty elaborate code to turn into euler angles. These don't seem to be correct however, and my maths skills aren't good enough to figure out why, though I'm pretty sure the code I got from the internet was correct. I also tried pointing the camera to a point infront of the object (since every object in my system has a forward vector, this was pretty easy). However, rotating the camera round the Z axis became a problem, which I tried to solve my projecting the camera's and the object's current up vector onto a 2d plane so I could measure the angle between them, but everything got too complicated at that point and I figured there must be a simpler way.

I'll get back to you with any progress I've made with the view matrix.

"everyone forgets a semi-colon sometimes." - Phaelax
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 5th Dec 2012 18:48
Are you wanting full flight? If so, the post I made earlier showing the quaternion camera is a good place to start.

I use something like this:

Any code examples you find (and they are hard to find), will be confusing, but this is about as simplified as I can make it. There's not a lot to the actual "math" part.....

Making another object "point at" a location is another part. You would have to do something like this:

Once again, the RotationMatrix would be applied to the object's matrix.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-18 21:40:25
Your offset time is: 2024-11-18 21:40:25