1

So I am creating a simple 3d render engine in the LWJGL, and I am having issues with the fact that when I back up from an object, it travels to the left and upwards (towards 0,0) when I really need it to travel to screenResX/2,screenResY/2 (maybe 0 I dont know). Is there a way that I can set some kind of variable that will let it fade towards the center?

Additionally, In this engine, I need to bend the polygons to render as if the player was looking at them. At the moment, I only have polygons rendering if you are looking straight at them, and I know that that's not what is needed, can anyone help me?

Thanks in advance for your help, this is my first 3d engine and I'm pretty clueless.

blazingkin
  • 552
  • 1
  • 4
  • 17
  • I don't quite understand the questions. For the first part, do you mean when you pull the camera back by modifying its position? And for the second part, do you mean something like billboards? – PeterT Jan 08 '12 at 10:14
  • @PeterT For the first part, I am pulling the camera back by reducing the size of the polygon as the camera gets further away. – blazingkin Jan 08 '12 at 18:38
  • @PeterT For the second part, I want something that will draw like the you are viewing it from different angles, but it stays facing the same way. looking at it straight on it would be a square, but looking at it slightly turned would make it like a rectangle. – blazingkin Jan 08 '12 at 18:40

1 Answers1

0

So for the first question: Scaling always takes place around the origin. Meaning that you have to translate your object to the origin, scale it and then translate it to its destination. This is better explained here: OpenGL: scale then translate? and how?

But the basics are something like this (from the linked question):

//this moves the scaled 
glTranslatef(destCenter.x, destCenter.y, 0.0);
//scale to the desired factor
glScalef(scaleX, scaleY, 0.0);
//move the center of the scaling operation into the origin
glTranslatef(sourceCenter.x * -1.0, sourceCenter.y * -1.0, 0.0);   

I still don't quite understand your second question, but I am guessing that you mean that you want something to be drawn in perspective rather than in an orthogonal fashion. Have a look at gluPerspective(...) or glFrustum(...) instead of glOrtho(...).

Community
  • 1
  • 1
PeterT
  • 7,981
  • 1
  • 26
  • 34
  • You could use `-sourceCenter.x` instead of `sourceCenter.x * -1.0` for X, and `-sourceCenter.y` instead of `sourceCenter.y * -1.0` for Y. – Daniel Kvist Mar 21 '15 at 21:45