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?
Orienting node perpendicular to a surface
Re: Orienting node perpendicular to a surface
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.
Re: Orienting node perpendicular to a surface
yes but how do I create this transform I honestly have no idea
Re: Orienting node perpendicular to a surface
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.
Re: Orienting node perpendicular to a surface
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
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
Re: Orienting node perpendicular to a surface
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)
Re: Orienting node perpendicular to a surface
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
Left hand rotation from y to z is indeed x (90 degree).
Regards
thanh
Re: Orienting node perpendicular to a surface
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