summaryrefslogtreecommitdiff
path: root/sunkenEngine/src/viewport.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sunkenEngine/src/viewport.cpp')
-rwxr-xr-xsunkenEngine/src/viewport.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/sunkenEngine/src/viewport.cpp b/sunkenEngine/src/viewport.cpp
new file mode 100755
index 0000000..a169146
--- /dev/null
+++ b/sunkenEngine/src/viewport.cpp
@@ -0,0 +1,136 @@
+#include "viewport.h"
+
+
+
+viewport::viewport()
+{
+ //ctor
+}
+viewport::viewport(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ setup(_w,_h,_x,_y,_r,_ox,_oy);
+}
+
+void viewport::setup(int _w,int _h,int _x,int _y,float _r,int _ox,int _oy) {
+ r=_r;
+ w=_w;
+ h=_h;
+ x=_x;
+ y=_y;
+ ox=_ox;
+ oy=_oy;
+ rb1.allocate(w,h,GL_RGB);
+ rb2.allocate(w,h,GL_RGB);
+
+ printf("%ix%i, vp offset: %f,%f\n",w,h,-(sin(ofDegToRad(r))*h/2)-(cos(ofDegToRad(r))*w/2),-(sin(ofDegToRad(r))*w/2)-(cos(ofDegToRad(r))*h/2));
+}
+
+void viewport::draw(float a,unsigned char* controllers,int xshift,int yshift,playlist &list,bool transparentBlack,int note,int mode,ofColor* controller_colours,bool controlColours,float scale,float fscale,float colShift,int fadeBG){
+
+ //http://forum.xfce.org/viewtopic.php?id=6580
+
+ // test screen shape
+ /*
+ ofSetColor(255,0,0);
+ ofRect(0,0,w/2,h/2);
+ ofRect(w/2,h/2,w/2,h/2);
+ ofSetColor(0,255,0);
+ ofRect(0,h/2,w/2,h/2);
+ ofRect(w/2,0,w/2,h/2);
+ */
+
+ ofPushMatrix();
+
+ rb1.begin();
+
+ //can be done with texture offset?
+
+ int startx=((w-(w*fscale))/2)+xshift;
+ while (startx>0) startx-=(w*fscale);
+ int starty=((h-(h*fscale))/2)+yshift;
+ while (starty>0) starty-=(h*fscale);
+
+ for (int i=startx;i<w*2;i+=(w*fscale)) {
+ for (int j=starty;j<h*2;j+=(h*fscale)) {
+ rb2.draw(i,j,w*fscale,h*fscale);
+ }
+ }
+
+ if (fadeBG>0) {
+ //fadeout part
+ ofEnableAlphaBlending();
+ ofSetColor(0,0,0,fadeBG);
+ ofRect(0,0,w,h);
+ ofDisableAlphaBlending();
+ }
+
+ float notewidth=w/NUM_NOTES;
+ float noteheight=h/NUM_CONTROLLERS;
+
+ ofPushStyle();
+
+ if (note>0) {
+ switch(mode) {
+ case BLOCKS:
+ for (int i=0;i<NUM_CONTROLLERS;i++){
+ ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7));
+ ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight);
+ }
+ break;
+ case LIST:
+ if (list.lock()) { //if playlist is loaded
+ if (list.layers.find(note)!=list.layers.end()) {
+ ofPushMatrix();
+ ofTranslate(w/2,h/2);
+ ofScale(scale,scale,scale);
+ ofTranslate(-w/2,-h/2);
+ ofSetColor(255,255,255);
+ if (controlColours) list.layers[note]->draw(a,controllers,w,h,transparentBlack,colShift);
+ else list.layers[note]->draw(a,w,h,colShift);
+ ofPopMatrix();
+ }
+ list.unlock();
+ }
+ break;
+ }
+ }
+
+ ofPopStyle();
+
+ rb1.end();
+
+ rb2.begin();
+ ofSetColor(255,255,255);
+ rb1.draw(0,0);
+ rb2.end();
+
+ ofPopMatrix();
+
+ ofPushMatrix();
+ //ofTranslate(x+(w/2),y+(h/2)); this was the one that was working
+ //ofTranslate(abs(sin(ofDegToRad(r))*h/2)+abs(cos(ofDegToRad(r))*w/2),abs(sin(ofDegToRad(r))*w/2)+abs(cos(ofDegToRad(r))*h/2));
+ ofTranslate(x,y);
+
+ ofTranslate(((w/2)*abs(cos(ofDegToRad(r))))+((h/2)*abs(sin(ofDegToRad(r)))),
+ ((w/2)*abs(sin(ofDegToRad(r))))+((h/2)*abs(cos(ofDegToRad(r)))));
+
+ ofRotate(r);
+ ofTranslate(-w/2,-h/2);
+ //ofTranslate(-abs(sin(ofDegToRad(r))*h/2)-abs(cos(ofDegToRad(r))*w/2),-abs(sin(ofDegToRad(r))*w/2)-abs(cos(ofDegToRad(r))*h/2));
+ //ofTranslate(ox,oy); get rid of this and get the rotation right
+
+ ofDisableAlphaBlending();
+
+ rb2.draw(0,0);
+
+ ofPopMatrix();
+
+
+
+
+
+}
+
+viewport::~viewport()
+{
+ //dtor
+}