Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object calcShadows(Object *target, Object *target2, LightSource light, vector<double> index) {
- Object shadowMesh;
- for (int i = 0; i < target->vertices.size(); i++) {
- Vect3D direction = light.pos.Sub(target->vertices[i]);
- direction = direction.Normal();
- for (int j = 0; j < target2->oldFaces.size(); j++) {
- Vect3D p1 = target2->oldFaces[j].v3.Sub(target2->oldFaces[j].v1);
- Vect3D p2 = target2->oldFaces[j].v2.Sub(target2->oldFaces[j].v1);
- Vect3D n = p1.crossProduct(p2);
- double d = n.dotProduct(target2->oldFaces[j].v1);
- double t;
- if (n.dotProduct(direction) != 0) {
- t = (d - n.dotProduct(light.pos)) / n.dotProduct(direction);
- }
- t = t * 0.9998;
- Vect3D hitP = direction.Mlt(t);
- hitP = hitP.Add(light.pos);
- shadowMesh.vertices.push_back(hitP);
- }
- }
- Color shadowC;
- if (target2->oldFaces.size() > 0) {
- 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);
- }else {
- shadowC = Color(50, 50, 50);
- }
- shadowMesh.index = index;
- for (int i = 0; i < index.size(); i += 3) {
- 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));
- }
- return shadowMesh;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement