Something I thought would be simple...

Started by Cowbox, January 19, 2012, 02:36:03 AM

Previous topic - Next topic

Cowbox

A little while ago, I decided I wanted the FPS of my game to display onscreen.

In other engines this seems to be a trivial task (something along the lines of "print fps" or "g.drawString(fps,0,0);" normally does the trick)

But being the inexperienced Java coder I am, I'm unused to how to seek what I desire from a new set of Java libraries (namely jPCT).

I found there wasn't really a way to do 2D at all... or if there is it's extremely convoluted so I went for just seeing if I could get a picture to display on a plane and have that constantly infront of the camera.

First, it took me a while to figure out how to get transparency to work because the Java docs are wrong (it says the maximum value for setTransparency is 0 - which it isn't: it's 5)

After getting a plane with an alpha mapped .png image to render correctly I then searched for something resembling "position object x,y,z" or "setObjectPosition(float x,float y,float z)" but the only things I can find are all these translate, transform, origin, centre and matrix commands. - I honestly can't tell from the Java docs which one would do what I'd want.

All the positioning commands seem relative to previous movement. - Surely I mustn't have to store the vector an object was translated by, then reverse the translation just to move it somewhere else every time?

I wish to position an object at the camera, then move it forward a unit or so every cycle. But I can't see how in the world I'm supposed to achieve this. xD

Something like this:
while(running){
plane.positionObject(camera.getPositionX(),camera.getPositionY(),camera.getPositionZ());
plane.rotateObject(camera.getAngleX(),camera.getAngleY(),camera.getAngleZ());
plane.translate(0,0,1);
}


I feel incredibly stupid or like I'm missing a huge chunk of methods or something...

This kind of thing is nice and easy in DarkBASICPro/C++/other3Dengines as far as I'm aware.

Someone point me in the right direction D:

EgonOlsen

Quote from: Cowbox on January 19, 2012, 02:36:03 AM
First, it took me a while to figure out how to get transparency to work because the Java docs are wrong (it says the maximum value for setTransparency is 0 - which it isn't: it's 5)
It doesn't say that. It says that 0 is the highest possible transparency, which means the most transparent setting. Maybe the wording is misleading a little bit. The most opaque setting isn't fixed at 5...it's based on some formula that you can tweak in Config. But for the default setting, which tries to mimic the software renderer, 5 is already pretty much opaque.

Quote from: Cowbox on January 19, 2012, 02:36:03 AM
After getting a plane with an alpha mapped .png image to render correctly I then searched for something resembling "position object x,y,z" or "setObjectPosition(float x,float y,float z)" but the only things I can find are all these translate, transform, origin, centre and matrix commands. - I honestly can't tell from the Java docs which one would do what I'd want.
You want translate() in most cases. If you need to set an absolute position, just do


obj.clearTranslation();
obj.translate(x, y, z);



Quote from: Cowbox on January 19, 2012, 02:36:03 AM
I feel incredibly stupid or like I'm missing a huge chunk of methods or something..
If you want to output 2d content, you should rely on texture blitting: http://www.jpct.net/doc/com/threed/jpct/FrameBuffer.html#blit(com.threed.jpct.Texture, int, int, int, int, int, int, boolean). For more convenience regarding text output, have a look here: http://www.jpct.net/forum2/index.php/topic,1074.0.html

Cowbox

:D!!!

Thanks man, you're awesome. :D

I knew it'd be something really silly I was missing like obj.clearTranslation(). xD

And not only that, now I have solutions for the 2D stuff too. :D!!!