(link to image)
code it's not work :
Code: Select all
vector3df v2 = n2->getTransformedBoundingBox().getCenter();
vector3df v3 = n3->getTransformedBoundingBox().getCenter();
vector3df direct = v3 - v2;
n1->setRotation(direct.getHorizontalAngle());
Code: Select all
vector3df v2 = n2->getTransformedBoundingBox().getCenter();
vector3df v3 = n3->getTransformedBoundingBox().getCenter();
vector3df direct = v3 - v2;
n1->setRotation(direct.getHorizontalAngle());
Code: Select all
ISceneNode* mesh = smgr->getMesh("yourmesh.mesh');
mesh->setRotation(core::vector3df(0,90,0));
Code: Select all
int x = cos-1(direct_x/direct);
int y = cos-1(direct_y/direct);
int z = cos-1(direct_z/direct);
n1->setRotation(core::vector3df(x,y,z));
Code: Select all
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice *device = createDevice(video::EDT_OPENGL,
core::dimension2d<s32>(640, 480), 16, false, false, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
// add arrow to the scene which will represent object rotating towards target
scene::IMesh *mesh = smgr->addArrowMesh("arrow", video::SColor(180,255,0,255),
video::SColor(180,0,0,255), 4,8, 20,15, 0.5f,1 )->getMesh(0);
// arrow mesh points along Y axis originaly we have to change that
core::matrix4 m;
m.setRotationDegrees(core::vector3df(90,0,0));
smgr->getMeshManipulator()->transformMesh(mesh, m);
scene::ISceneNode *node = smgr->addMeshSceneNode(mesh);
node->setMaterialFlag(video::EMF_LIGHTING, false);
//node->setPosition(core::vector3df(0,0,10));
// origin marker
mesh = smgr->addSphereMesh("sphere1", 1)->getMesh(0);
smgr->getMeshManipulator()->setVertexColors(mesh, video::SColor(255,0,255,0));
scene::ISceneNode *origin = smgr->addMeshSceneNode(mesh);
origin->setPosition(core::vector3df(5,0,5));
origin->setMaterialFlag(video::EMF_LIGHTING, false);
// target marker
mesh = smgr->addSphereMesh("sphere2", 1)->getMesh(0);
smgr->getMeshManipulator()->setVertexColors(mesh, video::SColor(255,255,0,0));
scene::ISceneNode *target = smgr->addMeshSceneNode(mesh);
target->setPosition(core::vector3df(21,10,21));
target->setMaterialFlag(video::EMF_LIGHTING, false);
//! getHorizontalAngle() return horizontal(Y) and vertical(X) angle between two points
//! you have to use relative position of target to origin
core::vector3df relativeTarget = target->getPosition()-origin->getPosition();
node->setRotation(relativeTarget.getHorizontalAngle());
node->setPosition(origin->getPosition());
// camera
smgr->addCameraSceneNode(0, node->getPosition()+core::vector3df(20,20,-20),node->getPosition());
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,50,50,50));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Code: Select all
#include <iostream>
using namespace std;
#include <irrlicht.h>
using namespace irr;
int main()
{
IrrlichtDevice *device = createDevice(video::EDT_OPENGL,
core::dimension2d<s32>(640, 480), 16, false, false, false);
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
// add arrow to the scene which will represent object rotating towards target
scene::IMesh *mesh = smgr->addArrowMesh("arrow", video::SColor(180,255,0,255),
video::SColor(180,0,0,255), 4,8, 20,15, 0.5f,1 )->getMesh(0);
// arrow mesh points along Y axis originaly we have to change that to Z
core::matrix4 m;
m.setRotationDegrees(core::vector3df(90,0,0));
smgr->getMeshManipulator()->transformMesh(mesh, m);
scene::ISceneNode *node = smgr->addMeshSceneNode(mesh);
node->setMaterialFlag(video::EMF_LIGHTING, false);
//node->setPosition(core::vector3df(0,0,10));
// origin marker
mesh = smgr->addSphereMesh("sphere1", 1)->getMesh(0);
smgr->getMeshManipulator()->setVertexColors(mesh, video::SColor(255,0,255,0));
scene::ISceneNode *origin = smgr->addMeshSceneNode(mesh);
origin->setPosition(core::vector3df(5,0,5));
origin->setMaterialFlag(video::EMF_LIGHTING, false);
// target marker
mesh = smgr->addSphereMesh("sphere2", 1)->getMesh(0);
smgr->getMeshManipulator()->setVertexColors(mesh, video::SColor(255,255,0,0));
scene::ISceneNode *target = smgr->addMeshSceneNode(mesh);
target->setPosition(core::vector3df(21,10,21));
target->setMaterialFlag(video::EMF_LIGHTING, false);
//! arrow offset from origin
core::vector3df offset(0,0,3);
//! getHorizontalAngle() return horizontal(Y) and vertical(X) angle between two points
//! you have to use relative position of target to origin
core::vector3df relativeTarget = target->getPosition()-origin->getPosition();
core::vector3df rotation = relativeTarget.getHorizontalAngle();
//! rotate offset around origin
core::matrix4 n;
n.setRotationDegrees(rotation);
n.rotateVect(offset);
offset += origin->getPosition();
//! update arrow
node->setRotation(rotation);
node->setPosition(offset);
// camera
smgr->addCameraSceneNode(0, node->getPosition()+core::vector3df(20,20,-20),node->getPosition());
while(device->run())
{
driver->beginScene(true, true, video::SColor(0,50,50,50));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
arras wrote:turn() rotate node around its Y axis
pitch() around X
roll() around Z
to rotate node around its Z axis 45 degrees just call: roll(yourCilinderNode, 45.0f)
Code: Select all
void CHickey::Rotate()
{
vector3df pos = m_pHickeyNode->getPosition();
f32 x = abs(atan2(pos.X, pos.Y));
f32 z = abs(atan2(pos.Z, pos.Y));
x *= RADTODEG;
z *= RADTODEG;
pos.X < 0 ? roll(m_pHickeyNode, x) : roll(m_pHickeyNode, -x); //roll() around Z
pos.Z < 0 ? pitch(m_pHickeyNode, z) : pitch(m_pHickeyNode, -z);//pitch() around X
turn(m_pHickeyNode, m_fAngleSelfRotate);//turn() around its own axis
}