Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples to glm #6389

Merged
merged 17 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
468 changes: 234 additions & 234 deletions examples/3d/3DPrimitivesExample/src/ofApp.cpp

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions examples/3d/3DPrimitivesExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ class ofApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);

bool bFill;
bool bWireframe;
bool bDrawNormals;
bool bDrawAxes;
bool bDrawLights;
bool bHelpText;
bool bMousePressed;
bool bSplitFaces;
ofImage texture;
ofVideoGrabber vidGrabber;
int mode;
ofSpherePrimitive sphere;
ofIcoSpherePrimitive icoSphere;
ofPlanePrimitive plane;
ofCylinderPrimitive cylinder;
ofConePrimitive cone;
ofBoxPrimitive box;
ofLight pointLight;
ofLight pointLight2;
ofLight pointLight3;
ofMaterial material;
// place to store the sides of the box //
ofVboMesh boxSides[ofBoxPrimitive::SIDES_TOTAL];
ofVboMesh deformPlane;
ofVboMesh topCap, bottomCap, body;
vector<ofMeshFace> triangles;
ofCamera cam;
bool bFill;
bool bWireframe;
bool bDrawNormals;
bool bDrawAxes;
bool bDrawLights;
bool bHelpText;
bool bMousePressed;
bool bSplitFaces;

ofImage texture;
ofVideoGrabber vidGrabber;
int mode;

ofSpherePrimitive sphere;
ofIcoSpherePrimitive icoSphere;
ofPlanePrimitive plane;
ofCylinderPrimitive cylinder;
ofConePrimitive cone;
ofBoxPrimitive box;

ofLight pointLight;
ofLight pointLight2;
ofLight pointLight3;
ofMaterial material;

// place to store the sides of the box //
ofVboMesh boxSides[ofBoxPrimitive::SIDES_TOTAL];
ofVboMesh deformPlane;
ofVboMesh topCap, bottomCap, body;
vector<ofMeshFace> triangles;

