• Advertisement
Sign in to follow this  

How do I make a 2D Ortho Projection? -- Java

This topic is 3032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a game in C# a while ago, and it used OpenGL. Now when I switched to Java I was pretty grateful that I didn't need an external Graphics Library. I have it set up with a Double Buffer which is much larger then the applet height and width. But I can't find an equivalent Java function to the OpenGL C# function: Gl.glOrtho(); What it does: It takes the rendered area and focuses in on an area. how would I do that in Java?

Share this post


Link to post
Share on other sites
Advertisement
You create an orthographic projection matrix, and need to multiply all your vertices with it (note: I do not know anything about JAVA, and I have no idea if I'm right here, I'm just telling you how OpenGL/DirectX does it)

Now, I wouldn't know how to create this matrix myself, but luckily microsoft documents it pretty well!

scroll down a bit here

Share this post


Link to post
Share on other sites
I looked at the code, and it looks like it's for a 3D projection, I might not have been clear on the fact that I need it 2D, like zooming in.

Share this post


Link to post
Share on other sites
Well you could use a matrix too...

first you want to translate your 'viewing point' to 0, 0, then you want to scale it, and then you want to return to your point...

so create a translation matrix first with, then scale it, then translate back, like this

(I'm assuming you know matrix multiplications and basic matrix operations like scaling and translating)

Translate(-camera.x, -camera.y, 0) * Scale(factor, factor, 1) * Translate(camera.x * factor, camera.y * factor, 0)

Share this post


Link to post
Share on other sites
Thanks for the replies, although I realized that the method I needed this information for wouldn't work because Java createImage() can't handle the size I need. Therefore I discovered an alternative. I'm done with this thread what do I do?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement