Plane.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   Plane.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Representation of a unit plane in the y=0 plane from (-.5,0,-.5) 
00009    to (.5,0,.5)
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #include "Plane.h"
00013 #include "SurfacePoint.h"
00014 #include <Random.h>
00015 
00016 #include <GL/gl.h>
00017 
00018 void Plane::init() {
00019    m_objSpaceAABB = AABB(Vector3(-.5, 0, -.5), Vector3(.5, 0, .5));
00020    
00021    Transformable::init();
00022 }
00023 
00024 real_t Plane::getIntersection(const Ray &ray, SurfacePoint &pt) {
00025    Point3  P;
00026    Vector3 D;
00027    _transformRayWorldToObj(ray, P, D);
00028    
00029    const real_t t = -P[1] / D[1];
00030    
00031    if (t > INTERSECT_TOLERANCE && 
00032        fabs(P[0] + t * D[0]) <= 0.5 && 
00033        fabs(P[2] + t * D[2]) <= 0.5)
00034       return t;
00035    
00036    return INFINITY;
00037 }
00038 
00039 bool Plane::intersects(const Ray &ray, real_t tMax) {
00040    Point3  P;
00041    Vector3 D;
00042    _transformRayWorldToObj(ray, P, D);
00043    
00044    const real_t t = -P[1] / D[1];
00045    
00046    return (isValidT(t, tMax) && 
00047            fabs(P[0] + t * D[0]) <= 0.5 && 
00048            fabs(P[2] + t * D[2]) <= 0.5);
00049 }
00050 
00051 void Plane::_getUV(SurfacePoint &pt) const {
00052    Point3 P;
00053    
00054    _transformPoint3WorldToObj(pt.position, P);
00055    
00056    pt.uv.u = CAP(P[0] + 0.5, 0, 1);
00057    pt.uv.v = CAP(P[2] + 0.5, 0, 1);
00058 }
00059 
00060 void Plane::_getGeometricNormal(SurfacePoint &pt) const {
00061    Vector3 nObj(0, 1, 0);
00062    
00063    _transformVector3ObjToWorld(nObj, pt.normalG);
00064 }
00065 
00066 void Plane::preview() {
00067    Transformable::preview();
00068    
00069    glBegin(GL_QUADS);
00070    
00071    glNormal3f(0, 1, 0);
00072    
00073    glVertex3f(-.5, 0, -.5);
00074    glVertex3f(-.5, 0,  .5);
00075    glVertex3f( .5, 0,  .5);
00076    glVertex3f( .5, 0, -.5);
00077    
00078    glEnd();
00079 }
00080 
00081 #if 0
00082 Vector3 Plane::getNormal(const Point3 &pt) const {
00083    Vector3 nObj(0, 1, 0), nWorld;
00084    
00085    _transformVector3ObjToWorld(nObj, nWorld);
00086    return nWorld;
00087 }
00088 #endif
00089 
00090 Point3 Plane::getPosition(const UV &uv) {
00091    return m_transToWorld * Point3(-.5 + uv.u, 0, -.5 + uv.v);
00092 }
00093 
00094 real_t Plane::_getSurfaceArea() {
00095    const Point3 &p1 = m_transToWorld * Point3(-.5, 0, -.5);
00096    const Point3 &p2 = m_transToWorld * Point3( .5, 0, -.5);
00097    //const Point3 &p3 = m_transToWorld * Point3( .5, 0,  .5);
00098    const Point3 &p4 = m_transToWorld * Point3(-.5, 0,  .5);
00099    
00100    const Vector3 &e1 = p2 - p1;
00101    const Vector3 &e2 = p4 - p1;
00102    
00103    return e1.cross(e2).getMagnitude();
00104 }
00105 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6