Author Topic: How to caculate the screen position?  (Read 3386 times)

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
How to caculate the screen position?
« on: January 06, 2015, 11:41:48 am »
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 ! :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to caculate the screen position?
« Reply #1 on: January 06, 2015, 05:29:40 pm »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to caculate the screen position?
« Reply #2 on: January 07, 2015, 01:05:34 am »
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 !

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to caculate the screen position?
« Reply #3 on: January 08, 2015, 01:59:27 am »
Any one help me?  thanks   ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to caculate the screen position?
« Reply #4 on: January 08, 2015, 08:29:08 am »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to caculate the screen position?
« Reply #5 on: January 08, 2015, 09:04:26 am »
Oh , thanks , The road is closed,  the view position changed every frame, should I  create vertex  every frame?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to caculate the screen position?
« Reply #6 on: January 08, 2015, 09:50:22 am »
Is that needed? The actual screen position of the end doesn't really change, or does it?

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to caculate the screen position?
« Reply #7 on: January 08, 2015, 10:11:41 am »
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 .

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: How to caculate the screen position?
« Reply #8 on: January 09, 2015, 05:36:54 pm »
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.

Offline gamenewer

  • long
  • ***
  • Posts: 171
    • View Profile
Re: How to caculate the screen position?
« Reply #9 on: January 10, 2015, 12:50:59 am »
A backdrop image may be a simple solution, i will try ajust y position  for diffrent  device screen size