00001 #include <gl/glut.h>
00002 #include <iostream>
00003 #include <math.h>
00004
00005 #include "TxPoint.h"
00006 #include "LifeVariables.h"
00007
00008 using namespace std;
00009
00010 TxPoint::TxPoint(GLfloat x, GLfloat y, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
00011 this->mouseOver = false;
00012 this->position[0] = x;
00013 this->position[1] = y;
00014 this->rgba[0] = red;
00015 this->rgba[1] = green;
00016 this->rgba[2] = blue;
00017 this->rgba[3] = alpha;
00018 this->computeBounds();
00019 }
00020
00021
00022 void TxPoint::computeBounds() {
00023
00024 this->bounds[0] = floor(this->position[0])- TX_POINT_BOUNDING_RADIUS;
00025
00026 this->bounds[1] = ceil(this->position[0])+ TX_POINT_BOUNDING_RADIUS;
00027 }
00028
00029
00030 bool TxPoint::hit(GLfloat x, GLfloat y) {
00031
00032 if(x < bounds[0] || x > bounds[1]) {
00033
00034 return false;
00035 }
00036
00037 else {
00038
00039 return true;
00040 }
00041 }
00042
00043
00044 void TxPoint::onMouseOver() {
00045 this->mouseOver = true;
00046 }
00047
00048
00049 void TxPoint::onMouseOut() {
00050 this->mouseOver = false;
00051 }
00052
00053
00054 void TxPoint::moveTo(GLfloat x, GLfloat y) {
00055 this->position[0] = x;
00056 this->position[1] = y;
00057 this->computeBounds();
00058 }
00059
00060
00061 bool TxPoint::equals(TxPoint *p) {
00062 return (this->position[0] == p->position[0] &&
00063 this->position[1] == p->position[1] &&
00064 this->rgba[0] == p->rgba[0] &&
00065 this->rgba[1] == p->rgba[1] &&
00066 this->rgba[2] == p->rgba[2] &&
00067 this->rgba[3] == p->rgba[3]);
00068 }
00069
00070
00071 void TxPoint::render() {
00072 glPushAttrib(GL_CURRENT_BIT);
00073 glColor4f(0,0,0,0);
00074 renderString(this->bounds[1], position[1], FONT, position[0]);
00075 glPointSize(TX_POINT_RADIUS);
00076 glBegin(GL_POINTS);
00077 glColor4fv(this->rgba);
00078 glVertex2fv(this->position);
00079 glEnd();
00080 glPopAttrib();
00081
00082
00083 }