tessecraft / CubeObj

Files at this revision

API Documentation at this revision

Comitter:
zgtk_r
Date:
Sun Jan 29 02:15:35 2017 +0000
Commit message:
For the 8x8x8 RGB LEDCube

Changed in this revision

CubeObj.cpp Show annotated file Show diff for this revision Revisions of this file
CubeObj.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 96a4e9c69d57 CubeObj.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CubeObj.cpp	Sun Jan 29 02:15:35 2017 +0000
@@ -0,0 +1,81 @@
+#include "CubeObj.h"
+#include<stdlib.h>
+
+CubeObj::CubeObj(){
+    x = 0;
+    y = 0;
+    z = 0;
+    gz = 0;
+    c = 0;
+}
+CubeObj::CubeObj(int sx, int sy, int sz, COL sc){
+    set(sx, sy, sz, sc);
+    ang[0] = 0;
+    ang[1] = 0;
+    sp = 0;
+    gz = 0;
+}
+void CubeObj::set(int sx, int sy, int sz, COL sc){
+    x = (double)sx;
+    y = (double)sy;
+    z = (double)sz;
+    c = sc;
+    ang[0] = 0;
+    ang[1] = 0;
+    sp = 0;
+    gz = 0;
+}
+void CubeObj::set(double ang1, double ang2, double s){
+    this->ang[0] = ang1;
+    this->ang[1] = ang2;
+    this->sp = s;
+    gz = 0;
+}
+void CubeObj::go(int tx, int ty, int tz, double s){
+    PutPixel(x, y, z, c);
+    ang[0] = atan2(ty-y, tx-x);
+    x += cos(ang[0]) * s;
+    y += sin(ang[0]) * s;
+    ang[1] = atan2(tz-z, tx-x);
+    z += sin(ang[1]) * s;
+    if(z <= -1 || z >= 8){
+        c = 0;
+    }
+}
+void CubeObj::go(double ang1, double ang2, double s){
+    PutPixel(x, y, z, c);
+    this->ang[0] = ang1;
+    this->ang[1] = ang2;
+    this->sp = s;
+    x += cos(ang[0]) * sp;
+    y += sin(ang[0]) * sp;
+    z += sin(ang[1]) * sp;
+}
+void CubeObj::go(){
+    PutPixel(x, y, z, c);
+    x += cos(ang[0]) * sp;
+    y += sin(ang[0]) * sp;
+    z += sin(ang[1]) * sp;
+}
+void CubeObj::friction(double stp){
+    sp /= stp;
+} 
+void CubeObj::gravity(double stp){
+    gz += stp;
+    z -= gz;
+}
+void CubeObj::leave(int tx, int ty, int tz, double s){
+    PutPixel(x, y, z, c);
+    ang[0] = atan2(ty-y, tx-x);
+    x -= cos(ang[0]) * s;
+    y -= sin(ang[0]) * s;
+    ang[1] = atan2(tz-z, tx-x);
+    z -= cos(ang[1]) * s;
+    if(z <= -1 || z >= 8){
+        c = 0;
+    }
+}
+
+void CubeObj::draw(){
+    PutPixel(x, y, z, c);
+}
\ No newline at end of file
diff -r 000000000000 -r 96a4e9c69d57 CubeObj.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CubeObj.h	Sun Jan 29 02:15:35 2017 +0000
@@ -0,0 +1,27 @@
+#pragma once
+
+#include<math.h>
+#include"LEDCUBE_RGB_888.h"
+
+#define PI 3.1415926535
+
+class CubeObj{
+public:
+    float x, y, z;
+    float gz;
+    float ang[2], sp;
+    int life;
+    COL c;
+    CubeObj();
+    CubeObj(int sx, int sy, int sz, COL sc);
+    void set(int sx, int sy, int sz, COL sc);
+    void set(double ang1, double ang2, double s);
+    void go();
+    void go(int tx, int ty, int tz, double s);
+    void go(double ang1, double ang2, double s);
+    void friction(double stp);
+    void gravity(double stp);
+    void leave(int tx, int ty, int tz, double s);
+    void move(int gx, int gy, int gz);
+    void draw();
+};
\ No newline at end of file