Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 97740 invoked from network); 26 May 2010 15:44:07 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 May 2010 15:44:07 -0000 Received: (qmail 66965 invoked by uid 500); 26 May 2010 15:44:06 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 66860 invoked by uid 500); 26 May 2010 15:44:06 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Delivered-To: moderator for user@commons.apache.org Received: (qmail 51066 invoked by uid 99); 26 May 2010 12:54:19 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of markus.petschnigg@gmx.at designates 213.165.64.20 as permitted sender) X-Authenticated: #22772494 X-Provags-ID: V01U2FsdGVkX1/aZQUiijbaYU1bGEV3xVEfHeWh4B4YXzaUL3xg7k sQlLE1vaqxr59b Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes To: user@commons.apache.org Date: Wed, 26 May 2010 14:53:44 +0200 Subject: Re: [Math] Rotating around global z-axis in processing Cc: "Paul Sommersguter" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: "Markus Petschnigg" Message-ID: User-Agent: Opera Mail/10.53 (Win32) X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked by ClamAV on apache.org 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