Skip to content

Commit

Permalink
Merge pull request #726 from elliotwoods/ofDrawGrid
Browse files Browse the repository at this point in the history
added ofDrawGrid to complement ofDrawAxis. added 'get' accessors to ofCam
  • Loading branch information
ofTheo committed Feb 9, 2012
2 parents 53dd099 + 7a6cc05 commit 7ca7833
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 9 deletions.
79 changes: 79 additions & 0 deletions libs/openFrameworks/3d/of3dUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,82 @@ void ofDrawAxis(float size) {

ofPopStyle();
}

//--------------------------------------------------------------
void ofDrawGrid(float scale, float ticks, bool labels, bool x, bool y, bool z) {

ofColor c = ofGetStyle().color;

ofPushStyle();

if (x) {
c.setHue(0.0f);
ofSetColor(c);
ofDrawGridPlane(scale, ticks, labels);
}
if (y) {
c.setHue(255.0f / 3.0f);
ofSetColor(c);
ofPushMatrix();
ofRotate(90, 0, 0, 1);
ofDrawGridPlane(scale, ticks, labels);
ofPopMatrix();
}
if (z) {
c.setHue(255.0f * 2.0f / 3.0f);
ofSetColor(c);
ofPushMatrix();
ofRotate(90, 0, 1, 0);
ofDrawGridPlane(scale, ticks, labels);
ofPopMatrix();
}

ofPopStyle();
}


//--------------------------------------------------------------
void drawGridPlane(float scale, float ticks, bool labels) {

This comment has been minimized.

Copy link
@emmanuelgeoffray

emmanuelgeoffray Feb 20, 2012

It should be ofDrawGridPlane?


float minor = scale / ticks;
float major = minor * 2.0f;

ofPushStyle();
for (int iDimension=0; iDimension<2; iDimension++)
{
for (float yz=-scale; yz<=scale; yz+= minor)
{
//major major
if (fabs(yz) == scale || yz == 0)
ofSetLineWidth(4);

//major
else if (yz / major == floor(yz / major) )
ofSetLineWidth(2);

//minor
else
ofSetLineWidth(1);
if (iDimension==0)
ofLine(0, yz, -scale, 0, yz, scale);
else
ofLine(0, -scale, yz, 0, scale, yz);
}
}
ofPopStyle();

if (labels) {
//draw numbers on axes
ofPushStyle();
ofSetColor(255, 255, 255);

ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL_BILLBOARD);
for (float yz = -scale; yz<=scale; yz+=minor)
{
ofDrawBitmapString(ofToString(yz, 0), 0, yz, 0);
ofDrawBitmapString(ofToString(yz, 0), 0, 0, yz);
}
ofPopStyle();
}

}
3 changes: 3 additions & 0 deletions libs/openFrameworks/3d/of3dUtils.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

void ofDrawAxis(float size);

void ofDrawGrid(float scale = 10.0f, float ticks = 5.0f, bool labels = false, bool x = true, bool y = true, bool z = true);
void ofDrawGridPlane(float scale, float ticks = 5.0f, bool labels = false);
6 changes: 5 additions & 1 deletion libs/openFrameworks/3d/ofCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class ofCamera : public ofNode {
void setNearClip(float f);
void setFarClip(float f);

float getFov() const { return fov; };
float getNearClip() const { return nearClip; };
float getFarClip() const { return farClip; };

void enableOrtho();
void disableOrtho();
bool getOrtho() const;
Expand All @@ -57,7 +61,7 @@ class ofCamera : public ofNode {
ofVec3f cameraToWorld(ofVec3f CameraXYZ, ofRectangle viewport = ofGetCurrentViewport());


private:
protected:
void calcClipPlanes(ofRectangle viewport);

bool isOrtho;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 42;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -51,7 +51,6 @@
E4B27C2E10CBEBAB00536013 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9770E8CC7DD009D7055 /* CoreServices.framework */; };
E4B27C3010CBEBAB00536013 /* OpenGL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE9790E8CC7DD009D7055 /* OpenGL.framework */; };
E4B27C3110CBEBAB00536013 /* QuickTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45BE97A0E8CC7DD009D7055 /* QuickTime.framework */; };
E4B5AE1E12D94F9B00BA355D /* ofQtUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B5AE1412D94F9B00BA355D /* ofQtUtils.cpp */; };
E4B5AE1F12D94F9B00BA355D /* ofQtUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B5AE1512D94F9B00BA355D /* ofQtUtils.h */; };
E4B5AE2012D94F9B00BA355D /* ofQuickTimeGrabber.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B5AE1612D94F9B00BA355D /* ofQuickTimeGrabber.cpp */; };
E4B5AE2112D94F9B00BA355D /* ofQuickTimeGrabber.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B5AE1712D94F9B00BA355D /* ofQuickTimeGrabber.h */; };
Expand Down Expand Up @@ -631,8 +630,11 @@
/* Begin PBXProject section */
E4B69B4C0A3A1720003C02F2 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "openFrameworksLib" */;
compatibilityVersion = "Xcode 2.4";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down Expand Up @@ -664,7 +666,6 @@
E4B27C2610CBEB9D00536013 /* ofVideoGrabber.cpp in Sources */,
E4B27C2710CBEB9D00536013 /* ofVideoPlayer.cpp in Sources */,
E4998A26128A39480094AC3F /* ofEvents.cpp in Sources */,
E4B5AE1E12D94F9B00BA355D /* ofQtUtils.cpp in Sources */,
E4B5AE2012D94F9B00BA355D /* ofQuickTimeGrabber.cpp in Sources */,
E4B5AE2212D94F9B00BA355D /* ofQuickTimePlayer.cpp in Sources */,
E4F3BA6712F4C4BF002D19BB /* of3dUtils.cpp in Sources */,
Expand Down Expand Up @@ -749,9 +750,8 @@
"$(LIB_GLUT)",
"$(LIB_FMODEX)",
);
PREBINDING = NO;
PRODUCT_NAME = openFrameworksDebug;
SDKROOT = "";
SDKROOT = macosx10.6;
};
name = Debug;
};
Expand Down Expand Up @@ -790,9 +790,8 @@
"$(LIB_GLUT)",
"$(LIB_FMODEX)",
);
PREBINDING = NO;
PRODUCT_NAME = openFrameworks;
SDKROOT = "";
SDKROOT = macosx10.6;
};
name = Release;
};
Expand Down

2 comments on commit 7ca7833

@gabrielstuff
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to bump here, but isn't here an issue with the call to ofDrawGridPlane( scale, ticks, labels), but there is just drawGridPlane(float scale, float ticks, bool labels) that is defined ?

@elliotwoods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey!
i've mentioned this elsewhere but this pull was stale, and should have been going into develop
and as others have noted drawGridPlane should be ofDrawGridPlane in the cpp.

Please sign in to comment.