Hello,
I want to rotate a point in a 3d space around an other / calculate which
coords the point has after the rotation around the other one.
Big Thx for your help!
[Solved] Rotate a 3D Point around an other
[Solved] Rotate a 3D Point around an other
Last edited by porcus on Sat Aug 23, 2008 4:22 pm, edited 1 time in total.
-
- Posts: 52
- Joined: Sun Jun 22, 2008 4:09 pm
- Contact:
Not overly sure what you are trying to achieve but if you are aiming to move the point in a circle around the other you could you trig:
x = r cos(t) + j
y = r sin(t) + k
x&y are you new points coords.
r is the radius of the new point from the original.
j&k and the origin of the rotating point ie. the other point.
t is the angle from 0 to 360... (this may need to be in radians?!)
I've not checked the above, just from memory but googling 'circle equation sin cos' should provide additional help with the 3d dimension.
x = r cos(t) + j
y = r sin(t) + k
x&y are you new points coords.
r is the radius of the new point from the original.
j&k and the origin of the rotating point ie. the other point.
t is the angle from 0 to 360... (this may need to be in radians?!)
I've not checked the above, just from memory but googling 'circle equation sin cos' should provide additional help with the 3d dimension.
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
There's doubtless a much smarter way of doing this, but it's Saturday, so this is the best that I can manage.
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
int main()
{
IrrlichtDevice *device =
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 32,
false, false, true, 0);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
smgr->addCameraSceneNode(0, vector3df(0,0,-50));
IBillboardSceneNode * bills[2];
for(int i = 0; i < 2; i++)
{
bills[i] = smgr->addBillboardSceneNode();
bills[i]->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bills[i]->setMaterialTexture(0, driver->getTexture("../../media/particle.bmp"));
bills[i]->setMaterialFlag(video::EMF_LIGHTING, false);
bills[i]->setMaterialFlag(video::EMF_ZBUFFER, false);
}
bills[0]->setPosition(vector3df(10, 10, 0));
bills[0]->updateAbsolutePosition();
bills[1]->setPosition(vector3df(20, 0, 0));
bills[1]->updateAbsolutePosition();
vector3df axisOfRotation(1, 2, 3);
axisOfRotation.normalize();
quaternion rotation;
// 1 degree per frame, and vsync is on, so should be ~60 fps
rotation.fromAngleAxis(1.f * DEGTORAD, axisOfRotation);
u32 then = device->getTimer()->getTime();
while(device->run())
{
vector3df relativePosition = bills[1]->getAbsolutePosition() - bills[0]->getAbsolutePosition();
relativePosition = rotation * relativePosition;
relativePosition += bills[0]->getAbsolutePosition();
bills[1]->setPosition(relativePosition);
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
thanks, but it is now solved with:
irr::core::vector3d< T > wrote:void rotateXYBy (f64 degrees, const vector3d< T > ¢er)
Rotates the vector by a specified number of degrees around the Z axis and the specified center.
void rotateXZBy (f64 degrees, const vector3d< T > ¢er)
Rotates the vector by a specified number of degrees around the Y axis and the specified center.
void rotateYZBy (f64 degrees, const vector3d< T > ¢er)
Rotates the vector by a specified number of degrees around the X axis and the specified center.
-
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
If the requirements had specified rotation only around the X, Y or Z axes, then that's what I'd have used. That's why it's worthwhile taking an extra ten seconds to ask the right question.Dark_Kilauea wrote:And this, ladies and gentlemen, is why people should always read the documentation first.
Not that rogerborg's solution wasn't cool to look at.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way