00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 00012 #include "Plane.h" 00013 #include <OpenCAL/Vertex.h> 00014 #include <OpenCAL/Triangle.h> 00015 #include <OpenCAL/Renderer.h> 00016 #include <OpenCAL/System.h> 00017 using namespace OpenCAL; 00018 00019 using namespace std; 00020 00021 00022 /****************************** 00023 * Constructors and destructor * 00024 ******************************/ 00025 00030 Plane::Plane(System *parent) 00031 : RigidObject(parent), m_normal(0,1,0) 00032 { 00033 } 00034 00035 Plane::Plane(System *parent, const Vector3 &position, const Vector3 &normal) 00036 : RigidObject(parent), m_normal(normal.normalized()) 00037 { 00038 m_position = position; 00039 } 00040 00041 Plane::~Plane() 00042 { 00043 } 00044 00045 00046 /************************ 00047 * Get and set functions * 00048 ************************/ 00049 00050 00051 /****************** 00052 * Other functions * 00053 ******************/ 00054 00055 void Plane::render() 00056 { 00057 Renderer *renderer = m_parent->getRenderer(); 00058 if(!renderer) return; 00059 00060 // Push the current transformation on the stack 00061 renderer->pushTransformation(); 00062 00063 renderer->translate(m_position); 00064 renderer->rotate(m_rotation); 00065 renderer->renderPlane(); 00066 00067 // Pop the transformation stack 00068 renderer->popTransformation(); 00069 } 00070 00071 float Plane::distance(const Vector3 &point) const 00072 { 00073 return (point - m_position).dotProduct(m_normal); 00074 } 00075 00076 /* 00077 #ifdef USE_OPENGL 00078 void Plane::initializeGL() 00079 { 00080 Rigid::initializeGL(); 00081 00082 const int radius = 50; 00083 00084 Vector3 p1(-radius, 0, -radius); 00085 Vector3 p2(-radius, 0, radius); 00086 Vector3 p3( radius, 0, radius); 00087 Vector3 p4( radius, 0, -radius); 00088 00089 Vertex *a = m_surface.addVertex(p1); 00090 Vertex *b = m_surface.addVertex(p2); 00091 Vertex *c = m_surface.addVertex(p3); 00092 Vertex *d = m_surface.addVertex(p4); 00093 00094 Triangle *t1 = m_surface.addTriangle(Triangle(a, b, c)); 00095 t1->calculateNormal(); 00096 Triangle *t2 = m_surface.addTriangle(Triangle(a, c, d)); 00097 t2->calculateNormal(); 00098 00099 // Compile the plane 00100 glNewList(m_displayList, GL_COMPILE); 00101 m_surface.drawGL(); 00102 glEndList(); 00103 } 00104 #endif // USE_OPENGL 00105 */ 00106 00107 00108 /********************** 00109 * Protected functions * 00110 **********************/