(solved) finding three points for a plane

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
deanh22a
Posts: 23
Joined: Thu Feb 08, 2007 11:08 pm

(solved) finding three points for a plane

Post by deanh22a »

I'm trying to find three points so I can create a plane out of them. My origin point is the position of a node (location1), and I want the plane to be aligned with direction the node is facing. So if the node is rolled sideways or facing up or down, the plane will go up and down. if the node is just evened off with no rotation, the plane will be horizontal, etc.

I tried to find the other points with something like this, but I can't get it to work right:
location1 = node->getAbsolutePosition();
location2 = location1;
location3 = location1;

vector3df distance = vector3df(0,0,5000);
vector3df rotation = node->getRotation();
irr::core::matrix4 m;

m.setRotationDegrees(rotation);
m.transformVect(distance);
location2 += distance;
Last edited by deanh22a on Fri Feb 16, 2007 2:09 am, edited 1 time in total.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

A plane is described by a point which is the distance from the origin and a normal. So for a horizontal plane which the node is on, you would use the nodes absolute position and the normal ( 0, 1, 0 ).
Last edited by Spintz on Sun Mar 04, 2007 2:38 pm, edited 1 time in total.
Image
deanh22a
Posts: 23
Joined: Thu Feb 08, 2007 11:08 pm

Post by deanh22a »

Spintz wrote:A plane is described by a point which is the distance from the origin and a normal. So for a horizontal plane which the node is on, you would use the nodes absolute position and the normal ( 0, 1, 0 ).
I'm not trying to make a horizontal plane... the plane is horizontal relatively to the node, but absolutely it will change depending on the rotation of the node.


i suppose I COULD do it by parenting 2 empty nodes to that node and make sure the relative Y for both of those are 0. then i can use the absolute positions of those two nodes as my points, but surely there's a quick matrix calculation I could use instead.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Spintz told you exactly what you needed to know, you just probably don't know enough to help yourself with that information.

He told you a plane is a point which is the distance from the origin and a normal. The point is actually a point in the plane. Just for giggles, say that the 'point' is the absolute position of the node. Now all you need to do is calculate the normal for the plane. You want the plane normal to be related to the orientation of the node. Well, the node has a rotation matrix. You can apply that rotation matrix to a vector, and that will get you a vector that is oriented relative to the node...

Code: Select all

core::vector3df up(0, 1, 0); // this points up in world space

// transform up from world space to node space
node->getAbsoluteTransformation().rotateVect(up);

// now up points 'up' wrt node. if node is rotated so it is facing down,
// the up vector will be pointing forward in world space
Given that, you should see what you need to do to create a plane.

Travis
deanh22a
Posts: 23
Joined: Thu Feb 08, 2007 11:08 pm

Post by deanh22a »

ah okay. i was asking for the three points so I could use plane.setPlane(), so if I understand what you're telling me, I ended up doing this.
plane3df plane;
vector3df location1 = node->getAbsolutePosition();

vector3df location2 = vector3df(0, 0, 2000);
node->getAbsoluteTransformation().rotateVect(location2);
vector3df location3 = vector3df(2000, 0, 0);
node->getAbsoluteTransformation().rotateVect(location3);

plane.setPlane(location1,location2,location3);
and that works like I want it to. 8)
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Glad that works for you. It's just a little slower to do that, then to simply get the rotation of the node and rotate the (0,1,0) normal vector based on that rotation and then call -

Code: Select all

plane.setPlane( point, normal );
I'm an optimization freak, so if that's working for you, stick with it.
Last edited by Spintz on Sun Mar 04, 2007 2:38 pm, edited 1 time in total.
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Yeah, I'm with Spintz. It is faster and easier to read this...

Code: Select all

core::vector3df normal(0, 1, 0);
node->getAbsoluteTransformation().rotateVect(normal);

core::plane3df plane( node->getAbsolutePosition(), normal );
Travis
Post Reply