2 This file is part of the 3dengfx, realtime visualization system.
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "shadows.hpp"
24 std::vector<Edge> *create_silhouette(const TriMesh *mesh, const Vector3 &pt) {
25 const GeometryArray<Edge> *mesh_edges = mesh->get_edge_array();
26 unsigned long ecount = mesh_edges->get_count();
27 const Edge *eptr = mesh_edges->get_data();
29 const Vertex *varray = mesh->get_vertex_array()->get_data();
30 const Triangle *tarray = mesh->get_triangle_array()->get_data();
32 std::vector<Edge> *edges = new std::vector<Edge>;
34 for(unsigned long i=0; i<ecount; i++) {
35 const Triangle *t1 = tarray + eptr->adjfaces[0];
36 const Triangle *t2 = tarray + eptr->adjfaces[1];
37 // XXX: assumption that the light direction for one of a triangle's vertices
38 // can be used as the light direction for the whole triangle.
39 Vector3 ldir1 = (pt - varray[t1->vertices[0]].pos).normalized();
40 Vector3 ldir2 = (pt - varray[t2->vertices[0]].pos).normalized();
41 scalar_t t1dot = dot_product(t1->normal, ldir1);
42 scalar_t t2dot = dot_product(t2->normal, ldir2);
44 if((t1dot > 0 && t2dot < 0) || (t1dot < 0 && t2dot > 0)) {
45 edges->push_back(*eptr);
53 void destroy_silhouette(std::vector<Edge> *edges) {
57 TriMesh *create_shadow_volume(const TriMesh *mesh, const Vector3 &pt) {