This is G o o g l e's cache of http://www.flashsandy.org/forum/index.php?act=Print&client=printer&f=17&t=350 as retrieved on 3 Aug 2007 00:26:40 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:NnzGHTAZ5_YJ:www.flashsandy.org/forum/index.php%3Fact%3DPrint%26client%3Dprinter%26f%3D17%26t%3D350+act%3DPrint+%22index+php%22+-lofiversion+site:www.flashsandy.org&hl=en&ct=clnk&cd=22


Google is neither affiliated with the authors of this page nor responsible for its content.
These search terms have been highlighted: index php 
These terms only appear in links pointing to this page: act print

Printable Version of Topic

Click here to view this topic in its original format

Sandy's Forum _ AS2 1.x versions _ How do I adjust a transform3D

Posted by: 3wme Mar 2 2007, 12:17 AM

I'm just starting to get to grips with Sandy, but think I must be missing something pretty basic here.

I make a cube, create a transformGroup and a transform3D, then:

translation.translateY(100)
tGroup.setTransform( translation );

then add the cube to that transformGroup. Thats fine.

Then later I want to move that cube on the X axis. If I do:

right_btn.onRelease=function(){
cube_pos=cube.getPosition();
trace("in "+cube_pos);
cube_x=cube_pos.x;
translation.translateX(cube_x+5);
tGroup.setTransform( translation );
cube_pos=cube.getPosition();
trace("out "+cube_pos);
}

on repeated presses, it traces out:

in Vector4 : 0,100,0
out Vector4 : 0,100,0
in Vector4 : 5,0,0
out Vector4 : 5,0,0
in Vector4 : 10,0,0
out Vector4 : 10,0,0

I dont quite understand why cube.getPosition() returns the same vector after the translateX function is called, but the bigger problem is why the previous translateY(100) is overwritten? i would have expected the Y and Z values to remain constant?

thanks for any advice


Posted by: 3wme Mar 2 2007, 09:13 AM

Ok, I seem to have found a solution. If you set the initial transform to:

translation.translate(0,100,0)

I can then later adjust any of the 3 co-ordinates by:

cube_pos=cube.getPosition();

translation.translate(cube_pos.x+xMovement,0-cube_pos.y,cube_pos.z);

I dont understand why the y value comes back as -100 after translation.translate(0,100,0), but using 0-cube_pos.y sorts it out.

It looks like creating/modifying transforms is much simpler in 1.2, but I'm not sure when I should make the switch? It sounds like you cant set a textureskin for the backface of a plane, for instance?

Posted by: Petit Mar 2 2007, 11:33 AM

QUOTE(3wme @ Mar 2 2007, 10:13 AM) *


translation.translate(0,100,0)
I can then later adjust any of the 3 co-ordinates by:
cube_pos=cube.getPosition();
translation.translate(cube_pos.x+xMovement,0-cube_pos.y,cube_pos.z);

I dont understand why the y value comes back as -100 after translation.translate(0,100,0), but using 0-cube_pos.y sorts it out.

It looks like creating/modifying transforms is much simpler in 1.2, but I'm not sure when I should make the switch? It sounds like you cant set a textureskin for the backface of a plane, for instance?

Yes, in 1.1 a translation along or rotation around one single axis inhibits earlier transformations.
This means that if you want to add transformations, you have to keep track of the current values and make a transform on all three coordinates. Think of any new transform as starting out from the default position.

The minus sign on the y movement, depends on an inconsistency in the transform handling in 1.1, which is remedied in 1.2.

The 1.2 beta still has some problems with handling backface skins, and a few other problems as well. It is still very much beta wink.gif

Posted by: 3wme Mar 2 2007, 01:25 PM

Attached File  cube_move_rotate.swf ( 28.88k ) Number of downloads: 19
Thanks Petit, I'm trying to add a rotation to the cube, too, just on the Y axis:

translation.translate(0,0,0)
rotation.rotY(0)
translation.combineTransform(rotation);
tGroup.setTransform( translation );

then later I can:

rot_right_btn.onRelease=function(){
degree+=10
rotation.rotY(degree)
translation.combineTransform(rotation);
}

It rotates correctly, but when I then try to move the cube:

right_btn.onRelease=function(){
cube_pos=cube.getPosition();
translation.translate(cube_pos.x+5,0-cube_pos.y,cube_pos.z);
rotation.rotY(degree);
translation.combineTransform(rotation);

}

It moves very oddly.

Also, tracing out cube.getPosition() when rotating the cube on the Y axis, the x and z values change, even though the cube isn't moving, just rotating around its centre point. Any ideas why that might be? I've attached a rough test

Posted by: 3wme Mar 2 2007, 01:53 PM


I meant :

rot_right_btn.onRelease=function(){
degree+=10
rotation.rotY(10)
translation.combineTransform(rotation);
}

So when it comes to move the cube again, I know the total degree rotated

Posted by: Petit Mar 2 2007, 05:50 PM

QUOTE(3wme @ Mar 2 2007, 02:53 PM) *

I meant :
rot_right_btn.onRelease=function(){
degree+=10
rotation.rotY(10)
translation.combineTransform(rotation);
}
So when it comes to move the cube again, I know the total degree rotated

Well I haven't used combineTransform myself, but before running into the button handlers, I'm a bit curious on how you start out with your scene. You do this
CODE
var tGroup = new sandy.core.group.TransformGroup();
var translation = new sandy.core.transform.Transform3D();

var rGroup = new sandy.core.group.TransformGroup();
var rotation = new sandy.core.transform.Transform3D();

translation.translate(0, 0, 0);
rotation.rotY(0);

translation.combineTransform(rotation);
tGroup.setTransform(translation);

var cube = new sandy.primitive.Box(70, 30, 30, "tri");

tGroup.addChild(cube);
rGroup.addChild(tGroup);
root.addChild(rGroup);

Here you do a combination of the translation and rotation.
That makes me a bit curious as to why you use both the tGroup and rGroup.
I'm certain to have missed something here.

Posted by: 3wme Mar 2 2007, 06:25 PM

CODE


var world:World3D = World3D.getInstance();
var root:Group = new Group();         
world.setRootGroup( root );    

var tGroup:TransformGroup = new TransformGroup();
var translation:Transform3D = new Transform3D();
var rGroup:TransformGroup = new TransformGroup();
var rotation:Transform3D = new Transform3D();

translation.translate(0,0,0)
rotation.rotY(0)
translation.combineTransform(rotation);
tGroup.setTransform( translation );

var cube:Object3D = new Box( 70, 30,30, 'tri' );

tGroup.addChild( cube );
rGroup.addChild( tGroup  );
root .addChild( rGroup );


I've tried combining the transforms in different sequences, but it gives even stranger results. Would it make more sense not to use combineTransform? I'm just working through different options seeing what effects it has. But you're right, the rGroup is redundant.

so:
CODE

translation.translate(0,0,0)
rotation.rotY(0)
translation.combineTransform(rotation);
tGroup.setTransform( translation );

var cube:Object3D = new Box( 70, 30,30, 'tri' );

tGroup.addChild( cube );
root .addChild( tGroup );

still gives the same results. I'm sure I'm missing something simple and obvious.

Posted by: Petit Mar 2 2007, 08:31 PM

QUOTE(3wme @ Mar 2 2007, 07:25 PM) *

I'm sure I'm missing something simple and obvious.

Probably wink.gif I've given it some shots, and I think I see what you want to accomplish .
I didn't come to a good solution, by revising your code, but I remembered to have seen something like this in the forum. I don't remember who created this very elegant demo - Thanks whoever you are!

He is using both buttons and mouse to rotate and move around a cube.
Have a look! I'm sure you have your solution here ( attached ).
I'm sorry I cannot attach the fla, but it is 500 by 500 pixels and contains 10 buttons for control.
The names are obvious from the code and the attached swf, I presume.

[Edit: Sorry, it doesn't really translate the cube, the translation is applied to the camera.]


Attached File(s)
Attached File  cube.as ( 2.87k ) Number of downloads: 8
Attached File  cube.swf ( 31.61k ) Number of downloads: 12

Posted by: 3wme Mar 2 2007, 08:44 PM

Thanks Petit,
I actually looked at that already, it scales and rotates a cube, but doesn't actually move it. I'll have another look

Posted by: zeusprod Mar 6 2007, 02:20 PM

QUOTE(Petit @ Mar 2 2007, 03:31 PM) *

Have a look! I'm sure you have your solution here ( attached ).
I'm sorry I cannot attach the fla, but it is 500 by 500 pixels and contains 10 buttons for control.
The names are obvious from the code and the attached swf, I presume.


The FLA is available in the original forum post by bfi.


Separately, however, I'm a little (perhaps a lot) confused about obtaining the current position, rotation, and scale of an object.

I'm using Sandy 1.1

I see the Object3D.getPosition() method, but that presumably returns the position of an object relative to its parent. (it doesn't seem to return the position in the world, although I could be wrong).

And there is no "getRotation" or "getScale" method. Granted, there is a TransformGroup.getTransform() method, but that returns a matrix. I don't know how to obtain the scale or rotation from that matrix.

Has anyone written such a function?

I'm guessing the easiest way to handle this in 1.1 is to store the rotation, scale, and position as properties of the object so that I don't have to query for them.

Is that correct or am I missing an easier way?

Bruce

Posted by: Petit Mar 6 2007, 04:54 PM

QUOTE(zeusprod @ Mar 6 2007, 03:20 PM) *

I'm using Sandy 1.1
I see the Object3D.getPosition() method, but that presumably returns the position of an object relative to its parent. (it doesn't seem to return the position in the world, although I could be wrong).

I'm guessing the easiest way to handle this in 1.1 is to store the rotation, scale, and position as properties of the object so that I don't have to query for them.
Is that correct or am I missing an easier way?

The getPostion() method in Sandy 1.1 is flawed in its first release. A simple bug fix may be found in http://www.flashsandy.org/forum/index.php?s=&showtopic=351&view=findpost&p=2050.
It should and will return the postion of the object in global ( or world ) coordinates.

To keep track of all rotation. scale and position values of your objects, I believe you're right smile.gif

Posted by: zeusprod Mar 6 2007, 06:28 PM

QUOTE(Petit @ Mar 6 2007, 11:54 AM) *

The getPostion() method in Sandy 1.1 is flawed in its first release. A simple bug fix may be found in http://www.flashsandy.org/forum/index.php?s=&showtopic=351&view=findpost&p=2050.
It should and will return the postion of the object in global ( or world ) coordinates.

To keep track of all rotation. scale and position values of your objects, I believe you're right smile.gif



Oops, yes, I'm using the*patched* Sandy 1.1 release (thanks to your patch!). I'll double-check that I have the patch on this machine.

I'm probably doing something else wrong or checking the position of a face instead of the entire object.

Thanks, I'll figure it out.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)