Android Tutorial How to make games

wonder

Expert
Licensed User
Longtime User
Quick question.

If I wanted to add 3D elements to an already existing LibGDX project, could I do so by adding the JPCT library to the project or would that cause a rip in the spacetime continuum and end the universe as we know it?
 

Informatix

Expert
Licensed User
Longtime User
Quick question.

If I wanted to add 3D elements to an already existing LibGDX project, could I do so by adding the JPCT library to the project or would that cause a rip in the spacetime continuum and end the universe as we know it?
I never used jPCT so I cannot answer for that part, but libGDX is based on OpenGL, so it is able to handle 3D objects. You just miss the high-level implementation and the helper functions (except the perspective camera and the decals, which are 3D classes).
 

wonder

Expert
Licensed User
Longtime User
That's what I thought, it should be able to handle 3D. Nevertheless, jPCT is able to load and handle textured animated models in a really simple manner.
I would be cool to have 2D sprites running in a 3D environment (ahhh... the late 90's...).


2D Sprites in a 3D world

I'm only concerned about the cycle time and overall stability of the project. jPCT does it's own thing in its own thread, just like LibGDX. Having events from both libraries being raised at the same time doesn't seem like a good idea to me.

...doesn't mean I'm not gonna try it, though. For science!!!
 
Last edited:

wonder

Expert
Licensed User
Longtime User
I have my own camera object which can be shared, so that wouldn't be an issue.

With LibGDX's transparent layer, I should be able to give it a try, only to satisfy my curiosity.
As I stated above, I don't believe such a project would ever be stable enough to be anything more than a proof of concept.
 

wonder

Expert
Licensed User
Longtime User
Yes, we're talking about the same thing.
Take my platform game for example (youtube: /watch?v=euTcEVp0afk).

In my main cycle code, the LibGDX camera is completely static, it never pans or zooms.
Instead, I have a class named "NinjaCam" which moves the entire world* in front of the static camera, according to a pivot point (player position).
No performance issues with this approach.

I took this path because I started this project in B4J, where everything was rendered into the Canvas object.

*By "entire world", I mean nothing more than the drawing coordinates of what goes on-screen.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
As you probably noticed, you have to pass the camera projection and view matrices to your SpriteBatch object to render the scene properly. It is what you cannot easily exchange with jPCT.
 

ilan

Expert
Licensed User
Longtime User
hi, is there a simple way to get the distance between 2 box2d bodies?

thank you

EDIT: ok i found a solution, i calculate the difference between body1.y and body2.y after i add to each of them the height of the world in meters. like this i wont have negative floats and the distance will be correct.
 
Last edited:

wonder

Expert
Licensed User
Longtime User
B4X:
//Returns the distance between 2 points in 2D space
double DistanceBetween2D(double x1, double y1, double x2, double y2)
{
    return sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
}
 

ilan

Expert
Licensed User
Longtime User

actually i know this formula but i thought it wont work in a box2d world since box2d world 0,0 is in the middle and you have - and + numbers
but it works.

btw, i used it like this:

B4X:
Sub distanceCalc(x1 As Float, x2 As Float, y1 As Float, y2 As Float) As Float
    Return Sqrt(Power(x2-x1,2)+Power(y2-y1,2)) 'simple distance calculation
End Sub
 

wonder

Expert
Licensed User
Longtime User
Any number multiplied by itself will always output a positive result, so it's all good!

By the way, don't use "power", use multiplication. The distance formula is quite expensive in itself already, so better refrain form two extra function calls...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…