ofCamera cam;
};
6 changes: 3 additions & 3 deletions examples/3d/advanced3dExample/src/Swarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void swarm::init(int nParticles, float positionDispersion, float velocityDispers

ofSeedRandom();
//
ofVec3f position, velocity;
glm::vec3 position, velocity;
ofColor color;
for(int i = 0; i < nParticles; i++){
position.x = (ofRandom(1.0f) - 0.5f) * positionDispersion;
Expand Down Expand Up @@ -145,8 +145,8 @@ void swarm::update(){


// [4] Force a maximum velocity
if(particles[i].velocity.length() > MAX_VELOCITY){
particles[i].velocity /= particles[i].velocity.length() * MAX_VELOCITY;
if(glm::length(particles[i].velocity) > MAX_VELOCITY){
particles[i].velocity /= glm::length(particles[i].velocity) * MAX_VELOCITY;
}

//
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/advanced3dExample/src/Swarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// with 'simple harmonic motion'
class swarm : public ofNode {
struct particle {
ofVec3f position;
ofVec3f velocity;
glm::vec3 position;
glm::vec3 velocity;
ofColor color;
};

Expand Down
8 changes: 4 additions & 4 deletions examples/3d/advanced3dExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ void ofApp::drawScene(int cameraIndex){

// Now lets get the inverse ViewProjection
// for the camera
ofMatrix4x4 inverseCameraMatrix;
inverseCameraMatrix.makeInvertOf(camEasyCam.getModelViewProjectionMatrix(boundsToUse));
glm::mat4 inverseCameraMatrix;
inverseCameraMatrix = glm::inverse(camEasyCam.getModelViewProjectionMatrix(boundsToUse));

// By default, we can say
// 'we are drawing in world space'
Expand Down Expand Up @@ -329,8 +329,8 @@ void ofApp::drawScene(int cameraIndex){
//--------------------------------------------------------------
void ofApp::updateMouseRay(){
// Define ray in screen space
ray[0] = ofVec3f(ofGetMouseX(), ofGetMouseY(), -1);
ray[1] = ofVec3f(ofGetMouseX(), ofGetMouseY(), 1);
ray[0] = glm::vec3(ofGetMouseX(), ofGetMouseY(), -1);
ray[1] = glm::vec3(ofGetMouseX(), ofGetMouseY(), 1);

// Transform ray into world space
ray[0] = cameras[iMainCamera]->screenToWorld(ray[0], viewMain);
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/advanced3dExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ class ofApp : public ofBaseApp {
grid nodeGrid;

//ray drawn under mouse cursor [start,end]
ofVec3f ray[2];
glm::vec3 ray[2];
};
2 changes: 1 addition & 1 deletion examples/3d/assimpExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ofApp::draw(){

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
ofPoint modelPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 0.75);
glm::vec3 modelPosition(ofGetWidth() * 0.5, (float)ofGetHeight() * 0.75, 0);
switch (key) {
case '1':
model.loadModel("astroBoy_walk.dae");
Expand Down
16 changes: 8 additions & 8 deletions examples/3d/cameraLensOffsetExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void ofApp::setup(){
previewCamera.setNearClip(0.01f);
previewCamera.setFarClip(500.0f);
previewCamera.setPosition(0.4f, 0.2f, 0.8f);
previewCamera.lookAt(ofVec3f(0.0f, 0.0f, 0.0f));
previewCamera.lookAt(glm::vec3(0.0f, 0.0f, 0.0f));

headTrackedCamera.setNearClip(0.01f);
headTrackedCamera.setFarClip(1000.0f);
Expand All @@ -22,13 +22,13 @@ void ofApp::setup(){
windowWidth = 0.3f;
windowHeight = 0.2f;

windowTopLeft = ofVec3f(-windowWidth / 2.0f,
windowTopLeft = glm::vec3(-windowWidth / 2.0f,
+windowHeight / 2.0f,
0.0f);
windowBottomLeft = ofVec3f(-windowWidth / 2.0f,
windowBottomLeft = glm::vec3(-windowWidth / 2.0f,
- windowHeight / 2.0f,
0.0f);
windowBottomRight = ofVec3f(+windowWidth / 2.0f,
windowBottomRight = glm::vec3(+windowWidth / 2.0f,
-windowHeight / 2.0f,
0.0f);

Expand All @@ -42,7 +42,7 @@ void ofApp::update(){
video.update();
finder.findHaarObjects(video.getPixels());

ofVec3f headPosition(0,0,viewerDistance);
glm::vec3 headPosition(0,0,viewerDistance);

if (finder.blobs.size() > 0) {
//get the head position in camera pixel coordinates
Expand All @@ -59,11 +59,11 @@ void ofApp::update(){
float worldHeadY = ofMap(cameraHeadY, 0, video.getHeight(), windowTopLeft.y, windowBottomLeft.y);

//set position in a pretty arbitrary way
headPosition = ofVec3f(worldHeadX, worldHeadY, viewerDistance);
headPosition = glm::vec3(worldHeadX, worldHeadY, viewerDistance);
} else {
if (!video.isInitialized()) {
//if video isn't working, just make something up
headPosition = ofVec3f(0.5f * windowWidth * sin(ofGetElapsedTimef()), 0.5f * windowHeight * cos(ofGetElapsedTimef()), viewerDistance);
headPosition = glm::vec3(0.5f * windowWidth * sin(ofGetElapsedTimef()), 0.5f * windowHeight * cos(ofGetElapsedTimef()), viewerDistance);
}
}

Expand Down Expand Up @@ -140,7 +140,7 @@ void ofApp::drawScene(bool isPreview){
ofSetLineWidth(5.0f);
ofBeginShape();
for (unsigned int i=0; i<headPositionHistory.size(); i++) {
ofPoint vertex(headPositionHistory[i].x, headPositionHistory[i].y, -float( headPositionHistory.size() - i ) * 0.05f);
glm::vec3 vertex(headPositionHistory[i].x, headPositionHistory[i].y, -float( headPositionHistory.size() - i ) * 0.05f);
ofCurveVertex(vertex);
}
ofEndShape(false);
Expand Down
8 changes: 4 additions & 4 deletions examples/3d/cameraLensOffsetExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class ofApp : public ofBaseApp{
ofxCvHaarFinder finder;

//the view window is defined by 3 corners
ofVec3f windowTopLeft;
ofVec3f windowBottomLeft;
ofVec3f windowBottomRight;
glm::vec3 windowTopLeft;
glm::vec3 windowBottomLeft;
glm::vec3 windowBottomRight;
ofCamera headTrackedCamera;
ofEasyCam previewCamera;

Expand All @@ -37,7 +37,7 @@ class ofApp : public ofBaseApp{
float windowHeight;
float viewerDistance;

deque<ofPoint> headPositionHistory;
deque<glm::vec3> headPositionHistory;

ofVboMesh window;
};
18 changes: 9 additions & 9 deletions examples/3d/cameraParentingExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ void ofApp::update(){
// all testNodes move in simple circles
// but because they are parented to each other, complex paths emerge
for(int i=0; i<kNumTestNodes; i++) {
testNodes[i].setPosition(ofVec3f(sin(ofGetElapsedTimef() * freqMult) * amp, cos(ofGetElapsedTimef() * freqMult) * amp, sin(ofGetElapsedTimef() * freqMult * 0.7) * amp));
testNodes[i].setPosition(glm::vec3(sin(ofGetElapsedTimef() * freqMult) * amp, cos(ofGetElapsedTimef() * freqMult) * amp, sin(ofGetElapsedTimef() * freqMult * 0.7) * amp));

testNodes[i].setOrientation(ofVec3f(sin(ofGetElapsedTimef() * freqMult * 0.2) * amp * 5, cos(ofGetElapsedTimef() * freqMult * 0.2) * amp * 5, sin(ofGetElapsedTimef() * freqMult * 0.2 * 0.7) * amp * 5));
testNodes[i].setOrientation(glm::vec3(sin(ofGetElapsedTimef() * freqMult * 0.2) * amp * 5, cos(ofGetElapsedTimef() * freqMult * 0.2) * amp * 5, sin(ofGetElapsedTimef() * freqMult * 0.2 * 0.7) * amp * 5));
testNodes[i].setScale(scale);

freqMult *= 3;
Expand Down Expand Up @@ -104,7 +104,7 @@ void ofApp::draw(){
glDisable(GL_CULL_FACE);
ofSetColor(255);
ofDisableLighting();
ofDrawBitmapString(s, ofPoint(20, 20));
ofDrawBitmapString(s, 20, 20);

glEnable(GL_CULL_FACE);
ofEnableLighting();
Expand Down Expand Up @@ -152,16 +152,16 @@ void ofApp::draw(){
// draw line from cam to its lookat
if(lookatIndex[i] >= 0) {
ofSetColor(0, 255, 255);
ofVec3f v1 = cam[i].getGlobalPosition();
ofVec3f v2 = testNodes[lookatIndex[i]].getGlobalPosition();
glm::vec3 v1 = cam[i].getGlobalPosition();
glm::vec3 v2 = testNodes[lookatIndex[i]].getGlobalPosition();
ofDrawLine(v1,v2);
}

// draw line from cam to its parent
if(parentIndex[i] >= 0) {
ofSetColor(255, 255, 0);
ofVec3f v1 = cam[i].getGlobalPosition();
ofVec3f v2 = testNodes[parentIndex[i]].getGlobalPosition();
glm::vec3 v1 = cam[i].getGlobalPosition();
glm::vec3 v2 = testNodes[parentIndex[i]].getGlobalPosition();
ofDrawLine(v1,v2);
}
}
Expand Down Expand Up @@ -236,8 +236,8 @@ void ofApp::keyPressed(int key){

case 'p':
parentIndex[camToConfigure]++ ;
ofVec3f oldP = cam[camToConfigure].getGlobalPosition();
ofQuaternion oldQ = cam[camToConfigure].getGlobalOrientation();
glm::vec3 oldP = cam[camToConfigure].getGlobalPosition();
glm::quat oldQ = cam[camToConfigure].getGlobalOrientation();
if(parentIndex[camToConfigure]>=kNumTestNodes) {
parentIndex[camToConfigure] = -1;
cam[camToConfigure].clearParent();
Expand Down
34 changes: 17 additions & 17 deletions examples/3d/cameraRibbonExample/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ofApp::setup(){
void ofApp::update(){
//don't move the points if we are using the camera
if(!usecamera){
ofVec3f sumOfAllPoints(0,0,0);
glm::vec3 sumOfAllPoints(0,0,0);
for(unsigned int i = 0; i < points.size(); i++){
points[i].z -= 4;
sumOfAllPoints += points[i];
Expand All @@ -53,23 +53,23 @@ void ofApp::draw(){
for(unsigned int i = 1; i < points.size(); i++){

//find this point and the next point
ofVec3f thisPoint = points[i-1];
ofVec3f nextPoint = points[i];
glm::vec3 thisPoint = points[i-1];
glm::vec3 nextPoint = points[i];

//get the direction from one to the next.
//the ribbon should fan out from this direction
ofVec3f direction = (nextPoint - thisPoint);
glm::vec3 direction = (nextPoint - thisPoint);

//get the distance from one point to the next
float distance = direction.length();
float distance = glm::length(direction);

//get the normalized direction. normalized vectors always have a length of one
//and are really useful for representing directions as opposed to something with length
ofVec3f unitDirection = direction.getNormalized();
glm::vec3 unitDirection = glm::normalize(direction);

//find both directions to the left and to the right
ofVec3f toTheLeft = unitDirection.getRotated(-90, ofVec3f(0,0,1));
ofVec3f toTheRight = unitDirection.getRotated(90, ofVec3f(0,0,1));
glm::vec3 toTheLeft = glm::rotate(unitDirection, -90.f, glm::vec3(0,0,1));
glm::vec3 toTheRight = glm::rotate(unitDirection, 90.f, glm::vec3(0,0,1));

//use the map function to determine the distance.
//the longer the distance, the narrower the line.
Expand All @@ -78,12 +78,12 @@ void ofApp::draw(){

//calculate the points to the left and to the right
//by extending the current point in the direction of left/right by the length
ofVec3f leftPoint = thisPoint+toTheLeft*thickness;
ofVec3f rightPoint = thisPoint+toTheRight*thickness;
glm::vec3 leftPoint = thisPoint+toTheLeft*thickness;
glm::vec3 rightPoint = thisPoint+toTheRight*thickness;

//add these points to the triangle strip
mesh.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));
mesh.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));
mesh.addVertex(glm::vec3(leftPoint.x, leftPoint.y, leftPoint.z));
mesh.addVertex(glm::vec3(rightPoint.x, rightPoint.y, rightPoint.z));
}

//end the shape
Expand Down Expand Up @@ -112,23 +112,23 @@ void ofApp::mouseMoved(int x, int y ){
//if we are using the camera, the mouse moving should rotate it around the whole sculpture
if(usecamera){
float rotateAmount = ofMap(ofGetMouseX(), 0, ofGetWidth(), 0, 360);
ofVec3f furthestPoint;
glm::vec3 furthestPoint;
if (points.size() > 0) {
furthestPoint = points[0];
}
else
{
furthestPoint = ofVec3f(x, y, 0);
furthestPoint = glm::vec3(x, y, 0);
}

ofVec3f directionToFurthestPoint = (furthestPoint - center);
ofVec3f directionToFurthestPointRotated = directionToFurthestPoint.getRotated(rotateAmount, ofVec3f(0,1,0));
glm::vec3 directionToFurthestPoint = (furthestPoint - center);
glm::vec3 directionToFurthestPointRotated = glm::rotate(directionToFurthestPoint, rotateAmount, glm::vec3(0,1,0));
camera.setPosition(center + directionToFurthestPointRotated);
camera.lookAt(center);
}
//otherwise add points like before
else{
ofVec3f mousePoint(x,y,0);
glm::vec3 mousePoint(x,y,0);
points.push_back(mousePoint);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/3d/cameraRibbonExample/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class ofApp : public ofBaseApp{
void gotMessage(ofMessage msg);

//this holds all of our points
vector<ofVec3f> points;
vector<glm::vec3> points;
//this keeps track of the center of all the points
ofVec3f center;
glm::vec3 center;

//our camera objects for looking at the scene from multiple perspectives
ofCamera camera;
Expand Down
Loading