Android Tutorial How to make games

Discussion in 'Tutorials & Examples' started by Informatix, Sep 12, 2013.

  1. wonder

    wonder Expert Licensed 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?
     
  2. Informatix

    Informatix Expert Licensed User

    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).
     
  3. wonder

    wonder Expert Licensed 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...).

    [​IMG]
    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!!! :D
     
    Last edited: Jun 8, 2016
  4. Informatix

    Informatix Expert Licensed User

    It's what decals are.

    I would not even try because they cannot share the camera or a loaded object.
     
  5. wonder

    wonder Expert Licensed 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.
     
  6. Informatix

    Informatix Expert Licensed User

    ??? I mean the orthographic or perspective camera object used by libGDX.
     
  7. wonder

    wonder Expert Licensed 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: Jun 8, 2016
  8. Informatix

    Informatix Expert Licensed 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.
     
  9. wonder

    wonder Expert Licensed User

    Alright, here it is, but only as a proof of concept.
    Like I predicted, no stability at all, huge frame rate drops.

    Ladies and gentleman, my Frankenstein monster:

    jPCT + LibGDX

    Don't try this at home. :D
     
  10. ilan

    ilan Expert Licensed 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: Nov 15, 2016
  11. wonder

    wonder Expert Licensed User

    Code:
    //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 and Informatix like this.
  12. ilan

    ilan Expert Licensed 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:

    Code:
    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
     
  13. wonder

    wonder Expert Licensed 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...
     
  14. melonZgz

    melonZgz Active Member Licensed User

    A lgMathVector2 has a dst or dst_xy function
    so if body1 and body2 are lgBox2DBody you could use
    Code:
    distance = body1.Position.dst(body2.Position)
     
    Informatix likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice