How to rotate object parallel to triangle?

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
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

How to rotate object parallel to triangle?

Post by Magnet »

I have two objects: cube and triangle:
Image

My triangle points is changed by some function (some points moved by Y coordinates)
Image

After points moved I need to change rotation matrix for cube.
Cube can be always parellel to triangle.
Image
Last edited by Magnet on Mon Nov 27, 2006 11:57 am, edited 1 time in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Set the cube as a child of the triangle?
Image Image Image
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

This is impossible!

I have triangle3df.

Code: Select all

ISceneNode node=smgr->addCubeSceneNode();
triangle3df tri = GetAssignedTriangle();
//node->setRotation(...);
//node->setTranslation(...); 
I need to calculate vectors Rotation and Translation for node for make cube paralel to triangle.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Sorry! I was being a bit silly but then you didn't say that either hehe! You'll have to use the triangle's normal some how, though i'm sure you knew that already. Not quite sure how you'd go about that though i was doing something similar with one of my projects by having my character stand with their back to a wall.
Image Image Image
Magnet
Posts: 101
Joined: Wed Sep 27, 2006 7:32 pm

Post by Magnet »

Thnx for all.
I am realize this task!
Part of source code:

Code: Select all

		//calculate normal of triangle
		vector3df normal1 = (tri.pointB-tri.pointA).crossProduct(tri.pointC-tri.pointB).normalize()*10;
		driver->draw3DLine(tri.pointA, tri.pointA+normal1);
		driver->draw3DLine(tri.pointB, tri.pointB+normal1);
		driver->draw3DLine(tri.pointC, tri.pointC+normal1);

		//calculate normal for buttom plain of cube
		aabbox3d<float> bbox =  cube->getBoundingBox();
		cube->getAbsoluteTransformation().transformBox(bbox);	
		vector3df A = bbox.MinEdge;
		vector3df B = bbox.MaxEdge;
		vector3df C = bbox.MinEdge;
		B.Y = A.Y;
		C.X = B.X;
		vector3df normal2 = (B-A).crossProduct(C-B).normalize()*10;

		vector3df angle = normal2.crossProduct(normal1);
		cube->setRotation(angle);
		cube->setPosition(intersection);
Post Reply