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 / position object allways in front of camera without chaning orientiation (no dbLockObjectOn)

Author
Message
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 15th Jun 2008 14:52 Edited at: 17th Jun 2008 21:32
How can I update the position of an object, so it is allways visible at the same position relative to the camera and keeps its original orientation.
I read that you can lock it to the screen with dbLockObjectOn but then it rotates with the camera. I dont want that.
Any hints?
Do I have to use cos, sin?


[SOLVED]

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Jun 2008 19:30
Here's how



Don't you just hate that Zotoaster guy?
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 15th Jun 2008 22:23
thanks! I tried that and the object moves when I rotate the camera but it is too slow.
How did you derive those equations?
I just remembered homogenous transformation matrices.
I will try to multiply:
- a translation for the distance from camera to object
- a rotation around x axis
- a rotation around y axis
- and a translation from world co-ordinate system (0,0,0) to camera position.
Then I will see whether I get the same equations.
I still dont remember though.. there was something about Euler and Roll-Pitch-Yaw systems and the order in which to multiply those matrices...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Jun 2008 22:56
I haven't done matrices in a while, and even then I only used them in a 2D scenario.

Forget X rotation, and only concentrate on Y:

x = origin_x + sin( angle ) * distance
z = origin_z + cos( angle ) * distance

This makes sense when you look at the waves. When 'angle' = 0, sin( angle ) = 0, cos( angle ) = 1, so you move forward. When 'angle' = 90, sin( angle ) = 1, cos( angle ) = 0, so you move sideways.

When you multiply the x and z values by the cos() of the x angle, you get a similar result. When you are facing forward (angle = 0), cos( angle ) = 1, so you move forward. When you are facing up or down (angle = 90 or 270), you will be moving up, so no forward movement. cos( angle ) = 0

Then all you have to do is affect the y movement. When you move forward you don't want any y movement, at angle = 0. sin( 0 ) = 0, so no y movement. When you face down your angle is 90, sin( 90 ) = 1, but you want it to be -1, so you simply negate it.

That's how I got those equations.

Don't you just hate that Zotoaster guy?
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 16th Jun 2008 09:38
I am trying to do the matrix multiplication now.
There are two co-ordinate systems: world co-ordinate system (WCS) and camera co-ordinate system (CCS).
1. Translation along WCS axes to have object in front of camera: T_w_d
2. Since WCS and CCS are still congruent it doesnt matter, so: Rotation around WCS x axis: R_w_x
3. Now they aren't congruent any more, so: Rotation around CCS y axis. R_c_y
4. Translation to camera position along WKS axes: T_w_c

The question is the order of the matrices. I think it is:
T_w_c * R_w_x * T_w_d * R_c_y
1,2,4 are roll-pitch-yaw
3 is Euler

Hope this is right.
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 16th Jun 2008 10:44 Edited at: 16th Jun 2008 17:36
nooooooo this is killing me. I cant get it to work. Please guys and girls, you have to help me out here!

What is wrong with this. No matter how I arange those matrices it doesnt work.
And why do I even get different results when reordering them? Its driving me nuts.

Those are my matrices


Why cant I do
T_c * R_x * T_d * R_y
or
T_c * R_x * R_y * T_d
and take the translational part as pos_x, pos_y and pos_z?
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 16th Jun 2008 20:25
You make me feel stupid.

If you can do any models for FW, reply to the FleetWars thread.

Click here!
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 16th Jun 2008 21:39 Edited at: 17th Jun 2008 16:25
zuka those are homogenous transformation matrices. They are a great way for calculating rotation, translation and even scaling and perspective. The great thing about them is, you can multiply them to apply multiple transformations at once. You cant do that with normal cartesian transformation matrices.
With those matrices I want to calculate where to draw the object so it is allways in front of the camera at a fixed position relative to the camera.
So I would like to take the origin of the global (world) co-ordinate system, translate it by a vector (distCamX, distCamY, distCamZ). Thats what the matrix T_d does when you map a point P with it. In the picture I accidently switched the names of T_c and T_d :p d for dist, c for camera...

