How to caculate the screen position?

Started by gamenewer, January 06, 2015, 11:41:48 AM

Previous topic - Next topic

gamenewer

Hello , I use a picture to show my question.  I use framebuffer.blit  to show a far scene in my game, as red part in picture, the far scene position at the road end ( maybe not the end , as far as see ,hope you can see my mean). My question is : How to caculate the Y position?(as blue line show in picture),  Thanks ! :)

EgonOlsen

http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Interact2D.html has some methods to do such things. In your case, you might want to look at the project3D2D-methods.

gamenewer

Thank you Egon, I try use this method :project3D2D(Camera camera, FrameBuffer buffer, SimpleVector vertex), I only know the  y=0  of  the vertex parameter, becuse  the road  place on the groud( y = 0),  I have no idea  how to set the  parameter vertex.  Could you help me ? Thanks !

gamenewer


EgonOlsen

You need some vertex at the end of the road. Either take it from the mesh or create it out of the data that http://www.jpct.net/doc/com/threed/jpct/Mesh.html#getBoundingBox() returns.

gamenewer

Oh , thanks , The road is closed,  the view position changed every frame, should I  create vertex  every frame?

EgonOlsen

Is that needed? The actual screen position of the end doesn't really change, or does it?

gamenewer

I show a picture, fisrt at  point  1 , the end at  the end_1 , if at the point 2 , the end at the end_2 .Yes, the actual screen position of the end doesn't really change, but  I don't  know   how to get the  correct vertex .

EgonOlsen

Either choose a pragmatic solution and create a backdrop image that will still look good when there's a small gap between the road and the city scene or you could simply iterate once over all vertices after setting up the scene and the camera, project everything into 2D and choose the max y value of all.

gamenewer

A backdrop image may be a simple solution, i will try ajust y position  for diffrent  device screen size