/*************************************************************************** File: PBMWall.cpp Created: 03/03/2002 Author: Maxim Garber Computer Science Department University of North Carolina - Chapel Hill garber@cs.unc.edu Description: An axis aligned wall with rendering and collision detection ----------------------------------------------------------------------------. Copyright 2002 Maxim Garber UNC Collide Research Group *****************************************************************************/ #include "PBMWall.h" #include "mat16fv.hpp" #include #include #include "GL\gl.h" #include "GL\glu.h" #include "GL\glut.h" /**************************************************************************** Function : PBMWall Description: Constructor initializes the wall state and transformations. ****************************************************************************/ PBMWall::PBMWall(float position[3], float normal[3], float right[3], float up[3], float width, float height) : _width(width), _height(height) { unsigned int i; // set vectors for(i=0; i<3; i++) { _position[i] = position[i]; _normal [i] = normal [i]; _right [i] = right [i]; _up [i] = up [i]; } // compute transformation matrices Identity16fv(_renderTransform); for(i=0; i<3; i++) { _renderTransform[i ] = _collisionRotation[0][i] = _right[i]; _renderTransform[i+4] = _collisionRotation[1][i] = _up[i]; _renderTransform[i+8] = _collisionRotation[2][i] = _normal[i]; _renderTransform[i+12] = _position[i]; } _InitCollision(); } /**************************************************************************** Function : ~PBMWall Description: Destructor ****************************************************************************/ PBMWall::~PBMWall(){} /**************************************************************************** Function : Update Description: Nothing ****************************************************************************/ void PBMWall::Update(float timeStep){} /**************************************************************************** Function : Draw Description: Draws the wall as a ruled plane ****************************************************************************/ void PBMWall::Draw() { // set transformation glPushMatrix(); glMultMatrixf(_renderTransform); // draw wall _DrawGridPlane(5, 5); glPopMatrix(); } /**************************************************************************** Function : GetNormal Description: Returns the wall normal ****************************************************************************/ void PBMWall::GetNormal(float normal[3]) { for(unsigned int i=0; i<3; i++) normal[i] = _normal[i]; } /**************************************************************************** Function : GetPosition Description: Returns the wall positin ****************************************************************************/ void PBMWall::GetPosition(float position[3]) { for(unsigned int i=0; i<3; i++) position[i] = _position[i]; } /**************************************************************************** Function : GetCollisionGeometry Description: Returns the wall collision geometry and transformation frame ****************************************************************************/ void PBMWall::GetCollisionGeometry(PQP_Model* &geometry, Frame3 &frame) { // set transformation unsigned int i; for(i=0; i<9; i++) frame.r[i/3][i%3] = _collisionRotation[i/3][i%3]; for(i=0; i<3; i++) frame.p[i] = _position[i]; // set geometry geometry = _collisionGeometry; } /**************************************************************************** Function : _InitCollision Description: Initializes the wall collision geometry ****************************************************************************/ void PBMWall::_InitCollision() { _collisionGeometry = new PQP_Model(); _collisionGeometry->BeginModel(); float A1[3] = {-_width/2, -_height/2, 0.0}; float B1[3] = { _width/2, _height/2, 0.0}; float C1[3] = {-_width/2, _height/2, 0.0}; _collisionGeometry->AddTri(A1, B1, C1, 1); float A2[3] = {-_width/2, -_height/2, 0.0}; float B2[3] = { _width/2, -_height/2, 0.0}; float C2[3] = { _width/2, _height/2, 0.0}; _collisionGeometry->AddTri(A2, B2, C2, 2); _collisionGeometry->EndModel(); } /**************************************************************************** Function : _DrawGridPlane Description: Draws a ruled plane in the xy plane, with size width x height. ****************************************************************************/ void PBMWall::_DrawGridPlane(unsigned int widthDivisions, unsigned int heightDivisions) { float widthSpacing = _width / widthDivisions; float widthStart = -_width/2; float widthEnd = _width/2; float heightSpacing = _height/ heightDivisions; float heightStart = -_height/2; float heightEnd = _height/2; glPushAttrib(GL_POLYGON_BIT); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); // draw plane in the z = 0 plane glNormal3f(0 ,0, 1); for(float h= heightStart; h