T_d * P. If you try this, you will see that a point/vector P has one coordinate too little. You have to make it a "homogenous" coordinate first. You do that by adding a 1 as the 4. coordinate. (0,0,0) becomes (0,0,0,1). Now you can multiply the the matrix T_c and the point P.
When you do this with the point (0,0,0) resp (0,0,0,1) you get to the point (distCamX, distCamY, distCamZ, 1).
I hope they dont mind me hotlinking:

To get back the original cartesian coordinate/point you simply divide by the 4. coordinate wich is 1 in this case (it is most of the time).

So far this is like with cartesian transformations (even more work). But the homogenous transformations come handy when you want to do multiple transformations.
So after translating the origin (0,0,0) to (distCamX, distCamY, distCamZ) I want to rotate around the x and y axis of the camera. I can do this with homogenous rotation matrices.

This matrix rotates around the x axis by A degrees.


I only need x and y. Thats what R_x and R_y are for.
One can do those steps in one because the matrices can be multiplied.
So if you multiply the matrices T_d, R_x and R_y, take the resulting matrix and multiply a vector with it. The vector is translated and rotated around x and y axis at once.
Since I want all this to happen at the current camera positon I do another translation with T_c. So I get the resulting transformation matrix by doing:
T_c*T_d*R_x*R_y

Why T_c at first? Because the order matters. (Matrix multiplication is not commutative)
It makes a difference whether I multiply a transformation from the left or from the right side.
From left: the transformation is done relative to the world co-ordinate system (WcS) axes. Those are fix. They never move nore rotate.
From right: the transformation is done relative to the new (formerly rotatet or moved/translated object co-ordinate system (or camera co-ordinate sytem in my case (OCS/CCS))

I find it easy to start a transformation with the identity Matrix I. Which does nothing

Try to multiply a homogenous vector with it. Nothing happens.
Now multiply the first transformation matrix. Since nothing happened yet it doesnt matter whether you multiply it to the right or to the left. But I find it easier to multiply it to the left, because the WCS is the only co-ordinate system (CS) in the beginning (or at least the wCS and the OCS/CCS are the same).
So because I want to translate to (distCamX, distCamY, distCamZ) I multiply

from the left: T_d * I

Now I want to rotate around the x axis of the camera (which is the object). So I multiply from the right.
T_d * I * R_x
Same for rotation around y. Now this time is the first time it would actually make a difference whether I multiplied from the left or right. Because after rotating with R_x around the x axis of the object you have to different CS. One for the world (WCS) and one for the object/camera (OCS/CCS). After rotating around the x axis, the two x axes still point in the same direction, but the y and z axis doesnt. So if I want to rotate around the y axis of the object/camera (which I do) I have to multiply from the right.
T_d * I * R_x * Ry

Last step is to bring everything to where the camera is with T_c

Since the camera position is given in world co-ordinates I have to translate along the axes of the WCS. Hence I have to multiply from the left:
T_c * T_d * I * R_x * Ry

There are other orders of multiplication that should lead to the same result.

If I multiply (0,0,0,1) with the resulting matrix I _should_ get to a position that lies at (distCamX, distCamY, distCamZ) in front of the camera.
But since I dont you shouldnt take my word for it
And if anyone spots an error in this... that would be great!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 16th Jun 2008 21:45


That's all very nice and all, but I think I'll stick to my


Don't you just hate that Zotoaster guy?
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 17th Jun 2008 13:08
zotoaster did you try it? that does not work for me
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 17th Jun 2008 18:31 Edited at: 17th Jun 2008 18:32
I found the 3DMaths commands.
No I am trying it this way:

positionX, -Y and -Z are allways 0 though..
Anyone ever worked with these? I dint find anything on the form...
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 17th Jun 2008 18:33
Quote: "You make me feel stupid."


Seconded. I need to brush up on my math.
manu
16
Years of Service
User Offline
Joined: 7th Jun 2008
Location:
Posted: 17th Jun 2008 18:48
When I read from vector 0 after setting it to (CSDistX, CSDistY, CSDistZ, 1.f ) I correctly get the values CSDistX, CSDistY, CSDistZ. But if I apply the transformation, all values in vector 1 are 0.

And in case I didnt mention I get a buffer overrun on exit once again.

Login to post a reply

Server time is: 2024-11-20 13:24:46
Your offset time is: 2024-11-20 13:24:46