Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created January 3, 2014 17:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ofZach/8242765 to your computer and use it in GitHub Desktop.
Save ofZach/8242765 to your computer and use it in GitHub Desktop.
billboard using ofNode / ofCamera
//--------------------------------------------------------------
void testApp::draw(){
glEnable(GL_DEPTH_TEST);
ofEnableLighting();
ofLight light;
light.setPosition(ofPoint(-200,0, -1000));
light.lookAt( ofPoint(-1000,0,0));
light.setDirectional();
light.enable();
cam.begin();
ofDrawAxis(100);
ofSeedRandom(0); // always pick the same random positions
for (int i = 0; i < 50; i++){
ofPoint pos(ofRandom(-200,200), ofRandom(-200,200), ofRandom(-200,200));
ofNode posNode;
posNode.setGlobalPosition(pos);
posNode.lookAt(cam.getGlobalPosition(), cam.getUpDir());
ofQuaternion posQuat = posNode.getGlobalOrientation();
float ang = 0;
ofPoint vec;
posQuat.getRotate(ang, vec);
ofPushMatrix();
ofTranslate(pos);
ofRotate(ang, vec.x, vec.y, vec.z);
ofRotate(30, 1,1,0); // rotate alittle bit, so you can see the "box" of the object
ofDrawBox(0,0,0,50);
ofPopMatrix();
}
cam.end();
}
@ofZach
Copy link
Author

ofZach commented Jan 3, 2014

in the .h file:

ofEasyCam cam;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment