Skip to content

Commit

Permalink
updates to grid
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwoods committed Jan 6, 2012
1 parent c78de72 commit 7a6cc05
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 29 deletions.
88 changes: 68 additions & 20 deletions libs/openFrameworks/3d/of3dUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,81 @@ void ofDrawAxis(float size) {
ofPopStyle();
}

void ofDrawGrid(float size) {


const float lineCountMajor = 3;
const float lineCountMinor = lineCountMajor*3;
const float lineStepMajor = size / lineCountMajor;
const float lineStepMinor = size / lineCountMinor;
//--------------------------------------------------------------
void ofDrawGrid(float scale, float ticks, bool labels, bool x, bool y, bool z) {

ofColor c = ofGetStyle().color;

ofPushStyle();

//draw major lines
ofSetLineWidth(3);
for (float s=-size; s<=size; s+=lineStepMajor)
{
ofLine(-size, s, size, s);
ofLine(s, -size, s, size);
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();
}

//draw minor lines
ofSetLineWidth(1);
for (float s=-size; s<=size; s+=lineStepMinor)
ofPopStyle();
}


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

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

ofPushStyle();
for (int iDimension=0; iDimension<2; iDimension++)
{
ofLine(-size, s, size, s);
ofLine(s, -size, s, size);
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();
}

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

void ofDrawAxis(float size);
void ofDrawGrid(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);
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

0 comments on commit 7a6cc05

Please sign in to comment.