This project is read-only.

Moving / rotating objects

To move an object to a specific position you can use the following function:

obj.setPosition(targetp);
where targetp is a JSON with x,y,z keys. To move an object with a displacement vector use the following syntax:

obj.move(displacement);
where displacement is a JSON with x,y,z keys. To set the absolute orientation of an object use the following:

obj.setOrientation(orientation);
where orientation is a JSON with alpha, beta, gamma keys with radian values or alphaD, betaD, gammaD keys with degree values. To rotate an object relative to its current orientation, use the following function:

obj.rotate(axis, angle);
where axis is a JSON with x,y,z keys and angle is given in radians. Please note, that the axis must be normalized before passing it to the rotate function (meaning length of axis must be equal to 1).

Examples:

obj.setPosition({x:100,y:150,z:10});
obj.move({x:10,y:0,z:0});
obj.rotate({x:0,y:0,z:1}, Math.PI / 2);
obj.setOrientation({alphaD: 0, betaD: 0, gammaD: 60});
To render the scene after changing the states of objects use the following function calls:

sheetengine.calc.calculateChangedSheets();
sheetengine.drawing.drawScene();
Be sure to only call these functions once in every frame iteration - after you have moved / rotated all your objects.

Last edited Jan 27, 2013 at 1:00 AM by dobsonl, version 2

Comments

dobsonl Jan 27, 2013 at 1:32 AM 
I meant obj.centerp, sry.

dobsonl Jan 27, 2013 at 1:27 AM 
Ok, I took note of the polygonorder and shadow issue. Thanks for the comments. About rotation with a distance: you could use the geometry.rotateAroundArbitraryAxis function on the obj.center object as first parameter, the axispoint as the second, axisdirection as third and angle as fourth. And also set the orientation of the object using obj.setOrientation.

Obi2Kenoby Jan 15, 2013 at 11:21 AM 
Hi there,

I discovered (with trial and error) that the method 'calculatePolygonOrder(polygon) is a very expensive method. Even when shadows are off, it still calculates polygon order for shadows.
So maybe, make sure he doesn't calculate unnecessary shadow calculations, when shadows are off?

Great library by the way!

Obi2Kenoby Jan 4, 2013 at 4:22 PM 
Hi,

Is there an easy way to rotate an object the same way as the object.rotateSheet method?
So you can add a distance from the rotation vector to it?

obj.rotateSheet(sheet, AXISPOINT, axisDirection, angle);

I've tried it manualy with a combination of rotation (around its own axis) and translation,
but I get to many rounding errors, and it is not a very efficient way to do it.

grtz.