Skip to content

Commit

Permalink
Flying: new tree
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmendoza committed Dec 15, 2013
1 parent ac61300 commit cffa2ce
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 deletions.
6 changes: 2 additions & 4 deletions CloudsData/visualsystems/Flying/shaders/plants.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

uniform vec3 lEye;
uniform float growth;
uniform float maxDepth;

varying float fogAmount;
varying vec3 nEye;
Expand All @@ -18,11 +17,10 @@ void main()
if (gl_TexCoord[0].t > growth) discard;

vec3 l = normalize(lEye - vEye);
vec3 lightN = normalize(cross(dFdx(vEye), dFdy(vEye)));
//vec3 lightN = normalize(nEye);

vec3 lightN = normalize(cross(dFdx(vEye), dFdy(vEye)));

float diffuse = max(dot(lightN, l), 0.0);

//gl_FragColor = vec4(gl_TexCoord[0].t / maxDepth, gl_TexCoord[0].t / maxDepth, gl_TexCoord[0].t / maxDepth, 1.0);//gl_Color;//vec4(gl_TexCoord[0].s, gl_TexCoord[0].s, gl_TexCoord[0].s, 1.0) * diffuse;//
gl_FragColor = (1.0 - fogAmount) * vec4(gl_Color.rgb * (diffuse/* + specular*/), 1.0);//gl_Color;//vec4(gl_TexCoord[0].s, gl_TexCoord[0].s, gl_TexCoord[0].s, 1.0) * diffuse;//
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include "CloudsRGBDVideoPlayer.h"
#include "CloudsInput.h"

const string CloudsVisualSystemFlying::RULES_FILES[] = { "rules/tree_flying.xml", "rules/flower.xml" };
const string CloudsVisualSystemFlying::RULES_FILES[] = { "rules/tree_flying.xml", "rules/tree_flying2.xml", "rules/flower.xml" };
//const string CloudsVisualSystemFlying::RULES_FILES[] = { "rules/tree_flying2.xml" };
const float CloudsVisualSystemFlying::CAM_DAMPING = .08f;

CloudsVisualSystemFlying::CloudsVisualSystemFlying() :
Expand Down Expand Up @@ -57,9 +58,11 @@ void CloudsVisualSystemFlying::generate()
for (unsigned i = 0; i < numPlantMeshes; ++i)
{
plantMeshes.push_back(ofxRules());
plantMeshes.back().load(getVisualSystemDataPath() + RULES_FILES[rand() % NUM_RULES_FILES]);
string file = getVisualSystemDataPath() + RULES_FILES[rand() % NUM_RULES_FILES];
plantMeshes.back().load(file);
plantMeshes.back().start();
while (plantMeshes.back().step()) ;
cout << file << " :::: " << plantMeshes.back().getNumSteps() << endl;
}

// floor - don't share vertices so can have
Expand Down Expand Up @@ -191,11 +194,10 @@ void CloudsVisualSystemFlying::selfDraw()

