[solved] Getting The Camera's 'AimVector'
[solved] Getting The Camera's 'AimVector'
I'm trying to get the 'AimVector' for the camera which in essence would just be a vector3df() with values in the range of 0,0,0 and 1,1,1.
Basically I need to have a function that takes the current rotation of the camera and applies some maths then spits out a vector3df as described previously. I've done some research on this and I thing it needs to call Sin and Cos on the .X and .Y values but I'm not completely sure and I cant seem to figure out the correct combination on my own.
Any help here from the maths geniuses would be most appreciated.
Thank you for your time!
Basically I need to have a function that takes the current rotation of the camera and applies some maths then spits out a vector3df as described previously. I've done some research on this and I thing it needs to call Sin and Cos on the .X and .Y values but I'm not completely sure and I cant seem to figure out the correct combination on my own.
Any help here from the maths geniuses would be most appreciated.
Thank you for your time!
Last edited by kklouzal on Thu Aug 14, 2014 8:11 pm, edited 2 times in total.
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
will this give you what you are looking for?
Code: Select all
vector3df aimVector = camera->getTarget() - camera->getPosition();
aimVector.normalize();
Re: Getting The Camera's 'AimVector'
I don't actually have access to the camera as this is being ran on the server-side, I'm sure there is a way to get it with sin() cos() I just for the life of me cant figure it out.
I believe it its:
But what about the Z axis??
I believe it its:
Code: Select all
irr::core::vector3df CameraRotation();
irr::core::vector3df AimVector();
AimVector.X = Cos(CameraRotation.X);
AimVector.Y = Sin(CameraRotation.Y);
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
vector3df(cos(Y)*cos(X), sin(Y)*cos(X), sin(X))
Re: Getting The Camera's 'AimVector'
That is definitely not working :P
This is *almost* working, it seems to be quite inaccurate though, nor does it take into account the Z-Axis!
This is *almost* working, it seems to be quite inaccurate though, nor does it take into account the Z-Axis!
Code: Select all
irr::core::vector3df(cos(irr::core::degToRad(Rot.Y)), sin(irr::core::degToRad(Rot.X)), Rot.Z)
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
What about rotationToDirection?
http://irrlicht.sourceforge.net/docu/cl ... a19278474d
irr::core::vector3df cameraDir = rot.rotationToDirection();
http://irrlicht.sourceforge.net/docu/cl ... a19278474d
irr::core::vector3df cameraDir = rot.rotationToDirection();
Re: Getting The Camera's 'AimVector'
That's almost exactly the opposite of what I'm trying to do.
I want to input my rotation vector and output the forward vector.
EDIT::
Maybe it would help if I explained the context of what I'm trying to do. I'm trying to do a raytrace from the players position 1000 units out from where he is looking.
I only have access to the players position and the players rotation, based off that I should be able to get a "forward vector" to apply to the equation to figure out my ray's end position.
I want to input my rotation vector and output the forward vector.
EDIT::
Maybe it would help if I explained the context of what I'm trying to do. I'm trying to do a raytrace from the players position 1000 units out from where he is looking.
I only have access to the players position and the players rotation, based off that I should be able to get a "forward vector" to apply to the equation to figure out my ray's end position.
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
Entity has most graciously posted the highschool grade trig to solve this most simple issue I could not wrap my preschool sized brain around:
Code: Select all
core::vector3df(sin(core::degToRad(rot.Y)), -sin(core::degToRad(rot.X)), cos(core::degToRad(rot.Y))).normalize();
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
Did you try my solution? I still think it's the right answer.
vector3df::rotationToDirection() converts a rotation in euler angles (that's the way scene nodes store it) to a normalized direction vector.
If you want to do the opposite (as you said), you can try vector3df::getHorizontalAngle(), which converts a direction to a euler rotation.
vector3df::rotationToDirection() converts a rotation in euler angles (that's the way scene nodes store it) to a normalized direction vector.
If you want to do the opposite (as you said), you can try vector3df::getHorizontalAngle(), which converts a direction to a euler rotation.
Re: Getting The Camera's 'AimVector'
Foaly I tried to use rotationToDirection() but no matter how I use it when I visualize the raytrace the lines fly out in random directions. This is what I've got at the moment.
If I uncomment the first Forward and comment the second then the rays trace where I'm looking, but if I look up or down past 90 degrees then it starts to get very inaccurate. using rotationToDirection must require a different formula to get EndPos that I can't figure out.. -.-
Code: Select all
irr::core::vector3df Rot = GetOwner()->GetRotation();
irr::core::vector3df StartPos(GetOwner()->GetPosition().x(), GetOwner()->GetPosition().y(), GetOwner()->GetPosition().z());
//irr::core::vector3df Forward(sin(irr::core::degToRad(Rot.Y)), -sin(irr::core::degToRad(Rot.X)), cos(irr::core::degToRad(Rot.Y)));
irr::core::vector3df Forward = StartPos.rotationToDirection();
irr::core::vector3df EndPos = StartPos + (Forward * 1000);
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: Getting The Camera's 'AimVector'
This is what finally got perfect results:
Code: Select all
irr::core::vector3df Rot = GetOwner()->GetRotation();
irr::core::vector3df Forward = irr::core::vector3df(0, 0, 1);
irr::core::matrix4 m;
m.setRotationDegrees(Rot);
m.rotateVect(Forward);
irr::core::vector3df StartPos(GetOwner()->GetPosition().x(), GetOwner()->GetPosition().y(), GetOwner()->GetPosition().z());
irr::core::vector3df EndPos = StartPos + (Forward * 1000);
Dream Big Or Go Home.
Help Me Help You.
Help Me Help You.
Re: [solved] Getting The Camera's 'AimVector'
i didnt understand the question before........... here is another way to do it.
http://irrlicht.sourceforge.net/forum/v ... in#p288921
in your case your would just use getPosition() as the start of the line, and getIn() * 1000 as the end.
http://irrlicht.sourceforge.net/forum/v ... in#p288921
in your case your would just use getPosition() as the start of the line, and getIn() * 1000 as the end.