Commit b7a83252 authored by Kevin Dang's avatar Kevin Dang

added LMB and RMB functionality

parent ac3dd516
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>E4B69B5A0A3A1756003C02F2</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
......@@ -2,125 +2,113 @@
// 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() {
light.setPosition(meanX,meanY,meanZ);
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();
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();
// std::cout << "" << std::endl;
// std::cout << "" << std::endl;
}
void lightDrawing::clearAllLines() {
drawLine.clear();
// for (int i = 0; i < drawLine.size(); i++) {
// drawLine[i].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());
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);
// 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++;
}
void lightDrawing::mouseReleased(ofVec3f _pos) {
rightMouseButtonPressed = false;
currentPolyline.curveTo(_pos.x,_pos.y,_pos.z);
polylines.push_back(currentPolyline);
currentPolyline.clear();
}
......@@ -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,31 +22,29 @@ public:
void draw();
void clearAllLines();
void mouseDragged(ofVec3f _pos);
void mousePressed();
void mouseRPressed();
void mouseRReleased();
void update();
void update(ofVec3f _pos);
ofLight light;
// 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;
};
......
......@@ -42,17 +42,17 @@ void ofApp::camRotate(){
cam.pan(xdiff);
if(mouseMode == false)
glfwSetCursorPos(window, windowcenterx, windowcentery);
glfwSetCursorPos(window, windowcenterx, windowcentery);
}
//--------------------------------------------------------------
void ofApp::setup(){
mouseMode = false;
......@@ -89,12 +89,16 @@ void ofApp::setup(){
gui.add(d2.setup("Diffuse 2", 0.f, -1.0f, 1.0f));
gui.add(d3.setup("Diffuse 3", 1.f, -1.0f, 1.0f));
}
//--------------------------------------------------------------
void ofApp::update(){
/*** Simon's Help Start ***/
......@@ -127,19 +131,19 @@ void ofApp::update(){
if(mouseMode == false){
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}else{
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
if(isMouseHeldDown == true){
LightDrawing.mouseDragged(pos);
}
LightDrawing.update();
LightDrawing.update(pos);
if (ofGetKeyPressed('w') == true) {
......@@ -167,19 +171,19 @@ void ofApp::update(){
cam.boom(1.4);
}
//light.setSpotlight();
//ofSeedRandom();
srand(time(NULL));
srand(time(NULL));
}
//--------------------------------------------------------------
void ofApp::draw(){
ofBackground(45);
ofEnableDepthTest();
light.enable();
......@@ -207,13 +211,13 @@ void ofApp::draw(){
// ofDrawBox(ofRandom(-1000,1000),ofRandom(-1000,1000), ofRandom(-1000,1000),100);
ofDrawBox(100,100,10,100);
}
//LightDrawing.light.enable();
LightDrawing.draw();
//LightDrawing.light.disable();
cam.end();
light.disable();
ofDisableDepthTest();
......@@ -224,8 +228,8 @@ void ofApp::draw(){
ofFill();
ofCircle(ofGetWindowWidth()/2,ofGetWindowHeight()/2,2);
}
//--------------------------------------------------------------
......@@ -237,7 +241,7 @@ void ofApp::keyPressed(int key){
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
if (key == 'r') {
LightDrawing.clearAllLines();
}
......@@ -247,50 +251,66 @@ void ofApp::keyReleased(int key){
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
if(mouseMode == false)
camRotate();
camRotate();
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
if(mouseMode == false)
camRotate();
camRotate();
LightDrawing.mouseDragged(pos);
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
if(mouseMode == false){
LightDrawing.mousePressed();
isMouseHeldDown = true;
if (button == OF_MOUSE_BUTTON_RIGHT) {
LightDrawing.mousePressed(pos);
}
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mouseRPressed();
}
isMouseHeldDown = true;
}
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
if(mouseMode == false)
isMouseHeldDown = false;
isMouseHeldDown = false;
if (button == OF_MOUSE_BUTTON_RIGHT) {
LightDrawing.mouseReleased(pos);
}
if (button == OF_MOUSE_BUTTON_LEFT) {
LightDrawing.mouseRReleased();
}
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
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