OpenFrameworks Quaternion to Toxiclibs Quaternion lost in translation
in
Contributed Library Questions
•
1 year ago
Hi,
I'm having problems trying to translate an OpenFrameworks example to Processing, here is the original OF code (it is a basic arcball example)
https://github.com/obviousjim/OFQuaternionExamples/blob/master/ArcballExample/src/testApp.cpp
And here is my translation using toxiclibs Quaternion class:
- import toxi.geom.*;
- Quaternion curRot = new Quaternion( 1, 0, 0, 0 );
- Vec2D lastMouse = new Vec2D( 0, 0 );
- void setup() {
- size( 640, 480, P3D );
- }
- void draw() {
- background( 200 );
- float[] axisAngle = curRot.toAxisAngle();
- pushMatrix();
- translate( width / 2, height / 2, 40 );
- rotate( degrees( axisAngle[0] ), axisAngle[1], axisAngle[2], axisAngle[3] );
- noFill();
- box( 100 );
- popMatrix();
- }
- void mousePressed() {
- lastMouse.set( mouseX, mouseY );
- }
- void mouseDragged() {
- Vec2D mouse = new Vec2D( mouseX, mouseY );
- Quaternion yRot = new Quaternion( mouse.x - lastMouse.x, 0, 1, 0 );
- Quaternion xRot = new Quaternion( mouse.y - lastMouse.y, 1, 0, 0 );
- Quaternion rot = yRot.multiply( xRot );
- curRot = curRot.multiply( rot );
- lastMouse = mouse;
- }
When I click and drag to rotate weird stuff happens, any ideas how to fix this?
1