In main loop I update camera position to match object position. I use FPS camera, so I have mouse movements cooked for me. But that doesn't suit for keys, and I have to manually move object with keys.
Well, I can move object forward and backward very easy, because I can just get camera position and target. But how will I get left or right strafe vectors?
Thanks.
How to find strafe vectors?
How to find strafe vectors?
Open Source all the way, baby
OSRPG
OSRPG
it turned out that if (x, y) is my forward vector, then (-y, x) is the left vector
Open Source all the way, baby
OSRPG
OSRPG
-
- Posts: 78
- Joined: Sat May 27, 2006 9:24 pm
- Location: Logan, UT
That one Irr modder who make a library and has a funny stickfigure avatar has some good code for what you want. Here, I use it myself:
You can't just copy-n-paste-n-compile, but the basic ideas are there. Having these vectors makes it so much easier to implement your own camera movement. Gah I wish I could remember his nick, Spintz?
Code: Select all
irr::core::vector3df WorldUpVector = irr::core::vector3df( 0.0f, 1.0f, 0.0f );
irr::core::vector3df cameraPosition = GetCamera()->getPosition();
irr::core::vector3df cameraTarget = GetCamera()->getTarget();
// Compute new forward vector
irr::core::vector3df forwardVector = cameraTarget - cameraPosition;
// Set the Y to 0 so the vectors are calculated on the XZ plane
forwardVector.Y = 0.0f;
forwardVector.normalize();
// Compute new right vector
irr::core::vector3df rightVector = WorldUpVector.crossProduct ( forwardVector );
rightVector.normalize();
// Compute new up vector
irr::core::vector3df upVector = forwardVector.crossProduct( rightVector );
upVector.normalize();
You can't just copy-n-paste-n-compile, but the basic ideas are there. Having these vectors makes it so much easier to implement your own camera movement. Gah I wish I could remember his nick, Spintz?
Stout Beer
Thanks, Mikenoworth.
But all this works only when camera was created as FPS one. When I create basic one, instead of moving left/right it turns around center :/
How to make it move, not turn?
Thanks.
But all this works only when camera was created as FPS one. When I create basic one, instead of moving left/right it turns around center :/
How to make it move, not turn?
Thanks.
Open Source all the way, baby
OSRPG
OSRPG
Ok lets say ur character is standing still at the beginning with a rotion of 0° degrees around the y(up)-axis. then u cpul dfor exampel say that:
0 0 1 is forward
0 0 -1 is backward
1 0 0 is strafe right
-1 0 0 is strafe left
this works as long you don't rotate your character but i guess u want to turn him as well therefor u use a matrix. simply do:
irr::core::matrix4 mat;
mat.setRotationDegrees(the rotation of the character around the Y-Axis)
mat.transform(forward);
mat.transform(backward);
mat.transform(strafe right);
mat.transform(strafe left);
and tada it works
0 0 1 is forward
0 0 -1 is backward
1 0 0 is strafe right
-1 0 0 is strafe left
this works as long you don't rotate your character but i guess u want to turn him as well therefor u use a matrix. simply do:
irr::core::matrix4 mat;
mat.setRotationDegrees(the rotation of the character around the Y-Axis)
mat.transform(forward);
mat.transform(backward);
mat.transform(strafe right);
mat.transform(strafe left);
and tada it works
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Posts: 4
- Joined: Mon Jun 02, 2008 6:33 pm
Hello ppl
I realize this thread is a year old but I just started using Irrlicht and since this was confusing me and couldn't find it anywhere in the forums, I thought I should post it in case someone else is confused by it too. I also JUST figured out how to do this the way I wanted it to work.
so therefore...
if you want to rotate the camera... you still gotta figure that out
ps: this is my first post evah!
I realize this thread is a year old but I just started using Irrlicht and since this was confusing me and couldn't find it anywhere in the forums, I thought I should post it in case someone else is confused by it too. I also JUST figured out how to do this the way I wanted it to work.
all you do is move the camera target by the vectors that you move the camera position by.But all this works only when camera was created as FPS one. When I create basic one, instead of moving left/right it turns around center :/
How to make it move, not turn?
so therefore...
Code: Select all
irr::core::vector3df WorldUpVector = irr::core::vector3df( 0.0f, 1.0f, 0.0f );
irr::core::vector3df cameraPosition = GetCamera()->getPosition();
irr::core::vector3df cameraTarget = GetCamera()->getTarget();
// Compute new forward vector
irr::core::vector3df forwardVector = cameraTarget - cameraPosition;
// Set the Y to 0 so the vectors are calculated on the XZ plane
forwardVector.Y = 0.0f;
forwardVector.normalize();
// Compute new right vector
irr::core::vector3df rightVector = WorldUpVector.crossProduct ( forwardVector );
rightVector.normalize();
// Compute new up vector
irr::core::vector3df upVector = forwardVector.crossProduct( rightVector );
upVector.normalize();
// Then to "slide" the camera to the right and change camera target to move with it
GetCamera->setPosition( GetCamera->getPosition() + rightVector);
GetCamera->setTarget(GetCamera->getTarget() + rightVector);
ps: this is my first post evah!
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
You popped your post cherry by sharing knowledge? I think I love you. Let's hug. Good touch hug.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way