Orienting node perpendicular to a surface

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Orienting node perpendicular to a surface

Post by Granyte »

So I guess i'm back to the basics.

let's say you have a non flat surface like a sphere and you wanna have objects sticking out of it with their up side pointing out from the sphere.

how would I do this I have looked at the getHorizontalAngle method and so far nothing good came out of it any suggestion ? pseudo code? any one already done this?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Orienting node perpendicular to a surface

Post by mongoose7 »

This is related to the normal of the surface, isn't it. You need to apply the transform which maps (0, 1, 0) to the surface normal.
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Orienting node perpendicular to a surface

Post by Granyte »

yes but how do I create this transform I honestly have no idea
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Orienting node perpendicular to a surface

Post by mongoose7 »

I think Irrlicht has functions for this. Look in the matrix headers or the docs. Otherwise, the axis of a quaternion would be cross(old_normal, new_normal) and the angle would be cos(theta) = old_normal.new_normal.
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Orienting node perpendicular to a surface

Post by thanhle »

Hi mate,
The crossproduct of two vector gives you a vector that is perpendicular to those two.
For example if you know the surface is a triangle with three vertices.

For simplicity assume you want to have the object sticking out of one of the vertice A for a triangle with A,B,C vertices.
Calculate the vector from A to B and vector from A to C.

Do cross product these two vector gives you the perpendicular vector, which is a direction vector sticking out at point A. You can use one of the two method below to get the angles. Maybe normalise the vector first.

1) You can then use that getHorizontalAngle function to get the X and Y angles.

2) or you can build a quaternion using rotationFromTo given to vectors. Then get euler angle from one of the quaternion function.

Put your node object at point A then do a rotation based on the resultant angles from method 1 or 2.

Make sure that your node initial rotation confine with irrlicht standard. I can't remember which axis is the initial facing.

If you want the node to sticking out in the middle of the triangle face, then you have to find the centroid of the triangle before applying the above methods.

If you want to have the object sticking out any point on a triangle then you have to compute that point (e.g. check out irrlicht ray to triangle collision for this), before using the above method.

Regards
thanh
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: Orienting node perpendicular to a surface

Post by Granyte »

Code: Select all

 
vector3df rotation(0,0,1);
irr::core::quaternion myQuat;
                    myQuat.rotationFromTo(irr::core::vector3df(0, 1, 0), rotation);
                    myQuat.toEuler(rotation);
                    scenenode->setRotation(rotation)
what have I missed here?
thanhle
Posts: 325
Joined: Wed Jun 12, 2013 8:09 am

Re: Orienting node perpendicular to a surface

Post by thanhle »

I think the document said node->setRotation modified the relative rotation of the node. Angle is in degree.

Left hand rotation from y to z is indeed x (90 degree).

Regards
thanh
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Orienting node perpendicular to a surface

Post by Mel »

If you're placing the object into a sphere, you could create a quaternion out of the position in the sphere and the center of such sphere, then, transform that quaternion into an Eulerian rotation vector, and place the object, in a nutshell.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply