Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Finding a point in 3D and rotating towards it

This topic is 5858 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, Iv''e got a problem. Consider this picture: http://www.demons.org.il/etus/images/car3d1.jpg I want to do two things: First of all, I want to find the coord of the point - to do that, I want that the mouse cursor will also be able to move along the Z axis - how do I do that? After the click had been made, Iv''e been given the coords of the point from the mouse. What I want to do now, is to rotate the car so it''ll face that point. Like this: http://www.demons.org.il/etus/images/car3d2.jpg How can I do that(and the mouse thing)? Thanks for your help(and sorry about the big pictures), Yuval

Share this post

Link to post
Share on other sites
Hi Etus

I am not to sure about the mouse thing, but I can help explain the technique in rotating your car toward the point you selected with the mouse.

The following code use functions from Power Render.

Here I am setting up my right vector which is all your car needs
The PR_Globals.Tvector is a user controled vector. What the PR_Transform function does is simply rotates my initial vector using the 3D objects matrix which is Pursuer->orientation.rot_mat. usually the matrix values change when I rotate the object such as your car. The new tranformed vector are stored in Rht1 point structure. You can also extract the each vector such as the forward, up, and right vectors from the objects matrix.

rht1.x = PR_Globals.tvector[0];
rht1.y = PR_Globals.tvector[1];
rht1.z = PR_Globals.tvector[2];

The location structure is my position in world space
The next function calculates the distance from your car to the X or target show in your picture.
Dist_To_Target = PR_Distance3D(Pursuer->orientation.location.x, Pursuer->orientation.location.y
, Pursuer->orientation.location.z , Target->orientation.location.x,
Target->orientation.location.y, Target->orientation.location.z);

Here I am calculating a normalize direction vector which is n
n.x = Target->orientation.location.x - Pursuer->orientation.location.x/Dist_To_Target;

n.y = Target->orientation.location.y - Pursuer->orientation.location.y/Dist_To_Target;

n.z = Target->orientation.location.z - Pursuer->orientation.location.z/Dist_To_Target;

Again I am using a PowerRender function of taking the dot product of my direction vector n and the Objects right vector

doty = PR_DotVect (&rht1, &n);

The following routine acts as a switch to change rotation direction of your car.

//Yaw Tracking
if(doty < 0)
yaw = -1;
yaw = 1;

Here is another Power Render function for getting the absolute value of a number in other words my number will always be positive.
doty = PRMATH_fabs(doty);

Here is the last equation before rotating your car you have the YawRate that is how fast your car will turn the yaw switch which determines the rotating direction and last the doty value that used to make the rotation transition smooth.

yaw_mod = YawRate*yaw*doty;

And finally the function used to rotate your car
PR_RotateEntity(Pursuer, 0, yaw_mod, 0);

The following is some Power Render code for transforming the objects initial velocity vector Fwd_Rev_vel by thePursuer->orientation.rot_mat maxtrix based the the previous rotation .

PR_Globals.tvector[0] = 0;
PR_Globals.tvector[1] = 0;
PR_Globals.tvector[2] = Fwd_Rev_vel;

The following function simply translate the objects position by and incremental value per frame.
PR_MoveEntity(Move,PR_Globals.tvector[0], PR_Globals.tvector[1], PR_Globals.tvector[2]);

Please understand the above code is based on the Power Render Graphics Engine syntax which I am using to explain the technique of rotating your car toward the point and travling to that point. I sure theres an equivalent set of functions in Directx , OpenGL or what ever engine your using to accomplish the same tasks.

This code is simplified version of a tracking algorithm that is set up for all three axis and alows the pursuing craft to move to the target on an intercept course as well as roll when the target craft is rolling.


[edited by - sovereign on November 4, 2002 12:01:35 AM]

[edited by - sovereign on November 4, 2002 12:02:39 AM]

[edited by - sovereign on November 4, 2002 12:03:20 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!