// PLANTS
plantsShader.begin();
const float camAvoidDistSq = camAvoidDistSq * camAvoidDistSq;
for (auto it = plants.begin(); it != plants.end(); ++it)
{
float growth = ofMap((it->pos - floorLookAt).lengthSquared(), 0.f, growDistSq, 1.4f * plantMeshes[it->meshIdx].getNumSteps(), 0.f, true);

const float camAvoidDistSq = camAvoidDistSq * camAvoidDistSq;
float growth = ofMap((it->pos - floorLookAt).lengthSquared(), 0.f, growDistSq, 1.4f * plantMeshes[it->meshIdx].getCurrentDepth(), 0.f, true);
float distToCamSq = (it->pos - cam.getPosition()).lengthSquared();
if (distToCamSq < camAvoidDistSq)
{
Expand All @@ -204,7 +206,6 @@ void CloudsVisualSystemFlying::selfDraw()
if (growth > 0.f)
{
plantsShader.setUniform1f("growth", growth);
plantsShader.setUniform1f("maxDepth", plantMeshes[it->meshIdx].getMaxDepth());
plantsShader.setUniform3fv("lEye", lEye.getPtr());
plantsShader.setUniform1f("noiseFreq", noiseFreq);
plantsShader.setUniform1f("noiseAmp", noiseAmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ struct Plant
class CloudsVisualSystemFlying : public CloudsVisualSystem
{
public:
static const unsigned NUM_RULES_FILES = 2;
static const unsigned NUM_RULES_FILES = 3;
//static const unsigned NUM_RULES_FILES = 1;
static const string RULES_FILES[NUM_RULES_FILES];
static const float CAM_DAMPING;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace itg
const string Rules::DEFAULT_START_RULE = "start";

Rules::Rules() :
maxDepth(numeric_limits<unsigned>::max()), numSteps(0)
maxDepth(numeric_limits<unsigned>::max()), numSteps(0), currentDepth(0)
{
registerAction<LineAction>("line");
registerAction<PointAction>("point");
Expand Down Expand Up @@ -87,11 +87,10 @@ namespace itg
auto ruleSet = ruleSets.find((*it)->getNextRuleName());
if (ruleSet != ruleSets.end())
{
//RuleSet::Ptr ruleSet = ruleSets[(*it)->getNextRuleName()];

vector<Branch::Ptr> children = ruleSet->second->randomRule()->step(*it, mesh);
newBranches.insert(newBranches.end(), children.begin(), children.end());
activeRuleSets++;
currentDepth = max(currentDepth, (*it)->getDepth());
}
else ofLogError() << "No ruleSet with name " << (*it)->getNextRuleName();
}
Expand Down Expand Up @@ -240,6 +239,8 @@ namespace itg
{
mesh.clear();
branches.clear();
numSteps = 0;
currentDepth = 0;
}

Rule::Ptr Rules::addRule(const string& ruleName, float weight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace itg

unsigned getNumSteps() const { return numSteps; }

unsigned getCurrentDepth() const { return currentDepth; }

void setStartRule(const string& startRule) { this->startRule = startRule; }

void load(const string& fileName);
Expand Down Expand Up @@ -104,6 +106,7 @@ namespace itg
map<string, ActionCreator> creators;
ofVboMesh mesh;
unsigned numSteps;
unsigned currentDepth;

bool enableVertexColours;
ofFloatColor meshColour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@

namespace itg
{
void ConeAction::setParameters(float radius, float height, unsigned radiusSegments)
void ConeAction::setParameters(float radius, float height, unsigned resolution)
{
coneMesh = Action::cone(radius, height, radiusSegments);
coneMesh = Action::cone(radius, height, resolution + 1);
ofVec3f direction = ((ofVec3f() * getTransform()) - ofVec3f()).normalized();
ofMatrix4x4 r;
r.makeRotationMatrix(ofVec3f(0, 1, 0), direction);
r.rotate(180, 1, 0, 0);
for (unsigned i = 0; i < coneMesh.getNumVertices(); ++i)
{
coneMesh.setVertex(i, coneMesh.getVertex(i) * r);
coneMesh.setNormal(i, coneMesh.getNormal(i) * r);
}
}

Branch::Ptr ConeAction::step(Branch::Ptr branch, ofMesh& mesh)
Expand All @@ -62,8 +71,8 @@ namespace itg
TransformAction::load(xml, tagName, tagIdx);
float radius = xml.getAttribute(tagName, "radius", 1.f, tagIdx);
float height = xml.getAttribute(tagName, "height", 1.f, tagIdx);
unsigned radiusSegments = xml.getAttribute(tagName, "height", 12, tagIdx);
setParameters(radius, height, radiusSegments);
unsigned resolution = xml.getAttribute(tagName, "resolution", 12, tagIdx);
setParameters(radius, height, resolution);
colour = Action::parseColour(xml.getAttribute(tagName, "colour", "", tagIdx));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace itg

void load(ofxXmlSettings& xml, const string& tagName, unsigned tagIdx);

void setParameters(float radius, float height, unsigned radiusSegments);
void setParameters(float radius, float height, unsigned resolution);

private:
ofMesh coneMesh;
Expand Down
2 changes: 2 additions & 0 deletions VSFlying/Flying.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
28B033D3184BD40F009B9099 /* CloudsVisualSystemFlying.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CloudsVisualSystemFlying.h; sourceTree = "<group>"; };
28F4F01B185CCDD6008D80A2 /* ConeAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConeAction.cpp; path = ../../Rulez/vs_src/ofxRules/src/actions/ConeAction.cpp; sourceTree = "<group>"; };
28F4F01C185CCDD6008D80A2 /* ConeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConeAction.h; path = ../../Rulez/vs_src/ofxRules/src/actions/ConeAction.h; sourceTree = "<group>"; };
28F4F021185CD2A7008D80A2 /* tree_flying2.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = tree_flying2.xml; sourceTree = "<group>"; };
BBAB23BE13894E4700AA2426 /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../libs/glut/lib/osx/GLUT.framework; sourceTree = "<group>"; };
E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
E45BE9710E8CC7DD009D7055 /* AGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AGL.framework; path = /System/Library/Frameworks/AGL.framework; sourceTree = "<absolute>"; };
Expand Down Expand Up @@ -1472,6 +1473,7 @@
children = (
E7F37DF01852DEFB0087F91C /* flower.xml */,
E7F37DF11852DEFB0087F91C /* tree_flying.xml */,
28F4F021185CD2A7008D80A2 /* tree_flying2.xml */,
);
name = rules;
path = ../../../../CloudsData/visualsystems/Flying/rules;
Expand Down
6 changes: 6 additions & 0 deletions VSRulez/Rulez.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
285C20AE182FFFEE0065BCAE /* ToonPass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 285C2091182FFFEE0065BCAE /* ToonPass.cpp */; };
285C20AF182FFFEE0065BCAE /* VerticalTiltShifPass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 285C2093182FFFEE0065BCAE /* VerticalTiltShifPass.cpp */; };
285C20B0182FFFEE0065BCAE /* ZoomBlurPass.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 285C2095182FFFEE0065BCAE /* ZoomBlurPass.cpp */; };
28A8A7B4185DE97D009DA217 /* ConeAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28A8A7B2185DE97D009DA217 /* ConeAction.cpp */; };
28B4EE29183E723B0091E0F3 /* CloudsVisualSystemRulez.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28B4EE06183E723B0091E0F3 /* CloudsVisualSystemRulez.cpp */; };
28B4EE2A183E723B0091E0F3 /* Action.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28B4EE0C183E723B0091E0F3 /* Action.cpp */; };
28B4EE2B183E723B0091E0F3 /* CubeAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 28B4EE0E183E723B0091E0F3 /* CubeAction.cpp */; };
Expand Down Expand Up @@ -285,6 +286,8 @@
285C2094182FFFEE0065BCAE /* VerticalTiltShifPass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VerticalTiltShifPass.h; sourceTree = "<group>"; };
285C2095182FFFEE0065BCAE /* ZoomBlurPass.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ZoomBlurPass.cpp; sourceTree = "<group>"; };
285C2096182FFFEE0065BCAE /* ZoomBlurPass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZoomBlurPass.h; sourceTree = "<group>"; };
28A8A7B2185DE97D009DA217 /* ConeAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConeAction.cpp; sourceTree = "<group>"; };
28A8A7B3185DE97D009DA217 /* ConeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConeAction.h; sourceTree = "<group>"; };
28B4EE06183E723B0091E0F3 /* CloudsVisualSystemRulez.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CloudsVisualSystemRulez.cpp; path = src/VisualSystems/Rulez/vs_src/CloudsVisualSystemRulez.cpp; sourceTree = "<group>"; };
28B4EE07183E723B0091E0F3 /* CloudsVisualSystemRulez.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CloudsVisualSystemRulez.h; path = src/VisualSystems/Rulez/vs_src/CloudsVisualSystemRulez.h; sourceTree = "<group>"; };
28B4EE09183E723B0091E0F3 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
Expand Down Expand Up @@ -874,6 +877,8 @@
children = (
28B4EE0C183E723B0091E0F3 /* Action.cpp */,
28B4EE0D183E723B0091E0F3 /* Action.h */,
28A8A7B2185DE97D009DA217 /* ConeAction.cpp */,
28A8A7B3185DE97D009DA217 /* ConeAction.h */,
28B4EE0E183E723B0091E0F3 /* CubeAction.cpp */,
28B4EE0F183E723B0091E0F3 /* CubeAction.h */,
28B4EE10183E723B0091E0F3 /* IcosphereAction.cpp */,
Expand Down Expand Up @@ -1665,6 +1670,7 @@
28B4EE35183E723B0091E0F3 /* Rule.cpp in Sources */,
E7D32FA91751C626006706ED /* ofxRParticleGlowieRenderer.cpp in Sources */,
E7D32FAA1751C626006706ED /* ofxRParticleRenderer.cpp in Sources */,
28A8A7B4185DE97D009DA217 /* ConeAction.cpp in Sources */,
280862221858A6DF00C51C32 /* ofxOscBundle.cpp in Sources */,
E7D32FAB1751C626006706ED /* ofxRParticleSystem.cpp in Sources */,
28B4EE32183E723B0091E0F3 /* TransformAction.cpp in Sources */,
Expand Down

0 comments on commit cffa2ce

Please sign in to comment.