A demo program for DOGL-128 LCD module. Based on Mike Sheldon's 3D Tie Fighter demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Cuboid.cpp Source File

Cuboid.cpp

00001 /* 
00002  * libmbed-graphics 2D and wireframe 3D graphics library for the MBED
00003  * microcontroller platform
00004  * Copyright (C) <2009> Michael Sheldon <mike@mikeasoft.com>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  * Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #include "Cuboid.h"
00023 
00024 // six sides, four vertices in each
00025 int _cube[6][4][3]={
00026     {
00027         {-10,-10,-10},
00028         { 10,-10,-10},
00029         { 10, 10,-10},
00030         {-10, 10,-10}
00031     },{
00032         {-10,-10, 10},
00033         { 10,-10, 10},
00034         { 10, 10, 10},
00035         {-10, 10, 10}
00036     },{
00037         {-10,-10,-10},
00038         { 10,-10,-10},
00039         { 10,-10, 10},
00040         {-10,-10, 10}
00041     },{
00042         {-10, 10,-10},
00043         { 10, 10,-10},
00044         { 10, 10, 10},
00045         {-10, 10, 10}
00046     },{
00047         {-10,-10,-10},
00048         {-10, 10,-10},
00049         {-10, 10, 10},
00050         {-10,-10, 10}
00051     },{
00052         { 10,-10,-10},
00053         { 10, 10,-10},
00054         { 10, 10, 10},
00055         { 10,-10, 10}
00056     }
00057 };
00058 
00059 
00060 Cuboid::Cuboid()
00061         : Object3D::Object3D()  {
00062 
00063 }
00064 
00065 void Cuboid::render(Graphics &g)
00066 {
00067     int side, v;
00068     int x[4], y[4], z[4];
00069     
00070     for (side = 0; side < 6; side++)
00071     {
00072         for (v = 0; v < 4; v++)
00073         {
00074             x[v] = _cube[side][v][0];
00075             y[v] = _cube[side][v][1];
00076             z[v] = _cube[side][v][2];
00077         }
00078         rotate3d(x, y, z, _rx, _ry, _rz, 4);
00079         for (v = 0; v < 4; v++)
00080         {
00081             x[v] += _x;
00082             y[v] += _y;
00083             z[v] += _z;
00084         }
00085         for (v = 0; v < 4; v++)
00086         {
00087             g.line3d(x[v], y[v], z[v], x[(v+1)%4], y[(v+1)%4], z[(v+1)%4], _colour);
00088         }
00089     }
00090 
00091     /*x0 = _cube[1][0][0];
00092     y0 = _cube[1][0][1];
00093     z0 = _cube[1][0][2];
00094     rotate3d(&x0, &y0, &z0, _rx, _ry, _rz);
00095     x1 = _cube[0][0][0];
00096     y1 = _cube[0][0][1];
00097     z1 = _cube[0][0][2];
00098     rotate3d(&x1, &y1, &z1, _rx, _ry, _rz);
00099     g.line3d(x0 + _x, y0 + _y, z0 + _z, x1 + _x, y1 + _y, z1 + _z, _colour);*/
00100 }