Hey Ari,
Ive been working with a similar issue in reflections. The solution I used
might be useful to you. The particular problem I had was, once I obtained a
3d point that I knew was on the surface of a plane, what would be the 2d
coordinates of that point on the plane? The solution involved determining
the top side and left side vectors of the plane, obtaining a vector from the
top left corner of the plane to the 3d point, and then using dot products to
project that vector onto the side vector. That gives you a scalar value that
corresponds to the coordinate system transformation of the point.
If you think it might help you, here is the code:
//Three vertices.
edgePoint = getVertexGlobalPosition(plane.vertices[0],
plane);
var p2:Number3D = getVertexGlobalPosition(plane.vertices[1],
plane);
var p3:Number3D = getVertexGlobalPosition(plane.vertices[4],
plane);
//Side vectors.
topVector = new Number3D();
topVector.sub(p2, edgePoint);
sideVector = new Number3D();
sideVector.sub(p3, edgePoint);
wRatio = MovieMaterial(plane.material).movie.width/plane.width;
hRatio =
MovieMaterial(plane.material).movie.height/plane.height;
//TRANSLATE GLOBAL TO PLANE.
//Translates a world 3D point to a corresponding 2D point on
the plane's material.
private function
translateGlobalToPlane(point:Number3D):Point
{
/*
Finds a vector from one of the corners of the plane
to the point,
and projects this vector on its sides, considering
scaling.
*/
var v:Number3D = new Number3D();
v.sub(point, edgePoint);
return new
Point(wRatio*v.dot(topVector)/topVector.modulo, hRatio*(this.height -
v.dot(sideVector)/sideVector.modulo));
}
//GET VERTEX GLOBAL POSITION.
//Translates vertex coordinates to world coordinates.
private function getVertexGlobalPosition(vertex:Vertex,
vertexContainer:Object3D):Number3D
{
var m:Matrix3D = new Matrix3D();
m.tx = vertex.x;
m.ty = vertex.y;
m.tz = vertex.z;
m.multiply(vertexContainer.transform, m);
return new Number3D(m.tx, m.ty, m.tz);
}
On Tue, Sep 2, 2008 at 9:34 PM, Ari Braginsky <[EMAIL PROTECTED]> wrote:
>
> I'm having an issue retrieving 2D coordinates off of a mesh based on a
> 3D object's position on the mesh.
>
> You can normally retrieve the 2D coordinates on the bitmap making up
> the mesh by dividing the coordinates of the object by the mesh's X and
> Y scale values (see extrusions/CollisionMap.as class).
>
> However, if you look at the position on the mesh and compare it to the
> raw bitmap, due to some deformations that happen to the mesh with
> certain subdivision values, the objects that appear in the bitmap
> don't line up with the 2D coordinates on the raw bitmap. If you tweak
> the subdivision values, the objects on the bitmap in the mesh move
> around/get squashed/etc.
>
> Example:
>
> Create a bitmap with a circle in the center filled with the color red.
>
> Create an elevation using a flat height map and use the bitmap for its
> skin.
>
> When rendered in 3D, you will see the red circle in the center of the
> mesh. If you move your mouse over it, you can translate the 3D
> coordinates into 2D space and divide them by the mesh's X and Y scale
> values to get the real coordinates on the raw bitmap.
>
> What I'm seeing with subdivision values X = 200 and y = 200 is that my
> point on the mesh doesn't correlate to the same point on the 2D bitmap
> when I convert the 3D coordinates to 2D, taking into account the mesh
> scale values.
>
> Is there something else I need to do to account for the subdivision
> values?
>
> If I didn't want any deformation of the mesh, are there subdivision
> values I can use such that 3D points on the mesh would exactly match
> up with 2D points on the associated bitmap?
>
> Thanks,
> Ari
>
>