Game Development Community

Drawing 3D shapes with perspective

by Manuel F. Lara · in Torque Game Builder · 07/05/2006 (8:16 am) · 7 replies

I've noticed 3D shapes are drawn using an orthogonal perspective. That may look OK for player models, but when tring to add big 3D objects like levels and so on, or things that are not centered on the screen, they look VERY ugly, as they lose all depth.

I've been looking at the source code and I think I could modify the code of t2dShape3D::renderObject(..) to change this behavior, but frankly, I don't know how to do it, I'm not very good at 3D math. I don't know if it'll cause any other side problems within TGB, either.

Can anyone shed a light on this?

This is a time where the bounty system would be very helpful. Did it stop working? I'd gladly pay some bucks for having this working, which I guess would be trivial for someone with the math skills needed. Dynamic lights which affect 3d shapes are another thing which I'd pay for.

#1
07/05/2006 (5:15 pm)
So you want to make T2D a 3D engine eh? ;) I was thinking about doing this to avoid using TGE (not because I'm cheap, just that it's going to be a lot more for me to learn) if I ever want to do a full 3D game. I don't know how much 3D math would really be involved, if any... it could be as simple as changing the renderer to not draw the 3D models in Ortho perspective. I'm not sure where exactly this takes place, it has to be somewhere in the scenegraph code.. but I'm no guru with the 3D stuff either.
#2
07/05/2006 (5:17 pm)
If you're using 3d for levels, which are presumably going to be seen from one vantage point, why don't you just pre-render it? Then you can have tons more detail and bake in lighting or whatever you want.
#3
07/05/2006 (8:27 pm)
@Manual [edit: Manuel], interesting - I had not noticed that before.

I also am going to be using 3D objects in my game because of things like full rotation & animation blending, skinning, etc. all things which cannot be done very well with bitmap sprites.

I looked at this for while and I think we just need to add calls to gluPerspective() or gluLookAt() in t2dShape3d::renderOBject. There are tons of OpenGL tutorials on the web so this should definitely be feasible. Although i don't really know opengl and I tried but failed to get it working
// Reset Projection/Modelview.
   glPopMatrix();
   glMatrixMode(GL_PROJECTION);
   // ... add some perspective to the projection here -Alex
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);
#4
07/06/2006 (11:59 pm)
More thoughts: Although ideally you would want to add a TS function to add perspective to any particular object. You might want different perspective for large objects vs. small, or different areas of the scenegraph. It could be controlled by script.
#5
07/07/2006 (12:13 am)
Yeat another thought - although slightly off topic: It would be *very* nice if it were possible to get the collision poly of a 3d shape to follow the visible, planar outline. But I guess thats hard to implement. And before someone screams this is a 2d engine etc etc, I must say that having 3d shapes, which handles with the ease of 2d objects is really handy.
#6
07/07/2006 (12:43 am)
@Johan- definitely! the .dts format has a lot of cool features that we could exploit, with some serious C++ opengl hacking.
#7
07/07/2006 (9:40 am)
I want everything you guys want. In a post I made earlier, however, it was said that there are no plans to expand the 3d functions of this engine.

I really don't understand it, either. To me, a 2d engine isn't about just using 2d graphics. A 2d engine is being able to edit on a 2d plane rather than worry about the z axis. In other words, 3d graphics on a 2d engine is a feature which could only make this engine better. It isn't turning it into a 3d engine - just expanding the possibilities. I could easily make some nice 3d graphics which look like 2d graphics. The only difference is the animation will be MUCH smoother, the customizability will me MUCH higher, and creating more variety will be MUCH easier.

Combining 3d with 2d doesn't make things harder. It makes things easier. People act like making 2d graphics is easy. Well, maybe for crappy 2d graphics it is easy. But creating hundreds of fully animated 2d objects takes months worth of efforts. Making excellent 2d graphics which are in pieces to allow fully customizable 2d objects and still making a smooth animation and graphics that look good is an even harder task. Using 3d objects to do this saves hundreds of hours of work IN ADDITION to producing better results. Using 3d in a 2d engine isn't a bad thing. It allows for people that don't have hundreds of hours to spare and don't have the resources to create hundreds of 2d graphics a chance to produce professional results. That is my opinion, anyway. I'm a graphics artist by nature but with natural skill in math, and I've spent hundreds of hours on 2d. I've also spent many hours on different engines piecing together 2d objects for customizing. I've spent many hours on 3d, and can produce very good results in a fraction of the time. It takes more time to get a starting product, but from that it allows you to do so much with 3d.

My main problem has always been pre-rendering. Pre-rendering 3d graphics defeats the purpose of it, I say. And thats is what I've always done. How much time it would save, and how much function it would add, to have a 2d engine by nature to use a wide variety of 3d effects. It isn't about having a traditional 2d game; thats living in a archaic world which wastes time. It is about using modern technology to produce results faster, yet visually the same as traditional graphics. Thats my opinion on the matter.

Not that my pathetic little opinion matters for this engine. Their minds are already made up.

So hey, I'm with you guys. If only I knew more about C++. I'd be able to do this myself rather easy. 3d maths are pretty simple if you ask me.