Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


drawing things on top of my heightmap


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 andy1984   Members   -  Reputation: 153

Like
0Likes
Like

Posted 01 May 2013 - 04:04 PM

i'm not good at 3d math (and openGL in general) at all - and i don't really want to learn right now, i just want to get this bit done. there are plenty of tutorials for heightmaps but i can't find examples of drawing an object on top of the heightmap - eg. (1) find the height of a point inside a heightmap cell, translate to that point (2) rotate to align with the cell's plane, so i can draw an object on it (so that the plane's normal is the up direction).

 

i think (1) should be easy, just adding some vectors. but i'm not sure how to do (2).

 

i'm not very familiar with glm but i think i should use this to do the math.

 

i hope i am making sense. any help would be appreciated. thanks :)



Sponsor:

#2 VladR   Members   -  Reputation: 722

Like
0Likes
Like

Posted 06 May 2013 - 01:08 PM

1. To get the exact YPOS of the point on a heightmap, a little bit of trigonometry is needed. Try to draw it on a paper from the front and side view and you should come up with the equations pretty easily yourself (it's just a basic trig - sin/cos and pythagoras)

 

2. You can also do an approximation through lerping - which works well most of the time (unless the difference in slope between two neighbouring tris is too big).

  - Calculate the DeltaY1 for points A,B : DeltaY1 = B.YPOS - A.YPOS

  - calc. DeltaY2 for points A,C. DeltaY2 = C.YPOS - A.YPOS

  - for a point P, on the triangle ABC:

    - PctX = (P.XPOS - A.XPOS) / (B.XPOS-A.XPOS)

    - PctZ = (P.ZPOS - A.ZPOS) / (B.ZPOS-A.ZPOS)

    - Y1 = A.YPOS + PctX*DeltaY1

    - Y2 = A.YPOS + PctZ*DeltaY2

    - final YPOS = Y1 + (Y2-Y1)/2


VladR    My 3rd person action RPG on GreenLight:    http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS