Harry
Member
|
[Partially Solved]Moving object according to camera matrix
Hi,
I want to move object like it is in Editor. I have no problem with x axis, but I don't know how do the same with z axis. I tried this:
Code:
targetPos+=Cam.matrix.z*Ms.d().y*10;
but it seems it doesn't work ok. What I'm doing wrong?
(This post was last modified: 09-24-2012 10:45 PM by Harry.)
|
|
09-20-2012 06:03 PM |
|
Dynad
Member
|
RE: Moving object according to camera matrix
perhaps use time instead?
targetPos+=Cam.matrix.z*Time.d()*10;
dunno if Time.d() is delta.. u should check that
There is always evil somewhere, you just have to look for it properly.
(This post was last modified: 09-20-2012 07:14 PM by Dynad.)
|
|
09-20-2012 07:08 PM |
|
Harry
Member
|
RE: Moving object according to camera matrix
Yes if I use Time.d() it will work but it moves object constantly when a keyboard/mouse button is pressed. And I want move object when I press a mouse button and then move the mouse.
|
|
09-20-2012 07:58 PM |
|
Rubeus
Member
|
RE: Moving object according to camera matrix
What are the symptoms of it not working? Is it a matter of transforming the mouse delta by the camera matrix before scaling and adding?
|
|
09-20-2012 11:27 PM |
|
Dynad
Member
|
RE: Moving object according to camera matrix
(09-20-2012 07:58 PM)Harry Wrote: Yes if I use Time.d() it will work but it moves object constantly when a keyboard/mouse button is pressed. And I want move object when I press a mouse button and then move the mouse.
Use a simple if/else statement? U have to use a button if u want to use 3 axis.. since a mouse has only x and y..
if(button x = pressed) targetPos+=Cam.matrix.z*Ms.d().y*10;
else targetPos+=Cam.matrix.y*Ms.d().y*10;
There is always evil somewhere, you just have to look for it properly.
|
|
09-21-2012 09:58 AM |
|
Harry
Member
|
RE: Moving object according to camera matrix
Here is my whole code for an object moving:
Code:
....
if(Ms.b(1)){
Ms.freeze();
if(Kb.b(KB_LCTRL))msg.target[i].targetPos[j].y+=Ms.d().y*10;
else {
msg.target[i].targetPos[j]+=Cam.matrix.x*Ms.d().x*10;
msg.target[i].targetPos[j]+=Cam.matrix.z*Ms.d().y*10;
}
}
....
When I comment msg.target[i].targetPos[j]+=Cam.matrix.z*Ms.d().y*10; an object moves properly in x axis. However, this code: Cam.matrix.z*Ms.d().y*10 causes the object moves in y an z axis. I'm not sure if I'm using correct matrix members because I always have problem with transformations on matrix. The only thing I'm sure is that there shouldn't be used Cam.matrix.z.
EDIT: targetPos.z+=Cam.matrix.z.z*Ms.d().y*10; - this seems working almost ok, but I'm not sure it is this the way it should be done. I think I need read more about these right, up and forward vectors in matrix
(This post was last modified: 09-21-2012 02:39 PM by Harry.)
|
|
09-21-2012 10:39 AM |
|
Harry
Member
|
RE: Moving object according to camera matrix
Could someone give me a clue what to do to make it work ok?
|
|
09-23-2012 06:43 PM |
|
Rubeus
Member
|
RE: Moving object according to camera matrix
Vec Move(0);
Move.set(Ms.d().x*Time.d()*10, 0, Ms.d().y*Time.d()*10);
Move *= Cam.matrix.orn();
targetPos += Move;
This should work, I think. It looks like what you are doing is multiplying cam.matrix.x by Ms.d().x which is a float times a float, and doesn't serve to actually rotate your vector to the camera's orientation. By multiplying the vector against the rotation matrix(.orn()), you rotate the vector to the same orientation that the camera is at.
The above code makes the y movement of the mouse move targetPos on the z access. Change the second line to Move.set(Ms.d().x*Time.d()*10, Ms.d().y*Time.d()*10, 0); if you want the mouse y to correspond to world y.
(I think it's all correct, I don't have access to my project to test it right now)
Is that what you needed?
|
|
09-23-2012 10:47 PM |
|
Harry
Member
|
RE: Moving object according to camera matrix
Unfortunately it works almost the same as my codes. In x axis it works ok (because Cam.roll is 0), and in z, object moves in all axes (when Cam.pitch!=0).
EDIT: I look closer how change rotation matrix when I change Camera pitch and I create something like that:
Code:
targetPos+=Cam.matrix.x*Ms.d().x*(Kb.b(KB_LSHIFT) ? 1 : 30); targetPos+=Vec(Cam.matrix.z.x,0,Cam.matrix.z.z)*Ms.d().y*(Kb.b(KB_LSHIFT) ? 1 : 30);
It works ok only when Camera roll is set to 0 but or me it's sufficient.
Anyway, if someone will know how to do that to be more universal or Rubeus will have access his project it will be appreciated to share it with other users
|
|
09-24-2012 10:44 PM |
|
Rubeus
Member
|
RE: [Partially Solved]Moving object according to camera matrix
I just checked my code... the only difference I have in mine is that I use keystrokes instead of mouse alpha, and I use it to give me a free-floating first person debug cam. I guess you could try alternatively getting the mouse position and the previous position and use the built in screen to world coordinates function on them both, then subract to get a movement vector you could directly add to your targetPos....
|
|
09-25-2012 06:51 PM |
|