Results 1 to 3 of 3

Thread: [ogLib] The Model Positioning Problem

  1. #1
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default [ogLib] The Model Positioning Problem

    The Model Positioning Problem



    Introduction


    A lot of complaints regarding ogLib, or OpenGL for that matter, pan around the issue of locating models. Sure, we can get the X and Y of a model, but some aren't exactly where they appear to be, or where ogLib thinks they are. Take the following example:

    B is the actual position of the model. However, the real model appears to be higher, at A. Or, rather, the area that we'd interact with. This is part of the reason I made .adjustPosition(). However, adjusting the position manually wouldn't quite cut it. Sure, we could simply:
    Simba Code:
    ogl.getModels(gargoyleID)[0].adjustPosition(0,-100)
    In this occasion, that'd work great. However, what about when the camera is adjusted as seen below:

    Now the position would be incorrect by ~80px. This is where we run into our problem. However, with ogLib, you can get the height, or verticalDegrees, of the camera which can be used to adjust your offset!

    For now, let's make a temporary variable for camera adjustment. We can see that at 0 degrees, we require an offset of -100px. However, at 52 degrees, we only require -20px, making a difference of 80px:
    Simba Code:
    verticalDegrees:=mainScreen.getVerticalDegrees();
    //~ -100px is the maximum offset.
    //~ When verticalDegrees is 52, we need to add 80px.
    //~ We need to get a percentage of 80px.
    //~ We need to remove that percentage from -100px.

    cameraAdjustment:=round(-100{px}+(52{degrees}-verticalDegrees)/52{degrees}*80{px});
    somePoint:=ogl.getModels(gargoyleID)[0].adjustPosition(0,cameraAdjustMent);

    That would be the complicated way of doing it. You could just assume 0 degrees is an offset of 100px, while 90 degrees is an offset of 0px:
    Simba Code:
    verticalDegrees:=mainScreen.getVerticalDegrees();
    cameraAdjustment:=round((90{degrees}-verticalDegrees)/90{degrees}*-100{px});
    somePoint:=ogl.getModels(gargoyleID)[0].adjustPosition(0,cameraAdjustMent);

    Or, if you felt like dealing with radians (credit to @Zyt3x):
    Simba Code:
    cameraAdjustment:=round((-1+sin(mainScreen.getVerticalRadians()))*90);



    Hope this helps!
    Last edited by Obscurity; 08-04-2015 at 12:28 AM.




    Skype: obscuritySRL@outlook.com

  2. #2
    Join Date
    Jun 2018
    Posts
    1
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It's a kind of nice info u have shared

  3. #3
    Join Date
    May 2012
    Location
    Glorious Nippon
    Posts
    1,011
    Mentioned
    50 Post(s)
    Quoted
    505 Post(s)

    Default

    Quote Originally Posted by hiretablets View Post
    It's a kind of nice info u have shared
    Don't gravedig a 3-year-old thread.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •