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=351 as retrieved on 2 Aug 2007 07:09:53 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:_y95t_7JvV4J:www.flashsandy.org/forum/index.php%3Fact%3DPrint%26client%3Dprinter%26f%3D17%26t%3D351+act%3DPrint+%22index+php%22+-lofiversion+site:www.flashsandy.org&hl=en&ct=clnk&cd=84


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

Printable Version of Topic

Click here to view this topic in its original format

Sandy's Forum _ AS2 1.x versions _ getPosition()

Posted by: cjstudios Mar 2 2007, 08:18 AM

Hi there, I'm fairly new to Sandy. currently using 1.1

I've written a test script to try and get a 3d object's position after applying a translation to it.

CODE

import sandy.core.data.*;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.view.*;
import sandy.core.*;
import sandy.skin.*;
import sandy.util.*;
import sandy.core.transform.*;
import sandy.events.*;

var world = World3D.getInstance();
var o:Object3D;
var cam:Camera3D;

function init (Void):Void
{
    // screen creation, the object where objects will be displayed.
    var ecran:ClipScreen = new ClipScreen (this.createEmptyMovieClip ('ecran', 1), 600, 600);
    // we create our camera
    cam = new Camera3D (700, ecran);
    // we add the camera to the world
    world.addCamera (cam);
    // we create the root node.
    var bg:Group = new Group ();
    // and set it as the root node of the world.
    world.setRootGroup (bg);
    // and we lauch the scene creation
    createScene (bg);
    world.addEventListener (World3D.onRenderEVENT, this, update);
    // and now that everything is created, we can launch the world rendering.
    world.render ();
}

function update() {
    trace(o.getPosition());
}


function createScene (bg:Group):Void
{
    // We create our object. It is a cube of 50 pixels, and with the quad mode, so here four points per face.
    o = new Box (50, 50, 50, 'quad');
    // we create a skin to "dress up" the object a bit, and make it visually better.
    //  SimpleColor skin is used here, it needs the fill color, alpha, and thickness
    var skin:Skin = new MixedSkin (0x00FF00, 100, 0, 100, 1);
    // We apply the skin to the object
    o.setSkin (skin);
    // We create two TransformGroup instances. Each one corresponds to a node of the tree we are going to create.transformations
    var tg1:TransformGroup = new TransformGroup ();
    //var tg2:TransformGroup = new TransformGroup ();
    // We also create two instances of Translation objects.
    // Give them an appropriate name, this becomes important very rapidly.
    var translation:Transform3D = new Transform3D ();
    //var rotation:Transform3D = new Transform3D ();
    // we translate the object by 500 pixels on the Z axis.
    translation.translate (0, 0, 1000);
    // We rotate the object by 30 degrees on an axis oriented from the origin to the point (1, 1, 1).
    //rotation.rotAxis (new Vector (1, 1, 1), 30);
    /// We apply those transformations to the nodes.
    tg1.setTransform (translation);
    //tg2.setTransform (rotation);
    // We add the rotation transformation to the node which represents the rotation by setting it as a child.
    // The rotation will be applied first, translation later (higher in the tree)
    //tg2.addChild (o);
    // Now we link the two nodes
    // The order here is very important.
    tg1.addChild (o);
    // Now we simply link the translation node to the root node, thus completing the tree creation
    bg.addChild (tg1);
}
// We launch the animation creation.
init ();


I've put a trace in the WorldOnRenderEvent. my Object3D's (o) initial getPosition result is 0,0,0 but changes to some strange value -17475,17475,17475 during each render cycle even when I haven't done any translation to it. I also notice that this return value is dependent on the camera, the values change if I only move the camera around.

my quesitons:

1. how do I get an Objects Position vector in world coordinates efficiently?
2. what is the value getPosition is returning?

Thanks

Posted by: Vatrobot Mar 2 2007, 11:15 AM

Hi!

Well, I've had some brainwork on this one too.
For Example this is the method I use for getting a "correct" actual position of an object:

var __posMatrix = posInt.getMatrix(); // posInt is a PositionInterpolator declared in a class
var __actualPos:Vector = new Vector(__posMatrix.n14,__posMatrix.n24,__posMatrix.n34);

Stick to Matrix for accurate manipulation! my advice.

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

QUOTE(cjstudios @ Mar 2 2007, 09:18 AM) *

Hi there, I'm fairly new to Sandy. currently using 1.1
I've written a test script to try and get a 3d object's position after applying a translation to it.

my quesitons:

1. how do I get an Objects Position vector in world coordinates efficiently?
2. what is the value getPosition is returning?


Strangely enough, when I compile your code using Sandy 1.1, I get the following trace:
CODE
Vector4 : 0,0,0
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000
Vector4 : 0,0,1000

This suggests that o.getPosition() returns the correct value.
Are you absolutely sure that you compile to the Sandy 1.1 ?

Posted by: Vatrobot Mar 2 2007, 02:55 PM

sorry, forget what i've said, i'm using 1.2 beta wink.gif

Posted by: cjstudios Mar 2 2007, 04:50 PM

yup sure its sandy 1.1

zip file is SANDY_1_1.zip 158 KB (162,214 bytes)

Compiling with Flash professional 8.

I've attached the FLA and the SWF.

the swf will display the coordinates in the textbox every render cycle.


Attached File(s)
Attached File  test2.zip ( 30.28k ) Number of downloads: 10

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

QUOTE(cjstudios @ Mar 2 2007, 05:50 PM) *

yup sure its sandy 1.1

Thanks! I decompiled your SWF to see the difference between the Object3D's we use.
Sure you have Sandy version 1.1, but with a bug in Object3D getPostition() method.

CODE
// bug in Object3D
// This version gives the wrong data
public function getPosition( Void ):Vector
{
    var v:Vertex = aPoints[0];
    return new Vector( v.wx - v.x, v.wy - v.y, v.wz - v.z );
}

And should be changed to this: ( tx, ty,tz instead of wx,wy,wz )
CODE
// This version gives the correct data
public function getPosition( Void ):Vector // Pasted from version 1.2 bug fix
{
    var v:Vertex = aPoints[0];
    return new Vector( v.tx - v.x, v.ty - v.y, v.tz - v.z );
}

That's all there is to it wink.gif

Posted by: cjstudios Mar 2 2007, 06:51 PM

thanks. I downloaded this from the link on your site. you might want to cehck and possibly update the sandy1.1 files in that case.

Posted by: cjstudios Mar 3 2007, 09:11 AM

One more thing I've noticed and would like to get around. Before calling world.render() the object3D.getPosition() returns (0,0,0) I suspect all the group transformations only happen AFTER rendering. what would be the best way to get an object's position before rendering?

i.e. I want to setup a scene but some of my objects are populated relative to other objects so I need their positions.

Posted by: Petit Mar 3 2007, 01:45 PM

QUOTE(cjstudios @ Mar 3 2007, 10:11 AM) *

1. I suspect all the group transformations only happen AFTER rendering. what would be the best way to get an object's position before rendering?
2. i.e. I want to setup a scene but some of my objects are populated relative to other objects so I need their positions.

1. Yes, I've noticed that too.

2. I suspect the safest way, would be to take care of this yourself in the initiation process.
What I mean is, that when you create objects, they are always placed at the origin (0, 0, 0).
Then you know how much you translate them, so that's where they gonna be when you start rendering.
So, I suppose you already know where the objects are when you start.

Posted by: cjstudios Mar 4 2007, 05:48 AM

ok, but what if I have a few branches of translation and rotations about an axis not along the object. then would have to multiply all the transform matrices together in order to obtain the final position of my object wouldn't I? or am I being stupid and missing something?

Thanks again so far for all your prompt replies Petit. I still in the process of reading through ur tutorial as and when I need a particular thing done.

Posted by: Petit Mar 4 2007, 01:25 PM

QUOTE(cjstudios @ Mar 4 2007, 06:48 AM) *

ok, but what if I have a few branches of translation and rotations about an axis not along the object. then would have to multiply all the transform matrices together in order to obtain the final position of my object wouldn't I? or am I being stupid and missing something?

Ah, You're right I believe. But then again, we may both be missing something.
We'll have to discuss a special, well defined problem, to see where it leads dry.gif

Posted by: 3wme Mar 5 2007, 10:18 AM

Does that bug appear in boundingbox functions as well? It seems to be producing odd results, and the code uses wx,wz rather than tx etc?

answered my own question. That fix solves the bug in the bbox.as as well.

Posted by: evanFlash Mar 7 2007, 11:21 PM

Hey guys.
It appears the above fix for getPosition() does not fully solve the problem. My test situation is this:

1) create a plane at the origin with a rotation transform associated with it
2) trace myPlane.getPosition() while adjusting the rotation of the plane along any axis.

The position value is changing, when it most definitely should not be. Any thoughts?

Posted by: Petit Mar 8 2007, 12:22 AM

QUOTE(evanFlash @ Mar 8 2007, 12:21 AM) *

It appears the above fix for getPosition() does not fully solve the problem. My test situation is this:
The position value is changing, when it most definitely should not be. Any thoughts?

Well, I have "fixed" the bug using the above code change,
and uploaded it to the original release post for Sandy 1.1.

You're right of course, the position given by getPosition() is drifting away, even if you only rotate an object.
It start with very small offsets, but seems to grow by the number of rotations.
A thought might be that the precision in the matrix multiplications causes small errors to add up with time.

I don't know if this is addressed in the ongoing AS3 -> AS2 development.
It's hard if you are dependent on a current position for something else to show up on the stage.

Posted by: 3wme Mar 8 2007, 10:27 AM

this is the same problem I'm having. My brute force solution was to store the objects positon before rotation, check the offset after the rotation, and make future transformations allowing for that difference. Its a bit laborious, but seems to work.

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