project 3D to 2D

Started by guillaume, December 12, 2011, 09:08:57 AM

Previous topic - Next topic

guillaume

I have a dummy Object, which has a child Object called Object A, vertex a is one of A's vertex,
I want to project vertex a to screen, it seems that I can not just use Interact2D.project2D3D
and take a as its argument to get the proper 2D coordinate, so what should I do ? thanks.


guillaume

I use the following code to project a vertex to screen, and the following output seems not what I want.
the mesh belong to a object which has a parent dummy object, I have scale and transfer the parent dummy object  to let
the object totally visible in the screen.  my question is how can I project a vertex which belong to a dummy object's son object ? sorry for my poor english.

public class VertexInfo extends GenericVertexController {

@Override
public void apply() {
// TODO Auto-generated method stub
SimpleVector[] sv = this.getSourceMesh();
Logger.log("mesh");
for(int i=0; i<sv.length; i++){
Logger.log(sv[i].toString());
}
// sort out the topLeftVertex
mMesh = new SimpleVector[sv.length];
for(int i=0; i<sv.length; i++){
mMesh[i] = SimpleVector.create(sv[i]);
}
}
private SimpleVector[] mMesh = null;
public SimpleVector getTopLeftVertex(Camera cam, FrameBuffer fb){

SimpleVector s = new SimpleVector();
for(int i=0; i<mMesh.length; i++){

SimpleVector sv = Interact2D.project3D2D(cam, fb, mMesh[i]);
Logger.log("project "+mMesh[i].toString()+" to "+sv.toString());
if(sv.x <= s.x && sv.y <= s.y){
s = SimpleVector.create(sv);
}

}
return s;
}

}

the output goes here:
mesh
(200.0,-15.0,50.0)
(-200.0,-15.0,50.0)
(-200.0,-15.0,-50.0)
(200.0,-15.0,-50.0)
(200.0,5.0,50.0)
(200.0,5.0,-50.0)
(-200.0,5.0,50.0)
(-200.0,5.0,-50.0)
project (200.0,-15.0,50.0) to (1496.2988,145.64708,0.0085648345)
project (-200.0,-15.0,50.0) to (-696.2988,145.64708,0.0085648345)
project (-200.0,-15.0,-50.0) to (-5812.3594,278.66663,0.048534058)
project (200.0,-15.0,-50.0) to (6612.3594,278.66663,0.048534058)
project (200.0,5.0,50.0) to (1447.0271,253.25842,0.008179899)
project (200.0,5.0,-50.0) to (5304.495,754.7368,0.03831637)
project (-200.0,5.0,50.0) to (-647.0271,253.25842,0.008179899)
project (-200.0,5.0,-50.0) to (-4504.495,754.7368,0.03831637)
top left of current board: (0.0,0.0,0.0)

EgonOlsen

That's because the method expects coordinates in world space but you are giving it object space coordinates. The PolygonManager has a method to get the actual world space coordinates. Maybe that helps.

guillaume

thanks. this is exactly what I want.