Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Plot2D.cc

Go to the documentation of this file.
00001 /*
00002     File:           Plot2D.cc
00003 
00004     Function:       See header file
00005 
00006     Author(s):      Andrew Willmott
00007 
00008     Copyright:      (c) 1995-2000, Andrew Willmott
00009 
00010     Notes:          
00011 
00012 */
00013 
00014 #include "gcl/Plot2D.h"
00015 
00021 scPlot2D::scPlot2D() : scPrimitive(pPoly), plotType(plotStep)
00022 {
00023     samples.SetSize(10, 10);
00024     samples.MakeZero();
00025 }
00026  
00027 StrConst scPlot2D::Label() const
00028 {
00029     return("2D Plot");
00030 }
00031 
00032 Void scPlot2D::Draw(Renderer &r, SLContext *context)
00033 {
00034     Int         i, j;
00035     Point       pos0, pos1, pos2, pos3;
00036     Vector      dx, dz, normal;
00037     Colour      col = *(SC_GET(Colour));
00038                 
00039     r.MakeCurrent();
00040 
00041     if (plotType != plotStep)
00042     {
00043         dx = Vector(2.0 / (samples.Cols() - 1), 0, 0);
00044         dz = Vector(0, 0, 2.0 / (samples.Rows() - 1));
00045 
00046         pos0[2] = -1;
00047         
00048         for (i = 0; i < samples.Rows() - 1; i++)
00049         {
00050             pos0[0] = -1;
00051             pos1 = pos0 + dz;
00052             
00053             for (j = 0; j < samples.Cols() - 1; j++)
00054             {
00055                 pos3 = pos0 + dx;
00056                 pos2 = pos1 + dx;
00057                 pos0[1] = samples[i][j] + 0.01;
00058                 pos1[1] = samples[i + 1][j] + 0.01;
00059                 pos2[1] = samples[i + 1][j + 1] + 0.01;
00060                 pos3[1] = samples[i][j + 1] + 0.01;
00061                 
00062                 normal = norm(cross(pos1 - pos0, pos3 - pos0)); 
00063                 
00064                 r.N(norm(normal));
00065                 r.C(col).Begin(sRenderStyle)
00066                     .P(pos0).P(pos1).P(pos2).P(pos3)
00067                     .End();
00068 
00069                 pos0 += dx;
00070                 pos1 += dx;
00071             }
00072             
00073             pos0 += dz;
00074         }
00075     }
00076     else
00077     {
00078         dx = Vector(2.0 / samples.Cols(), 0, 0);
00079         dz = Vector(0, 0, 2.0 / samples.Rows());
00080 
00081         pos0[2] = -1;
00082         
00083         for (i = 0; i < samples.Rows(); i++)
00084         {
00085             pos0[0] = -1;
00086             pos1 = pos0 + dz;
00087             
00088             for (j = 0; j < samples.Cols(); j++)
00089             {
00090                 pos3 = pos0 + dx;
00091                 pos2 = pos1 + dx;
00092                 pos0[1] = pos1[1] = pos2[1] = pos3[1] = samples[i][j];
00093             
00094                 r.Begin(renPoly).P(pos0).P(pos1).P(pos2).P(pos3).End();
00095             
00096                 pos0 += dx;
00097                 pos1 += dx;
00098             }
00099             
00100             pos0 += dz;
00101         }
00102     }
00103 }
00104   

Generated at Sat Aug 5 00:17:01 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000