Rick Posted July 31, 2011 Share Posted July 31, 2011 I'm drawing health bars for my units by getting the model AABB and position in 3D space. I then use the y1 value of the AABB in replace of the y value in the position to make a new Vec3 object which I then pass to CameraUnproject. So in my case this should get me a2D point directly above the models head. I then move that point some pixels to the left and that's the X for my rectangle. This works pretty well but I would expect the rectangle to always look pretty much center over the head all the time. In the 2 pictures I've rotated on the left and right side and you can see the health bar sort of slides to one side or the other. for k1,v1 in pairs(v) do aabb = GetEntityAABB(v1.model) pos = v1.model:GetPosition(1) -- replace the y value with the height of the bounding box pos.y = aabb.y1 + .25 result = CameraUnproject(camera, pos) SetColor(COLOR_RED) DrawRect(result.x - 25, result.y, 50, 5) SetColor(COLOR_GREEN) DrawRect(result.x - 25, result.y, 50, 5) end Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted July 31, 2011 Share Posted July 31, 2011 That is awesome! Thank you for sharing Rick Quote Link to comment Share on other sites More sharing options...
Rick Posted July 31, 2011 Author Share Posted July 31, 2011 I guess I was asking a question in there too Indirectly it would seem. Based on the camera angle the 2D drawing isn't always centered which is what I'm looking for. Quote Link to comment Share on other sites More sharing options...
Rekindled Phoenix Posted August 1, 2011 Share Posted August 1, 2011 Maybe get the width of the AABB bounding box showing on-screen and adjust pixels appropriately? Quote Link to comment Share on other sites More sharing options...
VeTaL Posted August 1, 2011 Share Posted August 1, 2011 //Maybe get the width of the AABB bounding box showing on-screen and adjust pixels appropriately? Looking like its too long.. Rick, maybe you sould just take the origin of model (if it is in center in 3d), move up (in 3d) and move (in 2d) panel half-of-its-width left? Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Rick Posted August 1, 2011 Author Share Posted August 1, 2011 Model origin is the middle by the feet. I wanted to use the height of the BB because each model has a different height, I just didn't want to hardcode that per model. And I am doing 1/2 the panel width to the left. So basically I'm doing that you are saying. The only difference being I'm using BB top y value instead of hardcoding. That shouldn't affect the x placement of the 2D image though? This isn't a massive issue, just something that would be nice to always have it look perfect. I've moved on, but might come back later. Quote Link to comment Share on other sites More sharing options...
VeTaL Posted August 1, 2011 Share Posted August 1, 2011 //And I am doing 1/2 the panel width to the left. Pretty strange - it souldn't be like on your pictures... Try to simplify calculations and comment out second step (moveing panel up) Quote Working on LeaFAQ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.