Thank you very much for your reply, Luc!
I'm using this class (which basically is a rewrite of the apache
commons.math.Rotation class):
http://www.lagers.org.uk/s3d4p/distribution/web/reference/index.html
Since there is no getOrientation method, I have to write my own, just
like you described it.
// get the direction of object X axis with respect to canvas frame
Vector 3D objectXAxis = ...;
// get the direction of object Y axis with respect to canvas frame
Vector 3D objectYAxis = ...;
how do I do that? what goes after the equation sign? I have no idea right now.
I have to use the Processing PVector class instead of a Vector3D, so
right now I use something like this:
public Rot getOrientation() {
// get the direction of object X axis with respect to canvas frame
PVector objectXAxis = new PVector (this.getRotVec().x, 0, 0);
// get the direction of object Y axis with respect to canvas frame
PVector objectYAxis = new PVector (0, this.getRotVec().y, 0);
// VectorConstants is Processing's own constants class
return new Rot(VectorConstants.PLUS_I, VectorConstants.PLUS_J,
objectXAxis, objectYAxis);
}
apparently, this approach doesn't really work. I call this method by
using this code:
public void rotateAroundGlobalZ(int direction) {
PVector zAxis =
this.getOrientation().revert().applyTo(VectorConstants.PLUS_K);
// get previous rotation
Rot prev_rotation = new Rot(RotOrder.XYZ, this.getRotArray()[0],
this.getRotArray()[1], this.getRotArray()[2]);
Rot rotation = new Rot(zAxis, (float) Math.toRadians(45));
rotation = rotation.applyTo(prev_rotation);
// rotate this istance of a shapes3d.Box object to this
this.rotateTo(rotation.getAngles(RotOrder.XYZ));
}
Am I doing the right thing? I think, the error either lies in the
calculation of the objectX and objectY axis or in the calculation of
the previous rotation / current rotation. Do you have any ideas?
Thanks again, your last reply really helped.
Le 20/05/2010 23:00, Markus Petschnigg a ?crit :
> Hi!
>
> We are building an application where we rotate and translate boxes with
> different Wiimote metaphors in Processing.
> We want to rotate an object around the global processing canvas z-axis,
> not around the objects own z-axis. No matter which rotation has been
> used before, no matter where the object is in the canvas, this should
> just rotate the object around the Processing z-axis. We are using the
> Shapes3D libary which is based on apache commons math. The method used
> for rotating is called Rot, which is basically the same as in the apache
> commons math.
> Here is a link to the processing forum, where we also discussed the
> issue: http://processing.org/discourse/yabb2/YaBB.pl?num=1272357250/15
> Our entire code is online at: http://code.google.com/p/3d-media-browser/
I would suggest to compute the coordinates of the canvas Z axis in the
object frame and to rotate the object around this axis.
I assume you have some methods to get or set the orientation fo your
object with respect to the canvas. For the sake of the example, I will
assume the API is something like :
Rotation r1 = myObject.getOrientation();
and
myObject.setOrientation(r2);
The assumed semantic is that v = r1(u) is such that if u is a vector in
object reference frame, v is the vector in the canvas reference frame,
i.e. myObject.getOrientation().applyTo(Vector3D.PLUS_K) gives the
orientation of the Z axis of the object in the canvas frame. What you
want is the opposite, so you have to revert the rotation.
You could use something along these lines :
Vector3D zAxis =
myObject.getOrientation().revert().applyTo(Vector3D.PLUS_K);
This vector is the canvas Z axis in the object frame. So if you apply a
rotation to the object around this axis, it will rotate around an axis
parallel to the canvas Z axis, but containing object origin.
If you don't have a getOrientation() method with the assumed semantic,
you will have to reconstruct the rotation by yourself. One way to do
this is to use the coordinates of two canonical axes of the object as
follows:
public Rotation getOrientation() {
// get the direction of object X axis with respect to canvas frame
Vector 3D objectXAxis = ...;
// get the direction of object Y axis with respect to canvas frame
Vector 3D objectYAxis = ...;
return new Rotation(Vector3D.PLUS_I, Vector3D.PLUS_J,
objectXAxis, objectYAxis);
}
Hope this helps,
Luc
>
> Thanks in advance
> Markus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org