Created
January 22, 2015 11:21
-
-
Save andreasmuller/c07429f55a07f4e73f40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "BoundingBox.h" | |
class OrientedBoundingBox : public BoundingBox | |
{ | |
public: | |
// -------------------------------------------- | |
void setOrientation( ofQuaternion _orientation ) | |
{ | |
orientation = _orientation; | |
transformHasChanged = true; | |
} | |
// -------------------------------------------- | |
bool pointIsInside( ofVec3f _point ) | |
{ | |
if( transformHasChanged ) | |
{ | |
worldToBox = getWorldToBoxmatrix(); | |
transformHasChanged = false; | |
} | |
ofVec3f pointBoxSpace = _point * worldToBox; | |
return localSpacePointIsInWithinBoxSize( pointBoxSpace ); | |
} | |
// -------------------------------------------- | |
void draw() | |
{ | |
ofNoFill(); | |
ofPushMatrix(); | |
ofTranslate( pos ); | |
ofMatrix4x4 rotMat; | |
orientation.get( rotMat ); | |
ofMultMatrix( rotMat ); | |
ofDrawBox( ofVec3f(0,0,0), size.x, size.y, size.z ); | |
ofPopMatrix(); | |
ofFill(); | |
} | |
private: | |
// -------------------------------------------- | |
ofMatrix4x4 getWorldToBoxmatrix() | |
{ | |
ofMatrix4x4 tmpWorldToBoxMat; | |
orientation.get( tmpWorldToBoxMat ); | |
tmpWorldToBoxMat = tmpWorldToBoxMat * ofMatrix4x4::newTranslationMatrix( pos ); | |
tmpWorldToBoxMat = tmpWorldToBoxMat.getInverse(); | |
return tmpWorldToBoxMat; | |
} | |
ofMatrix4x4 worldToBox; | |
ofQuaternion orientation; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment