rendered paste body/*
* vertex.h
* openFrameworks
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include "ofMain.h"
#include "math.h"
class vertex{
public:
vertex();
vertex(float x, float y);
~vertex();
void setAnchor(vertex anchor);
void rotate(vertex anchor, float theta);
void rotate(float theta);
void translate(float xAmt, float yAmt);
void translate(int time, float xAmt, float yAmt);
float getX();
void setX(float x);
float getY();
void setY(float y);
void draw();
bool translating;
bool rotating;
private:
float X;
float Y;
float AnchorX;
float AnchorY;
float targetXt;
float targetYt;
float startXt;
float startYt;
int startTime;
int timeFrame;
};
/*
* vertex.cpp
* openFrameworks
*
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#include "vertex.h"
#include <iostream>
vertex::vertex(){
X = 0;
Y = 0;
translating = false;
rotating = false;
}
vertex::vertex(float x, float y){
X = (float)x;
Y = (float)y;
translating = false;
rotating = false;
}
vertex::~vertex(){
// X = 0;
// Y = 0;
}
float vertex::getX(){
return X;
}
void vertex::setX(float x){
X = x;
}
float vertex::getY(){
return Y;
}
void vertex::setY(float y){
Y = y;
}
void vertex::draw(){
/* if(translating || rotating){
if(translating && rotating){
}
if(translating && !rotating){
if(ofGetElapsedTimeMillis() >= (timeFrame + startTime) ){
translating = false;
translate(targetXt,targetYt);
}else{
int curr = ofGetElapsedTimeMillis();
float percentage = ((curr - startTime)/timeFrame);
ofVertex(X + (targetXt * percentage) , Y + (targetYt * percentage));
}
}
if(rotating && !translating){
}
}else{*/
ofVertex(X,Y);
/*}*/
}
void vertex::translate(float xAmt, float yAmt){
/*
X =+ xAmt;
Y =+ yAmt;
*/
}
void vertex::translate(int time, float xAmt, float yAmt){
/*
translating = true;
startXt = X;
startYt = Y;
targetXt = xAmt;
targetYt = yAmt;
startTime = ofGetElapsedTimeMillis();
timeFrame = time;
*/
}
void vertex::rotate(vertex anchor, float theta){
AnchorX = anchor.getX();
AnchorY = anchor.getY();
// printf("anchor x: %d anchor y: %d \n", AnchorX, AnchorY);
float anchorX = AnchorX;
float anchorY = AnchorY;
float tempX = X - anchorX;
float tempY = Y - anchorY;
float finishedX = cos(theta)*tempX - sin(theta) * tempY;
float finishedY = sin(theta)*tempX + cos(theta) * tempY;
finishedX += anchorX;
finishedY += anchorY;
X = finishedX;
Y = finishedY;
}
void vertex::setAnchor(vertex anchor){
AnchorX = anchor.getX();
AnchorY = anchor.getY();
}
void vertex::rotate(float theta){
printf("anchor x: %f anchor y: %f \n", AnchorX, AnchorY);
float anchorX = AnchorX;
float anchorY = AnchorY;
float tempX = X - anchorX;
float tempY = Y - anchorY;
float finishedX = cos(theta)*tempX - sin(theta) * tempY;
float finishedY = sin(theta)*tempX + cos(theta) * tempY;
finishedX += anchorX;
finishedY += anchorY;
X = finishedX;
Y = finishedY;
}