Author Topic: project 3D to 2D  (Read 1811 times)

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
project 3D to 2D
« on: December 12, 2011, 09:08:57 am »
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.


Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: project 3D to 2D
« Reply #2 on: December 12, 2011, 11:12:13 am »
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.
Code: [Select]
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)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: project 3D to 2D
« Reply #3 on: December 12, 2011, 12:40:51 pm »
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.

Offline guillaume

  • int
  • **
  • Posts: 67
    • View Profile
Re: project 3D to 2D
« Reply #4 on: December 12, 2011, 01:17:25 pm »
thanks. this is exactly what I want.