X_GETCAMERAMATRIX

Previous topic - Next topic

MrTAToad

What values are stored in 16 entry record for this command ?

mentalthink

HI MrTatoad, I have this same question?¿, I think are the 3 translations, but the Scaling I´m not sure..., I think can be Scaled a Camera, in 3d max can be do... but those are the shape of the cone... more stretched or more rectangle.

Slydog

#2
I wasn't even aware of this command, is this something new?  (I'm still using 10.179)

If it is similar to the 'X_GETMATRIX' command (which retrieve's the current camera's transformation matrix), this function (from my TEntity TYPE) may help:

Code (glbasic) Select
FUNCTION LookAt: v AS TVector
LOCAL v_at AS TVector
LOCAL v_up AS TVector
LOCAL v_xaxis AS TVector

v_at = v.Subtract(self.position)
v_at.Normalize()

v_up.Set(0.0, 1.0, 0.0)
v_xaxis = v_at.CrossProduct(v_up)
v_xaxis.Normalize()
v_up = v_xaxis.CrossProduct(v_at)
v_up.Normalize()

DIM self.matrix[16]
self.matrix[ 0] = v_xaxis.x
self.matrix[ 1] = v_xaxis.y
self.matrix[ 2] = v_xaxis.z
self.matrix[ 3] = 0

self.matrix[ 4] = v_up.x
self.matrix[ 5] = v_up.y
self.matrix[ 6] = v_up.z
self.matrix[ 7] = 0

self.matrix[ 8] = v_at.x
self.matrix[ 9] = v_at.y
self.matrix[10] = v_at.z
self.matrix[11] = 0

self.matrix[12] = self.position.x + 0.0
self.matrix[13] = self.position.y + 0.0
self.matrix[14] = self.position.z + 0.0
self.matrix[15] = 1
ENDFUNCTION


The first four values are the x-axis vector, then then up vector, then the 'look at' vector, then the object position. 
I'm not sure about positions 3, 7, 11, and 15, but *may* be related to scale and/or skewing.
I use the above matrix (before 'X_DRAWOBJ') to alter the transformation with the 'X_MULTMATRIX' command.

[Edit] I should point out that my game doesn't use the above code, so I'm not even sure if it works. 
It was something I was trying near the beginning of my game.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

MrTAToad

It was introduced a couple of updates ago.  It's quite possible its the same format as GETMATRIX especially as the array size is the same for both.

Kitty Hello

Yes. It's a matrix as in X_GETMATRIX.

FutureCow

#5
So am I correct about the way to use this? :

If I have rotated my camera and then move it, after moving it I run a X_getcameramatrix and store the value in an array (eg. "cam[]")
The next frame I run
Code (glbasic) Select
x_cameraup cam[4],cam[5],cam[6]
x_camera cam[12],cam[13],cam[14],cam[8],cam[9],cam[10]


Assuming that's correct, how do I then align the camera with the x-axis returned earlier so that I can then move the camera relative to the new orientation? I can't see that x_movement works with the camera, it looks like I've got to use x_camera and it uses absolute coordinates.
I'm guessing I have to do some sort of matrix calculation to multiply/add this matrix against another???

kanonet

I played around with this command some weeks ago (see my X_SPRITE replacement code) and if i remember right, all values are correct, but not [12] [13] [14], you would expect them to contain camera position, but they dont do, just 'random' data. I have no idea why, talked to Gernot, but we couldnt find a way to get camera position with X_GETCAMERAMATRIX.

But you have a small error in your sample, if values [12] [13] [14] would be correct, your samplecode would need to be:
Code (glbasic) Select
x_cameraup cam[4],cam[5],cam[6]
x_camera cam[12],cam[13],cam[14],cam[12]+cam[8],cam[13]+cam[9],cam[14]+cam[10]


Yes, X_CAMERA and ..UP replace X_MOVEMENT and other commands, all needs to get done this way.
About your matrix manipulation, look in the Entitysystem, it does a bit more than necessary, but you will see and learn how to do this stuff.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64