Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create a vector representing the vector from the iDraw to the camera
- Vector toCam;
- toCam = _position - _camera->GetPosition();
- //Normalize toCam so it represents only the direction
- toCam.Normalize();
- //Create a vector representing the heading of a directional light
- Vector toLight(4, NULL);
- toLight(0) = 1;
- toLight(1) = 1.8;
- toLight(2) = 1;
- //Normalize toLight
- toLight.Normalize();
- //Create a vector representing the rotated face normal
- Vector faceNormal;
- //For each face
- for (int i = 0; i < _numFaces; i++)
- {
- //Rotate _faceNormal at i and store
- faceNormal = _faceNormals[i] * _coordinateSystem;
- //Determine color
- //The dot product of two vectors is the magnitude of the vectors multiplied by the cosine of the angle between them
- //Find the dot product of the face normal with the vector representing the direction of the light
- float dotProd = toLight.DotProduct(faceNormal);
- //The dot product between two normalized vectors is the cosine of the angle between them
- //Cosine is bound between -1 and 1. When the angle is 0, PI or any equivilent value the surface must be directly lit and cosine will equal +-1
- //When the angle is PI/2 or any other multiple of the surface is recieving no direct light and should be dark and cosine will equal 0
- //Consider the angle between the faceNormal and the toCam vector
- //When cosine of the angle is positive, the face shouldn't be drawn as it does not face you- it is facing the same direction as you
- //The dot product of the face normal with the normalized toCam vector will return the cosine of the angle between them
- //This is called Backface Culling
- //IF the face is facing us
- if (toCam.DotProduct(faceNormal) <= 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement