
I'm positioning an MC in three dimensional space using the following:
onClipEvent (load) {
sinY = cosY = 0.707;
cosX = 0.819;
sinX = 0.573;
x = 2;
z = 1;
y = 2;
// place moving block on screen appropriately
this._x = z * sinY + x * cosY;
this._y = y * cosX  (z * cosY x * sinY) * sinX;
}
This is working fine. Now here's the problem. How can I achieve the reverse of this? How can I supply the equation with an MC's stage _x and _Y and have it figure out what the equivalent x,y and z is in the three dimensional space. Can this be done, or am I out of my tree?
thanks in advance,
Paul

You have two equations and three unknowns  not good.
You'll need some other way to figure out one of the varibles to be solved for; any given point (_X,_Y) on the screen can correspond to any number of (x,y,z) points.

thanks  time to go back to school I think :)
I think I'm going to solve this one by realizing that I need to quantify all MCs within the 3d space that I have created, rather than trying to make some calculations based on 2D screen position, and some on 3D.

madskool.wordpress.com
I do a calculation like this. See my 3D engine at.
http://au.geocities.com/brutfood/
When you drag a new object the scene, or move an object already on the stage  it calculates (x,y,z) from (x,y). I always drag objects onto the z=0 plane. And dragging objects, z doesn't change. That's the trick.

Gross Pecululatarian
Ok, I'm assuming that you are drawing in ISO?
Anyway, first work out the bounding box size of one ISO tile, and work out what one the x and y coords are one (Math.floor(y/isotileheight) ect..) And remember that number
Next, you have to find what region of the rectangle you are in. Imagine that there are 5 regions, the first is the shape of the iso tile, the other 4 are the triangles left around the 4 corners. Work out which reigion of iso tile the point is in (make a dummy off screen and hitTest the four bits, or use algebra) and if it's in the center one, the number's you worked out earlier (x/y of the rectangle) is the tile, if it is top left or bottom right, then subtract or add 1 to the x number from earlier, if it's the top right or bot left, add or subtract one from the y axis
Here's an image

madskool.wordpress.com
Originally posted by scootaboy
this._x = z * sinY + x * cosY;
this._y = y * cosX  (z * cosY x * sinY) * sinX;
I suppose it is Isometric. The z value (z * cosY x * sinY) isn't retained to do any perspective calculation or depth/zbuffering.
I found a piece of code I wrote a while back. I'm not sure it's any use to you. I don't use it any more. I can't even remember how it works  but looking at it, I think I know what's going on. The principle was that it went back from 3D coordinates to 2D coordinates. It assumed that the variables sinx,siny etc.. were already set, as you have set them. It undid the perspective transformation first (not applicable to you), then it undid the rotation:
function unrotate(A,B,si,co) {K=si/co;return (A+K*B)/(K*si+co)}
function to3d(xx,yy,zz,i) {
yy=yy*(zz+512)/viewport;
xx=xx*(zz+512)/viewport;
xx0=unrotate(xx,yy,sinz,cosz);
yy0=unrotate(yy,xx,sinz,cosz);
X[i]=unrotate(xx0,zz,siny,cosy);
zz1=unrotate(zz,xx0,siny,cosy);
Y[i]=unrotate(yy0,zz1,sinx,cosx);
// Z[i]=unrotate(zz1,yy0,sinx,cosx)
}
I'm not sure whether this is equivalent, more complex or less complex than Ed's solution.

Gross Pecululatarian
I think yours defines regions.. Probably the same sort of thing.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
