Commit 02f3e9a9 authored by Kevin Dang's avatar Kevin Dang

added final comments to code

parent 160bb0e1
......@@ -9,20 +9,24 @@
#include <stdio.h>
#include "flocking.h"
// constructor which sets the positioning of the sphere object
// the 5 sphere ball objects will be randomly placed in the range
// -100 to 100
flocking::flocking(float _x, float _y, float _z): x(_x), y(_y), z(_z) {
x = ofRandom(-100,100);
y = ofRandom(-100,100);
z = ofRandom(-100,100);
location.set(x, y, z);
velocity.set(0,0,0);
acceleration.set(-0.001,0.01,0.01);
topSpeed = 5;
location.set(x, y, z); // we initialise the ofVec3f location variable to take in the x,y,z values
velocity.set(0,0,0); // initialise velocity variable
acceleration.set(-0.001,0.01,0.01); // initialise the acceleration variable
topSpeed = 5; // initialise topSpeed variable
}
void flocking::update(ofVec3f _tempPos) {
void flocking::update(ofVec3f _tempPos) { // update function will take in the position of the objects
staticTarget.set(_tempPos.x,_tempPos.y,_tempPos.z);
staticTarget.set(_tempPos.x,_tempPos.y,_tempPos.z); // set the 'static' position of the sphere objects
// movement calculation
dir.normalize();
dir = dir * 0.1;
acceleration = dir;
......@@ -33,8 +37,7 @@ void flocking::update(ofVec3f _tempPos) {
void flocking::display() {
ofPushMatrix();
ofTranslate(location.x, location.y, location.z);
ofTranslate(location.x, location.y, location.z); // sets the position of the sphere objects, translating it from 0 to new values
ofSetColor(255);
ofFill();
ofDrawSphere(0,0,0,20);
......
......@@ -16,10 +16,13 @@ public:
float x; // x
float y; // y
float z; // z
ofVec3f location, velocity, acceleration, dir, staticTarget; // ofVec3f variables for movement of sphere objects
float topSpeed; // max speed of objects
// function defintions
void display();
void update(ofVec3f _tempPos);
ofVec3f location, velocity, acceleration, dir, staticTarget;
float topSpeed;
};
......
......@@ -20,7 +20,7 @@ void lightBalls::update(ofVec3f _tempPos) {
Flocking[i].update(_tempPos); // apply the update function to all elements in the vector
}
for (int i = 0; i < Flocking.size(); i++) { // this controls the movement and direction of the sphere objects
for (int i = 0; i < Flocking.size(); i++) { // this controls the movement and direction of the sphere objects
Flocking[i].dir.set(Flocking[i].staticTarget.x - Flocking[i].location.x,Flocking[i].staticTarget.y - Flocking[i].location.y);
}
......
......@@ -13,8 +13,8 @@
class lightBalls {
public:
lightBalls();
void display();
lightBalls();
void display();
void update(ofVec3f _tempPos);
vector <flocking> Flocking; // create vector of Flocking class
};
......
......@@ -15,45 +15,46 @@ lightDrawing::lightDrawing() {}
void lightDrawing::setup() {
minDistance = 10;
rightMouseButtonPressed = false;
minDistance = 10; // sets a min distance to determine if it's worth adding detail to the drawing
rightMouseButtonPressed = false; // sets bool to false at setup
}
void lightDrawing::update(ofVec3f _pos) {
if (rightMouseButtonPressed) {
if (lastPoint.distance(_pos) >= minDistance) {
currentPolyline.curveTo(_pos);
if (lastPoint.distance(_pos) >= minDistance) { // if dist is greater than or equal to 10, then add detail
currentPolyline.curveTo(_pos); // curveTo helps smoothen our drawings
lastPoint = _pos;
}
}
}
void lightDrawing::draw() {
// standard stroke draw method
ofPushStyle();
ofSetColor(255);
for (int i = 0; i < drawLine.size(); i++) {
ofSetLineWidth(lineWidth[i]);
drawLine[i].draw();
drawLine[i].getSmoothed(1);
drawLine[i].draw(); // uses built in ofPolyline draw method
drawLine[i].getSmoothed(1); // smoothens line
}
ofPopStyle();
// light cluster method
ofPushStyle();
for (int i = 0; i < polylines.size(); i++) {
ofPolyline polyline = polylines[i];
polyline.draw();
ofPolyline polyline = polylines[i]; // initialising new ofPolyline object with existing 'polylines' object
polyline.draw(); // draws line drawings
ofSetColor(255, 50);
float numPoints = polyline.size();
float tangentLength = 800;
float numPoints = polyline.size(); // set float variable to take in vector size
float tangentLength = 800; // sets length of line clusters
for (int p=0; p<500; p+=1) {
ofVec3f point = polyline.getPointAtPercent(p/500.0);
ofVec3f point = polyline.getPointAtPercent(p/500.0); // 'returns a point at a percentage along the line'
float floatIndex = p/500.0 * (numPoints-1);
// vector normals are lines which are perpendicular to an existing line
// a tangent is very similar to normals and they are used to create interesting visuals
// in this code, tangents are used on its own to create an 'explosive' spread rather than a smooth spread
ofVec3f tangent = polyline.getTangentAtIndexInterpolated(floatIndex) * tangentLength;
ofLine(point-tangent/2, point+tangent/2);
}
......@@ -79,12 +80,20 @@ void lightDrawing::clearPreviousLine() {
}
// We are accessing the last object created.
// This is done by this part of the code: [drawLine.size()-1]
// For instance: when you first press the mouse, you create drawLine[1]
// but you want to access drawLine[0]. By taking 1 away, you gain access
// to the last object created and you add the vertex position to this object
void lightDrawing::mouseDragged(ofVec3f _pos) {
drawLine[drawLine.size() - 1].addVertex(_pos);
}
// whenever the mouse is pressed, you create a new ofPolyline
// object to draw a new line:
void lightDrawing::mouseRPressed() {
lineWidth.push_back(standardSize);
drawLine.push_back(ofPolyline());
......@@ -93,6 +102,7 @@ void lightDrawing::mouseRPressed() {
void lightDrawing::mousePressed(ofVec3f _pos) {
// when mouse pressed, use _pos values for the curveTo function to add detail and spread to the vector of ofPolyline objects
rightMouseButtonPressed = true;
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
......@@ -103,8 +113,8 @@ void lightDrawing::mousePressed(ofVec3f _pos) {
void lightDrawing::mouseReleased(ofVec3f _pos) {
rightMouseButtonPressed = false;
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
polylines.push_back(currentPolyline);
currentPolyline.clear();
polylines.push_back(currentPolyline); // adds another ofPolyline object when mouse released for light cluster method
currentPolyline.clear(); // stops continous drawing (i.e. disconnects new line with previous line drawing)
}
......@@ -118,8 +128,10 @@ void lightDrawing::bubbledraw(){
void lightDrawing::createbubble(ofVec3f _pos){
for(int i = 0; i<3; i++){
// draw bubble objects
sphere.setRadius(ofRandom(0.01,2));
storeSphere.push_back(sphere);
// positioning was set to make it appear more natural when used to draw
storeSphere[storeSphere.size()-1].setPosition(_pos+ofVec3f(ofRandom(-5,5),ofRandom(-5,5),ofRandom(-5,5)));
}
......
......@@ -17,31 +17,35 @@ class lightDrawing : public Gui {
public:
lightDrawing();
vector <ofPolyline> drawLine;
// functions
void setup();
void draw();
void clearPreviousLine();
void mouseDragged(ofVec3f _pos);
void mouseRPressed();
void update(ofVec3f _pos);
// standard stroke
vector <ofPolyline> drawLine;
vector <float> lineWidth;
// this is for the light cluster stroke
ofPolyline currentPolyline;
bool rightMouseButtonPressed;
ofVec3f lastPoint;
float minDistance;
vector <ofPolyline> polylines;
vector <float> lineWidth;
void mousePressed(ofVec3f _pos);
void mouseReleased(ofVec3f _pos);
// this is the bubble stroke
vector <ofSpherePrimitive> storeSphere;
ofSpherePrimitive sphere;
void bubbledraw();
void createbubble(ofVec3f _pos);
// mousepressed and mouse released controls
void mousePressed(ofVec3f _pos);
void mouseReleased(ofVec3f _pos);
};
......
#include "ofApp.h"
/*** Simon's Help Start ***/
bool ofApp::intersectPlane(const ofVec3f &n, const ofVec3f &p0, const ofVec3f &l0, const ofVec3f &l, float &t)
{
//read this article
//http://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-plane-and-ray-disk-intersection
// assuming vectors are all normalized
float denom = n.dot(l);
if (denom > 1e-6)
{
ofVec3f p0l0 = p0 - l0;
t = p0l0.dot(n) / denom;
return (t >= 0);
}
return false;
}
/*** Simon's Help End ***/
//--------------------------------------------------------------
void ofApp::camRotate(){
//Center of Window
int windowcenterx = ofGetWindowWidth() / 2;
......@@ -56,6 +32,13 @@ void ofApp::camRotate(){
//--------------------------------------------------------------
void ofApp::setup(){
// set starting position of player
playerLocationX = 0;
playerLocationY = 0;
playerLocationZ = -600;
/*** Simon's Help Start ***/
planeDist = 100;
......@@ -72,7 +55,7 @@ void ofApp::setup(){
ofSetVerticalSync(true);
ofSetSmoothLighting(true);
state = 0;
state = 0; // set state to be at 0
//Loads Image for Startup Screen
landingPage.loadImage("landingPage.png");
......@@ -83,20 +66,13 @@ void ofApp::setup(){
isMouseHeldDown = false;
playerLocationX = 0;
playerLocationY = 0;
playerLocationZ = -600;
ofEnableAlphaBlending();
//Calls setup from classes
LightDrawing.setup();
userInterface.setup();
for(int i = 0; i<5; i++){
newLightBallPosition.push_back(ofVec3f());
}
......@@ -143,8 +119,6 @@ void ofApp::update(){
ofVec3f planePoint = cam.getPosition() + normal * planeDist; // a point on a plane 'n' pixels away
float dist = 0;
intersectPlane(normal, planePoint, cam.getPosition(), ray, dist); // find the distance along the ray at which intersection with our plane occurs
ray *= dist; // scale the ray to the correct distance
pos = cam.getPosition() + cam.getLookAtDir()*50.f; // + ray; //add it to the camera origin ... ///TADA
......@@ -331,7 +305,7 @@ void ofApp::draw(){
ofFill();
for (int i = 0; i < 50; i++) {
ofSetColor(255);
ofFill();
......@@ -346,13 +320,13 @@ void ofApp::draw(){
smallSpheres.display();
lightBalls.display();
//Camera End
//Camera End
cam.end();
//Disable DepthTest and Lighting
ofDisableDepthTest();
ofDisableLighting();
//Draw GUI User Interface
userInterface.draw();
......
......@@ -11,9 +11,9 @@
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void setup();
void update();
void draw();
void camRotate();
......@@ -30,9 +30,6 @@ public:
void gotMessage(ofMessage msg);
bool intersectPlane(const ofVec3f &n, const ofVec3f &p0, const ofVec3f &l0, const ofVec3f &l, float &t);
//GLFW static cast pointer
GLFWwindow *window = static_cast<ofAppGLFWWindow*>(ofGetWindowPtr())->getGLFWWindow();
......@@ -63,7 +60,7 @@ public:
Gui userInterface;
lightDrawing LightDrawing;
//Default World Objects
populateSmallSphere smallSpheres;
lightBalls lightBalls;
......
......@@ -14,7 +14,7 @@ populateSmallSphere::populateSmallSphere() {
sphereObjects.push_back(smallSphereObject(0,0,0)); // populate the world with 600 small sphere objects
}
for (int i = 0; i < 5; i++) {
boxObject.push_back(boxObjects(0,0,0)); // populate the world with box objects
boxObject.push_back(boxObjects(0,0,0)); // populate the world with box objects
}
}
......
......@@ -16,8 +16,8 @@ class populateSmallSphere {
public:
populateSmallSphere();
void display();
// create vector of smallSphereObject and boxObjects
vector <smallSphereObject> sphereObjects;
// create vector of smallSphereObject and boxObjects
vector <smallSphereObject> sphereObjects;
vector <boxObjects> boxObject;
};
......
......@@ -9,9 +9,9 @@
#include <stdio.h>
#include "smallSphereObject.h"
// class for small sphere objects which populate space
smallSphereObject::smallSphereObject(float _x, float _y, float _z): x(_x), y(_y), z(_z) {
x = ofRandom(-2500,2500);
x = ofRandom(-2500,2500); // set the limit of -2500 to 2500 for how far into the world these objects are scattered
y = ofRandom(-2500,2500);
z = ofRandom(-2500,2500);
location.set(x, y, z);
......@@ -19,7 +19,7 @@ smallSphereObject::smallSphereObject(float _x, float _y, float _z): x(_x), y(_y)
void smallSphereObject::display() {
ofPushMatrix();
ofTranslate(location.x, location.y, location.z);
ofTranslate(location.x, location.y, location.z); // displays objects at location specified in location vector
ofSetColor(255);
ofFill();
ofDrawSphere(0,0,0,2);
......@@ -27,6 +27,7 @@ void smallSphereObject::display() {
}
// boxObject display function which does the same thing as the sphere display function but with boxes
void boxObjects::display() {
ofPushMatrix();
ofTranslate(location.x, location.y, location.z);
......
......@@ -18,7 +18,7 @@ protected:
float y;
float z;
ofVec3f location; // create vector for location variable which takes in the floats x,y,z
public:
public:
explicit smallSphereObject(float _x, float _y, float _z); // the explicit keyword allows for constructor inheritance
virtual void display();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment