Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Object calcShadows(Object *target, Object *target2, LightSource light, vector<double> index) {
  2. Object shadowMesh;
  3.  
  4. for (int i = 0; i < target->vertices.size(); i++) {
  5. Vect3D direction = light.pos.Sub(target->vertices[i]);
  6. direction = direction.Normal();
  7. for (int j = 0; j < target2->oldFaces.size(); j++) {
  8. Vect3D p1 = target2->oldFaces[j].v3.Sub(target2->oldFaces[j].v1);
  9. Vect3D p2 = target2->oldFaces[j].v2.Sub(target2->oldFaces[j].v1);
  10. Vect3D n = p1.crossProduct(p2);
  11. double d = n.dotProduct(target2->oldFaces[j].v1);
  12. double t;
  13. if (n.dotProduct(direction) != 0) {
  14. t = (d - n.dotProduct(light.pos)) / n.dotProduct(direction);
  15. }
  16. t = t * 0.9998;
  17.  
  18. Vect3D hitP = direction.Mlt(t);
  19. hitP = hitP.Add(light.pos);
  20.  
  21. shadowMesh.vertices.push_back(hitP);
  22. }
  23. }
  24. Color shadowC;
  25.  
  26. if (target2->oldFaces.size() > 0) {
  27. shadowC = Color(target2->oldFaces[0].c1.r / light.intensity * 1.2, target2->oldFaces[0].c1.g / light.intensity * 1.2, target2->oldFaces[0].c1.b / light.intensity * 1.2);
  28. }else {
  29. shadowC = Color(50, 50, 50);
  30. }
  31.  
  32. shadowMesh.index = index;
  33.  
  34. for (int i = 0; i < index.size(); i += 3) {
  35. shadowMesh.oldFaces.push_back(Tris(shadowMesh.vertices[index[i] - 1], shadowMesh.vertices[index[i + 1] - 1], shadowMesh.vertices[index[i + 2] - 1], shadowC, shadowC, shadowC));
  36. }
  37.  
  38. return shadowMesh;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement