Thread: Calculating Perfect Graphic Heights using Model Vertex Data

Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1 Calculating Perfect Graphic Heights using Model Vertex Data 
    Jire
    Jire's Avatar
    Join Date
    Nov 2008
    Posts
    34
    Thanks given
    193
    Thanks received
    70
    Rep Power
    608
    This will allow you to grab an appropriate height for the end height of projectiles, for instance.
    You use this to automatically apply perfect graphic/projectile heights for anything.

    Notice how the arrow lands exactly at the perfect spot for each NPC:
    rats are right at the ground, imps in the middle, and men at the top

    Attached image

    First we need to be able to determine model height per model:
    Code:
    public static int modelHeight(int modelID) {
        ModelDefinition definition = forID(modelID);
        if (definition == null) {
            return -1;
        }
        return Math.max(Math.abs(definition.highestY), Math.abs(definition.lowestY));
    }
    To determine our highest/lowest vertex values, simply loop through your model vertices:
    Code:
    void calculateModelBounds() {
        lowestX = 32767;
        lowestY = 32767;
        lowestZ = 32767;
        highestX = -32768;
        highestY = -32768;
        highestZ = -32768;
    		
        for (int i = 0; i < vertexCount; i++) {
            int x = xVertices[i];
            int y = yVertices[i];
            int z = zVertices[i];
    
            if (x < lowestX) {
    	    lowestX = x;
    	}
    	if (x > highestX) {
    	    highestX = x;
    	}
    	if (y < lowestY) {
    	    lowestY = y;
    	}
    	if (y > highestY) {
    	    highestY = y;
    	}
            if (z < lowestZ) {
                lowestZ = z;
            }
            if (z > highestZ) {
                highestZ = z;
            }
        }
    }
    For NPCs for example, you need to loop through all of their models:
    Code:
    int npcModelHeight = -1;
    for (int modelID : npc.getDefinition().getModelIDs()) {
        int modelHeight = ModelDefinition.modelHeight(modelID);
        if (modelHeight > npcModelHeight) {
            npcModelHeight = modelHeight;
        }
    }
    Once you have your highest model height, we divide by 8 (>>> 3) to get the center of the NPC:
    Code:
    int centerHeight = npcModelHeight >>> 3;
    Finally, to determine the height to use for graphic end heights, it's just 50% more than the center height.
    Code:
    int headHeight = centerHeight * 1.5;
    I recommend clamping this so a minimum of 8 and maximum of 96 for use as projectile end height, like so:
    Code:
    Math.max(8, Math.min(96, headHeight))
    You're also able to determine the absolute peak point of the NPC, which is just double the center:
    Code:
    int peakHeight = centerHeight * 2;
    Hope you enjoyed!
    Discord: jire
    Reply With Quote  
     


  2. #2  
    Super Donator

    StanDev's Avatar
    Join Date
    Apr 2014
    Posts
    660
    Thanks given
    82
    Thanks received
    255
    Rep Power
    592
    Nice idea, good job
    Reply With Quote  
     

  3. #3  
    Registered Member
    thing1's Avatar
    Join Date
    Aug 2008
    Posts
    2,111
    Thanks given
    131
    Thanks received
    1,099
    Rep Power
    2402
    Amazing work as usual
    Reply With Quote  
     

  4. #4  
    🎶 As you're falling down 🎶


    uint32_t's Avatar
    Join Date
    Feb 2015
    Posts
    1,396
    Thanks given
    6,177
    Thanks received
    776
    Rep Power
    5000
    Nice work + nice signature.
    Quote Originally Posted by Idiot Bird View Post
    Quote Originally Posted by Velocity View Post
    lol np mate looks like the community brought ur rep down to ur IQ
    Not too sure about that, it's at 0 . It would have to go minus to even be remotely close to his IQ.
    Reply With Quote  
     

  5. #5  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Is there any situation the height should be something different?
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  6. #6  
    Jire
    Jire's Avatar
    Join Date
    Nov 2008
    Posts
    34
    Thanks given
    193
    Thanks received
    70
    Rep Power
    608
    Quote Originally Posted by mige5 View Post
    Is there any situation the height should be something different?
    The only situation I can think of is for NPCs whos animation makes them "hover" off the ground like for Avansies in GWD. Personally I just hard set the end heights for them, although I'm sure you could loop through animation frames of the NPC's standing animation to calculate the offsetted height.
    Discord: jire
    Reply With Quote  
     

  7. #7  
    Renown Programmer
    Greg's Avatar
    Join Date
    Jun 2010
    Posts
    1,179
    Thanks given
    260
    Thanks received
    1,012
    Rep Power
    2003
    Quote Originally Posted by mige5 View Post
    Is there any situation the height should be something different?
    Quote Originally Posted by Jire View Post
    The only situation I can think of is for NPCs whos animation makes them "hover" off the ground like for Avansies in GWD. Personally I just hard set the end heights for them, although I'm sure you could loop through animation frames of the NPC's standing animation to calculate the offsetted height.
    I presume this doesn't work for anything that flys; bats, birds, axes etc?

    From the code it doesn't look like it takes tile height into account either, so what happens if an npc is on a mountain or something?

    It's a nice idea, especially since not a lot of people don't use the server-side calculation for height, but as with all protocol changes, there's probably a good reason why Jagex didn't do it that way in the first place.
    Attached imageAttached image
    Reply With Quote  
     

  8. #8  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Quote Originally Posted by Greg View Post
    I presume this doesn't work for anything that flys; bats, birds, axes etc?

    From the code it doesn't look like it takes tile height into account either, so what happens if an npc is on a mountain or something?

    It's a nice idea, especially since not a lot of people don't use the server-side calculation for height, but as with all protocol changes, there's probably a good reason why Jagex didn't do it that way in the first place.
    I may be wrong but I don't think standing on a mountain would matter, pretty sure client already takes the tile height into account with projectiles (and other entities).
    This seems like a nice idea but don't think people will bother considering you'll have to go through the trouble of loading the models server-sided.
    [Today 01:29 AM] RSTrials: Nice 0.97 Win/Loss Ratio luke. That's pretty bad.
    [Today 01:30 AM] Luke132: Ok u fucking moron i forgot i could influence misc.random
    Reply With Quote  
     

  9. Thankful users:


  10. #9  
    Jire
    Jire's Avatar
    Join Date
    Nov 2008
    Posts
    34
    Thanks given
    193
    Thanks received
    70
    Rep Power
    608
    Quote Originally Posted by Greg View Post
    I presume this doesn't work for anything that flys; bats, birds, axes etc?

    From the code it doesn't look like it takes tile height into account either, so what happens if an npc is on a mountain or something?

    It's a nice idea, especially since not a lot of people don't use the server-side calculation for height, but as with all protocol changes, there's probably a good reason why Jagex didn't do it that way in the first place.
    The "hover" standing animation needs to be accounted for, might try to solve it later with animation frames.

    The tile height is automatically accounted for in the client, however.
    Discord: jire
    Reply With Quote  
     

  11. #10  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Quote Originally Posted by Jire View Post
    The "hover" standing animation needs to be accounted for, might try to solve it later with animation frames.

    The tile height is automatically accounted for in the client, however.
    If thats all, If u do that, can't u just do all of this client-sided then and remove the need of sending the height server-sided.
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Similar Threads

  1. Most Bank Coords, Perfected(Can be used for PVP)
    By George in forum Configuration
    Replies: 21
    Last Post: 04-11-2013, 08:33 PM
  2. [Hyperion] Graphic Height Levels (gfx100)
    By Shamon King in forum Tutorials
    Replies: 9
    Last Post: 12-08-2009, 05:46 PM
  3. Problem using model preloader
    By Ex-Ex in forum Help
    Replies: 2
    Last Post: 11-30-2009, 11:40 PM
  4. Inserting and using models...
    By !!!bLuE!!! in forum Help
    Replies: 0
    Last Post: 11-11-2009, 11:37 AM
  5. Arithmetic Calculating! - SIMPLE AND VERY USEFUL!
    By LiL PhYScO in forum Application Development
    Replies: 6
    Last Post: 05-24-2009, 05:38 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •