1
\$\begingroup\$

I want to convert the camera coordinate to screen coordinate. I have asked this question because my camera is 48m wide and 32m high but my screen is 480x320 pixels. So whatever collision point I get those are based on camera. Also I like to mention that my camera set at center of the screen. So I get (0,0) coordinate at middle of the screen. At collision time I put some particle effect but now that particle effect not at correct place in the screen. So someone from community please help.

\$\endgroup\$

3 Answers 3

7
\$\begingroup\$

How about using the project-method in the camera class.

camera.project(Vector3 worldPoint)

That projects the vector cameraPoint from world/camera coordinates into screen/window coordinates. The reverse method is camera.unproject(Vector3 screenPoint). Have a look at the libgdx camera class.

\$\endgroup\$
1
  • \$\begingroup\$ This is the right way to do it +1 :D \$\endgroup\$
    – arielsan
    Aug 24, 2012 at 16:21
2
\$\begingroup\$

Taken from http://www.badlogicgames.com/wordpress/?p=2032

I'm only assuming that this will help based on your question...

Ray pickRay = cam.getPickRay(Gdx.input.getX(), Gdx.input.getY());
Intersector.intersectRayPlane(pickRay, xzPlane, intersection);
\$\endgroup\$
0
1
\$\begingroup\$

What you need to do is to translate the camera coordinates into viewspace.

In this particular case your Camera coordinates go from [-24,-16] to [24,16] and you want that to translate to [0,0] to [480,320].

Pseudo code:

view.X = camera.X * 10 + view.width / 2
view.Y = camera.Y * 10 + view.height / 2
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .