Commit dbcd4d21 authored by Kevin Dang's avatar Kevin Dang

updated Lux files

parent 2b39bff1
No preview for this file type
......@@ -2,125 +2,119 @@
// lightDrawing.cpp
// Lux
//
// Created by Kevin Dang on 06/04/2016.
// Created by Dat Nguyen & Kevin Dang
//
//
#include <stdio.h>
#include "lightDrawing.h"
// based from tutorial: http://openframeworks.cc/ofBook/chapters/foreword.html
lightDrawing::lightDrawing() {}
void lightDrawing::setup() {
// initialise count variable
// value is set at -1 so that
// it matches the drawLine element number
storeLineXYZCount = -1;
countTest = 0;
sumX = 0;
minDistance = 10;
leftMouseButtonPressed = false;
rightMouseButtonPressed = false;
}
void lightDrawing::update(ofVec3f _pos) {
if (rightMouseButtonPressed) {
if (lastPoint.distance(_pos) >= minDistance) {
currentPolyline.curveTo(_pos);
lastPoint = _pos;
}
}
}
void lightDrawing::draw() {
ofPushStyle();
ofSetColor(255);
ofSetLineWidth(2);
for (int i = 0; i < drawLine.size(); i++) {
drawLine[i].draw();
drawLine[i].getSmoothed(1);
for (int a = 0; a < getLineXYZ.size(); a++) {
getLineXYZ = drawLine[i].getVertices();
allX = getLineXYZ[a].x; // prints out the individual values of X
//std::cout << "drawLine[" << i << "] : Position[" << a << "] = " << allX << std::endl;
// this variable should be used for MEAN calculation
numberOfPositions = a;
while (countTest <= a) { // this has to be <= or it will not take into account the next element
sumX += getLineXYZ[countTest].x;
sumY += getLineXYZ[countTest].y;
sumZ += getLineXYZ[countTest].z;
countTest++;
}
meanX = sumX/countTest;
meanY = sumY/countTest;
meanZ = sumZ/countTest;
}
// std::cout << "" << std::endl;
// std::cout << "This is sumX for drawLine[" << i << "]: " << sumX << std::endl;
// std::cout << "This is countTest: " << countTest << std::endl;
// std::cout << "This is meanX: " << meanX << std::endl;
// std::cout << "This is meanY: " << meanY << std::endl;
// std::cout << "This is meanZ: " << meanZ << std::endl;
}
ofPopStyle();
// std::cout << "" << std::endl;
// std::cout << "" << std::endl;
ofPushStyle();
for (int i = 0; i < polylines.size(); i++) {
ofPolyline polyline = polylines[i];
polyline.draw();
ofSetColor(255, 50);
float numPoints = polyline.size();
float tangentLength = 300;
for (int p=0; p<500; p+=1) {
ofVec3f point = polyline.getPointAtPercent(p/500.0);
float floatIndex = p/500.0 * (numPoints-1);
ofVec3f tangent = polyline.getTangentAtIndexInterpolated(floatIndex) * tangentLength;
ofLine(point-tangent/2, point+tangent/2);
}
}
ofSetColor(255,130);
ofSetLineWidth(1);
currentPolyline.draw();
ofPopStyle();
}
void lightDrawing::clearAllLines() {
drawLine.clear();
drawLine.clear();
}
void lightDrawing::mouseDragged(ofVec3f _pos) {
drawLine[drawLine.size() - 1].addVertex(_pos);
// creates new element for every point position
getLineXYZ.push_back(ofVec3f());
// for each nth element of 'drawLine object'
// store all the points relative to that nth object inside a ofVec3f object: getLineXYZ
if (leftMouseButtonPressed) {
drawLine[drawLine.size() - 1].addVertex(_pos);
}
}
void lightDrawing::mousePressed() {
void lightDrawing::mouseRPressed() {
leftMouseButtonPressed = true;
drawLine.push_back(ofPolyline());
}
void lightDrawing::mouseRReleased() {
leftMouseButtonPressed = false;
}
void lightDrawing::mousePressed(ofVec3f _pos) {
// drawLine.push_back(ofPolyline());
// create a new ofVec3f variabe everytime mouse is pressed
// this is only for the storeLineXYZ as it takes the average
// of all the other points
// i.e. you only need one set of storeLineXYZ for all the getLineXYZ data
// of one line drawing
storeLineXYZ.push_back(ofVec3f());
// increment count variable to match
// with the number of elements in drawLine
storeLineXYZCount++;
rightMouseButtonPressed = true;
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
lastPoint.set(_pos.x,_pos.y,_pos.z);
}
void lightDrawing::mouseReleased(ofVec3f _pos) {
rightMouseButtonPressed = false;
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
polylines.push_back(currentPolyline);
currentPolyline.clear();
}
void lightDrawing::bubblesetup(){
}
......
......@@ -2,7 +2,7 @@
// lightDrawing.h
// Lux
//
// Created by Kevin Dang on 06/04/2016.
// Created by Dat Nguyen & Kevin Dang
//
//
......@@ -10,6 +10,7 @@
#define lightDrawing_h
#include "ofMain.h"
// based from tutorial: http://openframeworks.cc/ofBook/chapters/foreword.html
class lightDrawing {
public:
......@@ -21,30 +22,26 @@ public:
void draw();
void clearAllLines();
void mouseDragged(ofVec3f _pos);
void mousePressed();
void mouseRPressed();
void mouseRReleased();
void update(ofVec3f _pos);
// ofLight light;
vector <ofVec3f> getLineXYZ;
vector <ofVec3f> storeLineXYZ;
ofPolyline currentPolyline;
bool leftMouseButtonPressed;
bool rightMouseButtonPressed;
ofVec3f lastPoint;
float minDistance;
vector <ofPolyline> polylines;
void mousePressed(ofVec3f _pos);
void mouseReleased(ofVec3f _pos);
int storeLineXYZCount;
float meanX, meanY, meanZ;
float allX;
float sumX;
float sumY;
float sumZ;
int numberOfPositions;
float tempCatchValue;
int countTest;
vector <ofSpherePrimitive> storeSphere;
ofSpherePrimitive sphere;
......
......@@ -90,6 +90,7 @@ void ofApp::setup(){
guiBrushes.setPosition(810,10);
guiBrushes.add(standard.setup("Standard", false));
guiBrushes.add(bubbles.setup("Bubble", true));
guiBrushes.add(lightCluster.setup("Line Cluster", false));
LightDrawing.bubblesetup();
}
......@@ -146,6 +147,11 @@ void ofApp::update(){
LightDrawing.createbubble(pos);
}
if(isMouseHeldDown == true && lightCluster == true){
LightDrawing.mouseDragged(pos);
}
if (ofGetKeyPressed('w') == true) {
cam.dolly(-1.4);
......@@ -177,6 +183,8 @@ void ofApp::update(){
//ofSeedRandom();
srand(time(NULL));
LightDrawing.update(pos);
}
......@@ -262,12 +270,21 @@ void ofApp::mouseMoved(int x, int y ){
void ofApp::mouseDragged(int x, int y, int button){
if(mouseMode == false)
camRotate();
LightDrawing.mouseDragged(pos);
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
if(mouseMode == false && standard == true){
LightDrawing.mousePressed();
// LightDrawing.mousePressed(pos);
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mouseRPressed();
}
isMouseHeldDown = true;
}
......@@ -276,13 +293,25 @@ void ofApp::mousePressed(int x, int y, int button){
}
if (lightCluster == true) {
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mousePressed(pos);
}
}
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
if(mouseMode == false)
isMouseHeldDown = false;
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mouseReleased(pos);
}
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mouseRReleased();
}
}
......
......@@ -53,6 +53,6 @@ class ofApp : public ofBaseApp{
ofxFloatSlider a1,a2,a3,d1,d2,d3;
ofxPanel guiBrushes;
ofxToggle standard, bubbles;
ofxToggle standard, bubbles, lightCluster;
};
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