Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Calculating normals for heightmap

Hybrid View

  1. #1
    Intern Newbie
    Join Date
    Aug 2013
    Posts
    32

    Calculating normals for heightmap

    Edit: I have this solved now. If anyone is interested...
    vector3d class or more or less float x, y, z with a few functions to help deal with vectors... which are hard to understand but I found a really great site to help explain this http://www.fundza.com/vectors/normalize/index.html
    This looks pretty decent I think.


    Code :
    float vector3d::length()
    {
    	return sqrt(x*x + y*y + z*z);
    }
     
    void vector3d::normalize()
    {
    	float len = length();
    	if(len != 0)
    	{
    		x /= len;
    		y /= len;
    		z /= len;
    	}
    }

    Output
    Code :
    Points
    2 0 0
    2 0 1
    3 0 0
    Normals
    1 0 0
    0.894427 0 0.447214
    1 0 0
     
    Points
    3 0 0
    2 0 1
    3 0 1
    Normals
    1 0 0
    0.894427 0 0.447214
    0.948683 0 0.316228
     
    Points
    3 0 0
    3 0 1
    4 0 0
    Normals
    1 0 0
    0.948683 0 0.316228
    1 0 0

    ...Well crap, I have the normals now what.. lol. Guess I'll have to figure out how to combine this with the rest of the data... then it's textures next I think...I hope, I wanna see some nice grassy hills and a mountain... then a tree.
    Last edited by Exempt; 08-17-2013 at 06:25 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
  •