Archived

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

vector gibberish.

This topic is 5752 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

I have no experience with vectors, so this is probably a simple question for most. My 3d game has an overhead, isometricish-style camera view with doesn''t change, but it can be zoomed in and out. The code below sets my Camera''s veiw vector permanently. What I''m having trouble with is this...I need a formula that can be given a y value along this vector, and I need it to solve for the z value at the same point along this vector. So like if I wanted to put something at a height of 25 on the y axis, yet have it centered in the middle of my screen, I''d need to slap it right on that view vector, so I''d need the corresponding Z value. ViewV.x = (float)(PositionV.x + cos(90.0*PI/180.0)); ViewV.z = (float)(PositionV.z + sin(200.0*PI/180.0)); ViewV.y = (float)(PositionV.y + cos(200.0*PI/180.0));

Share this post


Link to post
Share on other sites
I don''t quite follow the question. Your view vector should not include the position. Assuming the camera is at a position that is substantially more than a distance of one from the origin your view vector is going to basically point away from the origin. Your view vector is just a direction, not a position. It should have a magnitude of one.

The angles used in the trig functions might work, but it would generally make more sense to use something with some intuitive meaning. So using a real world example perhaps your compass direction and and inclination, i.e. you are pointing north and looking down at an angle of 45 degree with the horizontal. So say the xz plane is horizontal then perhaps a counter clockwise rotation from the x-axis. Pointing down the x-axis is 0 degrees, the z-axis 90 degrees, the negative x-axis 180 degrees, etc. Then y would be up and you would just have an angle up or down. If theta was the angle of rotation in the xz plane and phi your inclination then your vector would be (x,y,z)=(cos(theta)*cos(phi), sin(phi), sin(theta)*cos(phi)).

Now given that view vector it have a magnitude of 1. So if you want to find the position of a camera when you know the position of the object the camera is pointing at and the distance of that object from the camera then it is p(d)=p0-v*d where p0 is the position of the object, v is the view vector and d is the distance of the camera from the object. That works because the magnitude of the view vector is one so d*v has a magnitude (length) of d. You subtract because you want to be a distance of d away pointing at the object rather than on the opposite side of the object pointing away from it.

It isn''t clear to me where your x, y and z axis point nor why you used the view vector you did. Hopefully there is enough information for you to figure out precisely what you are trying to do.

Share this post


Link to post
Share on other sites
Thanks, that cleared up my misunderstandings, I have the problem cleared up now.

Much appreciated.

Share this post


Link to post
Share on other sites