x y points & plane equation

Started by
3 comments, last by bobason456 18 years, 9 months ago
Hello, I'm trying to find the world space 3d cord of a 2d point on a plane where only the planes normal is known. I've been using the plane equation, but with out much luck. AX + BY + CZ + D = 0 The normal is the normalized camera position. So this plane will always face the viewer, further it's location is at 0,0,0 so given this I thought to ignore D, in the above equation. Then just solve for Z Z = - (AX + BY) / C The problem with this is that as C goes to zero Z gets very large. and before zero I seem to be getting a plane that goes a little skewd. Here is my code.

x = cos(frameAngle*piover180);
y = sin(frameAngle*piover180);
z = -(x*p[0] + y*p[1])/p[2];
glVertex3f(0, 0, 0);
glVertex3f(x, y, z);
frameAngle++;
if(frameAngle>360) frameAngle = 0;

Does any one know of a different, method to do this, or comments or sujestions would he much appritiated.
Advertisement
Quote:Original post by bobason456
Hello, I'm trying to find the world space 3d cord of a 2d point on a plane where only the planes normal is known.


This is not possible. There are an infinite number of planes with that normal. Not only that, but there are an infinite number of possible orientations of the 2D coordinate system on the plane. You need more information.

Edit: After further reading, it seems that you do have more information.

Apparently, the plane goes through the origin, so the value of D is 0 (as you assumed). Since you are talking about a camera, it must have an "up" vector. That is sufficient.

However a camera usually has an orientation. You can get your answer simply by transforming the point [x, y, 0] by the camera's orientation matrix.



[Edited by - JohnBolton on July 10, 2005 2:52:26 PM]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Hi, this post follows on from a previous question about camera orientation. But it looks like I've gone off on the wrong track.

Here is what I'm trying to do, I have a small sphere that is the "world", I want to place the camera on the surface of the sphere, I have x,y,z cords position of the camera. The sphere is always centered at 0,0,0. So the up vector is going to be the cam normalized(x*2,y*2,z*2). And I'm trying to find a eye vector that is a right angle to the up vector.

Id also like to be able to rotate other objects in this way.. so they can point "down" toward 0,0,0 and be rotated about the axis that goes "up" through the center of them.

So for example, I have a bunch of tree objects. The bottom of them need to point toward the center of the world regardless of where they are. Once I can do that the heading is no problem as I can use the normalized x,y,z as an axis for arbitrary rotation.
Quote:Original post by bobason456
Hi, this post follows on from a previous question about camera orientation. But it looks like I've gone off on the wrong track.

Here is what I'm trying to do, I have a small sphere that is the "world", I want to place the camera on the surface of the sphere, I have x,y,z cords position of the camera. The sphere is always centered at 0,0,0. So the up vector is going to be the cam normalized(x*2,y*2,z*2). And I'm trying to find a eye vector that is a right angle to the up vector.


For the position normalizing the camera position and scaling it back to your world sphere radius should be enough. From the whole description of your problem I have the impression that you want the (edit) camera to look at the origin. If so you are not looking for an eye vector perpendicular to the up vector (unless you are talking in camera space and not in world space). The eye vector would simply be -cam_pos.Normalize(). I don't understand the bit about "[...] the up vector is going to be the cam normalized (x*2,y*2,z*2)".

Quote:
Id also like to be able to rotate other objects in this way.. so they can point "down" toward 0,0,0 and be rotated about the axis that goes "up" through the center of them.


You look like you could use a lookat function [smile].
I can post one if you want, or explain how to make one (copy/paste from my post in the "Inverse plane matrix" thread).

Quote:
Once I can do that the heading is no problem as I can use the normalized x,y,z as an axis for arbitrary rotation.


This is not clear. Are you talking about banking? Heading and pitch are locked onto the origin.
Praise the alternative.
Thanks.. I have it sorted now.. but not perhaps the best way. I had the function before but had trouble getting it around it. So I had my camera calculate longitude and latitude from the center of world to the cam location.

Then did all the needed rotations, should work for objects also once I get convert_xyz2llr out of the cam class. Thanks for your help.

// In my cam class I call this method on every update.void CCam::convert_xyz2llr(void){	r = sqrt(x*x + y*y + z*z);	lon = 180-atan2(z,x)*57.2957795;	lat = 90-(acos ( y / r )*57.2957795);}.....// Then when I go to render, we can rotate the cam base on the mouse moves// lookupdown / heading.// Then by the longitude and latitude	glRotatef((mainWnd->cam1.lookupdown),1.0f,0,0);		glRotatef((-mainWnd->cam1.heading),0,1,0);		glRotatef(mainWnd->cam1.lat-90,0,0,1);		glRotatef(-mainWnd->cam1.lon,0,1,0);

This topic is closed to new replies.

Advertisement