|
Luca, Sr. Member
Posted: 24 March 2013 01:09 PM Total Posts: 230
[ # 16 ]
Of main view only, in this case, i think…
|
Iogen, Newbie
Posted: 24 March 2013 01:20 PM Total Posts: 9
[ # 17 ]
Had another child container inside of it from a previous test accidently. I removed and children meshes are now rotating. The rotation seems to be off though. I rotate by 90 on the X Axis and it doesn’t just spin around its pivot point - it moves to a different position as well.
|
ranoya, Newbie
Posted: 24 March 2013 01:28 PM Total Posts: 29
[ # 18 ]
I found a code that i’d already used, and it works well:
private function onKeyDown(e:KeyboardEvent) { var transform:Matrix3D = selectedObject.transform;
if (e.keyCode == Keyboard.LEFT) { trace ("left"); transform.appendRotation( -90, Vector3D.Y_AXIS); } else if (e.keyCode == Keyboard.RIGHT) { trace ("right"); transform.appendRotation( 90, Vector3D.Y_AXIS); } else if (e.keyCode == Keyboard.UP) { trace ("up"); transform.appendRotation( -90, Vector3D.X_AXIS); } else if (e.keyCode == Keyboard.DOWN) { trace ("down"); transform.appendRotation( 90, Vector3D.X_AXIS); } selectedObject.transform = transform; }
The difference with the code i posted before is that tou can not transform directly the object.transform.
If you use a reference or a clone of the object’s transform, make the transformation, and atributte this to the object at the end, than it works.
|
Luca, Sr. Member
Posted: 24 March 2013 01:28 PM Total Posts: 230
[ # 19 ]
private function Qr1():void { RotationQX1 += 0.01; RotationQY1 += 0.01; RotationQZ1 += 0.01; var qrx:Quaternion = new Quaternion(); var qry:Quaternion = new Quaternion(); var qrz:Quaternion = new Quaternion(); qrx.fromAxisAngle( new Vector3D( 1, 0, 0 ), RotationQX1 ); qry.fromAxisAngle( new Vector3D( 0, 1, 0 ), RotationQY1 ); qrz.fromAxisAngle( new Vector3D( 0, 0, 1 ), RotationQZ1 ); var mrx:Matrix3D = new Matrix3D(); mrx.identity(); var mry:Matrix3D = new Matrix3D(); //mry.identity(); var mrz:Matrix3D = new Matrix3D(); //mrz.identity(); var TransformMatrix:Matrix3D = new Matrix3D(); TransformMatrix.identity(); qrx.toMatrix3D( mrx ); qry.toMatrix3D( mry ); qrz.toMatrix3D( mrz ); var v1:Vector.<Vector3D> = new Vector.<Vector3D>(3); var v2:Vector.<Vector3D> = new Vector.<Vector3D>(3); var orMatrix:Matrix3D = objContainer.transform; v1 = orMatrix.decompose(); TransformMatrix.appendRotation( v1[1].x, new Vector3D( 1, 0, 0 ) ); TransformMatrix.appendRotation( v1[1].y, new Vector3D( 0, 1, 0 ) ); TransformMatrix.appendRotation( v1[1].z, new Vector3D( 0, 0, 1 ) ); TransformMatrix.append( mrx ); objContainer.transform = mrx; // objContainer.transform.append( mrx ); // objContainer.sceneTransform.append( mry ); // objContainer.sceneTransform.append( mrz ); // var oldQ:Quaternion = new Quaternion(); // var newQ:Quaternion = new Quaternion(); // var resultQ:Quaternion = new Quaternion(); // var newM:Matrix3D = new Matrix3D(); // // oldQ.fromMatrix( objContainer.transform ); // newQ.fromMatrix( newM ); // // // resultQ.multiply( oldQ, newQ ); // // //resultQ.multiply( oldQ, qrx ); // //resultQ.multiply( oldQ, qry ); // // objContainer.transform = resultQ.toMatrix3D(); // // // objContainer.rotationX += 0.1; }
|
ranoya, Newbie
Posted: 24 March 2013 01:37 PM Total Posts: 29
[ # 20 ]
For the object doens’t move with the appendRotation method, you make this:
var oldPosition:Vector3D = object.position.clone(); object.position = new Vector3D(); var transform:Matrix3D = object.transform.clone(); transform.appendRotation(90, Vector3D.Y_AXIS); transform.position = oldPosition; object.transform = transform;
|
Luca, Sr. Member
Posted: 24 March 2013 01:46 PM Total Posts: 230
[ # 21 ]
Ops…
more simple:
private function Qr3():void
{
var q1:Quaternion = new Quaternion();
var q2:Quaternion = new Quaternion();
var q3:Quaternion = new Quaternion();
q1.fromMatrix( objContainer.transform );
q2.fromAxisAngle( new Vector3D( 0, 1, 0 ), 0.01 );
q3.multiply( q1, q2 );
var TransformMatrix:Matrix3D = new Matrix3D();
TransformMatrix.identity();
q3.toMatrix3D( TransformMatrix );
objContainer.transform = TransformMatrix;
}
|
Iogen, Newbie
Posted: 24 March 2013 03:42 PM Total Posts: 9
[ # 22 ]
I implemented your solution and it worked for the most part. I still got a couple of unexplained rotation errors (probably something I over looked).
I decided to go with a solution that involved moving the camera instead of rotating the object. A bit messier given the context of my application; but it works.
Thanks for all the help.
|
|
Luca, Sr. Member
Posted: 24 March 2013 04:37 PM Total Posts: 230
[ # 24 ]
So for example this rotate right ?
private function Qr8( X:Number, Y:Number, z:Number ):void
{
RotationQX1 = 0.1;
var q1:Quaternion = new Quaternion();
var q1Mat:Matrix3D = new Matrix3D();
q1.fromAxisAngle( Vector3D.X_AXIS, DegRad( -RotationQX1 ) );
q1.toMatrix3D( q1Mat );
RotationQX1 = 0.1;
var q2:Quaternion = new Quaternion();
var q2Mat:Matrix3D = new Matrix3D();
q2.fromAxisAngle( Vector3D.Y_AXIS, DegRad( RotationQX1 ) );
q2.toMatrix3D( q2Mat );
var TransformMatrix:Matrix3D = new Matrix3D();
TransformMatrix = objContainer.transform;
var v1:Vector.<Vector3D> = new Vector.<Vector3D>(3);
v1 = TransformMatrix.decompose();
var om:Matrix3D = new Matrix3D();
TransformMatrix.append(q1Mat);
TransformMatrix.append(q2Mat);
objContainer.transform = TransformMatrix;
}
|
ERik Eide, Newbie
Posted: 19 September 2013 07:45 PM Total Posts: 3
[ # 25 ]
Hi every one,
@Luca, I tried part of your code, plugin it on a leapmotion, with the usefull LeapmotionAS3
it works fantastic on a simple automation I’ve done but I still have the problem
if you change the cube position, the quaternion works very well but on the center Vector3D, I would like to put the cube to whatever vector3D for position and manage rotationX and rotationY with the axis based on cube position
for instance, putting my cube at x = 50, vertical rotationX works welll but rotationY works around center of the scene, and not on the center (position) of the cube in 3d space :/...
I suppose there is something very simple to do on this, based on the matrix ? or in the quatenion on initialisation, I ve tried putting values in quaternion and matrix, but as I am very dumb on 3d, I can’t manage anything….
could you help me a bit please ?
thank you
here is my code,
I changed my leap control with arrows to allow anyone to test the code and maybe help me to finish this
package { import away3d.containers.*; import away3d.core.math.*; import away3d.debug.Trident; import away3d.entities.*; import away3d.materials.*; import away3d.primitives.*; import away3d.utils.*; import flash.display.*; import flash.events.*; import flash.geom.Matrix3D; import flash.geom.Vector3D; import flash.ui.Keyboard; public class SwipeCube extends Sprite { public static const DEG2RAD:Number = (Math.PI / 180); //0.017453293; private var _view:View3D; private var _cube:Mesh; private var _indent:Number = 0; private var _limit:Number = 0; private var _swiped:Boolean = false; private var _direction:String; private var RotationQX:Number = 0.05; private var RotationQY:Number = 0.01; private var RotationQZ:Number = 0.01; private var tri:Trident; private var RotateByQuaternion:Boolean; public function SwipeCube() { if (stage) init(new Event(Event.ADDED_TO_STAGE)); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, init); stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; _view = new View3D(); addChild(_view); _view.x = 100; _view.camera.x = -35; _view.camera.y = 100; _view.camera.z = -250; _view.camera.lookAt(new Vector3D()); tri = new Trident(100, true); _view.scene.addChild(tri); _cube = new Mesh(new CubeGeometry(50, 50, 50), null); _view.scene.addChild(_cube); _cube.rotationX = -90; _cube.rotationY = 90; addEventListener( Event.ENTER_FRAME, _onEnterFrame ); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener); } private function keyDownListener(e:KeyboardEvent):void { if(e.keyCode == Keyboard.UP) { onSwipe('up'); } if(e.keyCode == Keyboard.DOWN) { onSwipe('down'); } if(e.keyCode == Keyboard.RIGHT) { onSwipe('right'); } if(e.keyCode == Keyboard.LEFT) { onSwipe('left'); } } //private function onSwipe(e:LeapMotionControllerEvent):void private function onSwipe(direction:String):void { //trace('onSwipe: ' + e.direction); //e.stopImmediatePropagation(); if (_swiped) return; //_direction = e.direction; _direction = direction; switch(_direction) { case 'up': RotationQX = .015; _limit = DEG2RAD * 90; break; case 'right': RotationQY = -.015; _limit = -DEG2RAD * 90; break; case 'down': RotationQX = -.015; _limit = -DEG2RAD * 90; break; default: // default is 'left' in our app. RotationQY = +.015; _limit = DEG2RAD * 90; break; } _swiped = !_swiped; // true } private function Qr():void { var qrx:Quaternion;// = new Quaternion(); var qry:Quaternion;// = new Quaternion(); var matrix:Matrix3D = new Matrix3D(); matrix.identity(); switch(_direction) { case 'up': _indent += RotationQX; qrx = new Quaternion(); qrx.fromAxisAngle(new Vector3D(1, 0, 0), RotationQX); qrx.toMatrix3D(matrix); break; case 'right': _indent += RotationQY; qry = new Quaternion(); qry.fromAxisAngle(Vector3D.Y_AXIS, RotationQY); qry.toMatrix3D(matrix); break; case 'down': _indent += RotationQX; qrx = new Quaternion(); qrx.fromAxisAngle(new Vector3D(1, 0, 0), RotationQX); qrx.toMatrix3D(matrix); break; default:// default is left in our app. _indent += RotationQY; qry = new Quaternion(); qry.fromAxisAngle(new Vector3D(0, 1, 0), RotationQY); qry.toMatrix3D(matrix); break; } _cube.sceneTransform.append(matrix); } private function _onEnterFrame(e:Event):void { if (_swiped) { if(_limit > 0) { if(_indent <= _limit) Qr(); else { _swiped = !_swiped; // false _indent = 0; } } else { if(_indent >= _limit) Qr(); else { _swiped = !_swiped; _indent = 0; } } } _view.render(); } } }
|
Luca, Sr. Member
Posted: 19 September 2013 08:05 PM Total Posts: 230
[ # 26 ]
Hi Erik,
Simply go to:
http://79.44.229.152:8086/AwayGamesMaker/
or directly here:
http://79.44.229.152:8086/AwayGamesMaker/src/GamesMakerClass/MathUtils/
In this folder you can find the GMMathUtils class, in that class you can find a function that can be used to rotate one or a Group of objects, by specify a ref point that can be everywhere in the scene ...
And a series of “patched” rotations functions
This class can help you ?
if you want you can try games maker, insert two or tree “cubes” select it with the rectangle selection tool, or click the cubes with the CTRL key pressed, and than rotate it
The interface are very similar to the 3ds MAX interface
Problem solved ?
|
ERik Eide, Newbie
Posted: 19 September 2013 10:28 PM Total Posts: 3
[ # 27 ]
@luca: thank you very much
I tried first RotateObjectByArbitraryAxisAndPoint method because I thought the axis u have to choose was the Vector3D.X_AXIs, Y_AXIS or Z_AXIS of the Object passed as an argument, and the point, the delta with the center of the scene ...
but it did rotation around the center + the rotation on itself(the one I want ..)
so if you can precise exactly what I did to understand, u’ll be welcomed
then I tried RotateObjectByArbitraryAxis, the axis being simply the Vector3D.X_AXIs, Y_AXIS or Z_AXIS
thank you, it does it for me
fantastic your class, I will try the different methods trying to understand them and to use it, and I will certainly ask u some questions on some of them
regards
|
Luca, Sr. Member
Posted: 20 September 2013 05:57 AM Total Posts: 230
[ # 28 ]
By using Matrix you transform the coordinates of a point or a series ( array or vector or… ) by the transform you need…
For example if have a Vector3D 10,10,10 you can rotate or scale this vector by the degrees ( appendrotations ) or scalefactor ( appendscale ) you need.
Remember that in a series of transform the order that you use for the transformations are important, example:
rotate
translate
scale
are not the same as
transale
rotate
scale
but, if you want you can:
transale
rotate
translate
scale
rotate
ecc ecc ecc
This means you can apply a serier of transfonramtions by using the same Matrix.
Anyway, i am glad that your program works, so W AWAY3D !!!
Hi Erik ...
|
GrokDD, Newbie
Posted: 20 September 2013 07:25 AM Total Posts: 28
[ # 29 ]
Perhaps nest two more ObjectContainer3D inside the original, with all the children objects residing in the third Container??
xObj3DCont contains yObj3DCont
yObj3DCont contains zObj3DCont
zObj3DCont contains all the children
And then you just rotate the one axis per container…
However you may end up with the same original problem.
But… then can’t you calculate the orientation based on the master scene?
Just a little out of the box thinking, no time to test it myself.
Good luck!
|
Luca, Sr. Member
Posted: 20 September 2013 07:35 AM Total Posts: 230
[ # 30 ]
Hi GrokDD
Right, the transofmation are relative to the local transformations or are cumulative so you have
Matrix1, Matrix2, Matrix3 and so on ... applyed to the same object…
So you have last Object transform Matrix, decompose and you have the last rotation quantity and than ...
In that case, your example, you need more than one Container, but this is not the better solution if don’t want to, for example, use too much memory and processor cycle ( you need to calculate all the transform one by one )
I think if i wont to change any object position or rotations, without tricks, i must be able to do that
But your solution WORKS !
|