View Full Version : data display
Alex Christensen
06-06-2008, 12:21 PM
With the new Flexscript OpenGL commands, we now have more ability to better display data. We could always use all the OpenGL commands in C++ and some draw commands in Flexscript, but now we have a little more control of drawing. These could be used to make new ways to display data in a model, instead of just using the recorder object.
I've attached three models that draw 3D graphs. There's a cartesian 3d graph of a function of x, y, and time, a polar function of theta, phi, and time, and an actual practical application that draws a 3D bar graph of a global table.
Most of the code is in the OnDraw triggers of the visual tools. This code can be adapted to make some cool data displays.
AlanZhang
06-07-2008, 01:38 AM
Thanks, Alex. This is really great! The cartesian model (and polar model) shows a great way of visualizing functions with parameter t.
The different of Flexscript and C++ is so dramatic here. If I change it to Flexscript, Flexsim almost hang on. I guess here is the case that a DLL could be used.
Here is one interesting but simpler pattern (an ideal water wave) by using the following code:
double t=10*sqrt(time()/100);
double z00=5+cos(y0+t);
double z01=5+cos(y1+t);
double z10=z00;
double z11=z01;
For the polar model, add two lines before draw rectangle to make it more interesting:
double t=10*sqrt(time());
glColor3d(sin(t+x00),cos(t+y00),(sin(t+z00)+cos(t+ z00))/sqrt(2.0));
To view the effects, it is better to comment out the glEnable(GL_LIGHTING) line.
Some questions: What glDisable(2884); and glNormal3D do?
Alex Christensen
06-09-2008, 11:02 AM
First of all, here's an updated bar graph code. Copy it into any OnDraw trigger (especially a visual tool), and it will fully display any global table with a nice picklist option. treenode current = ownerobject(c);
treenode view = parnode(1);
/**draw global table bar graph \n*/
/**table name: */
string tablename=/**/"processtimes"/**/;
/**\nbar width:*/
double barwidth=/**/2/**/;
/**\nbar height:*/
double barheight=/**/2/**/;
int tablenum=getrank(ownerobject(reftable(tablename))) ;
for(int row=1;row<=gettablerows(tablenum);row++){
for(int col=1;col<=gettablecols(tablenum);col++){
double value=gettablenum(tablenum,row,col);
drawcube((col-1)*barwidth/get(spatialsx(current)),//x
-(row-1)*barheight/get(spatialsy(current))+barheight*gettablerows(tab lenum),//y
0.000001, //z
barwidth/get(spatialsx(current)), //sx
barheight/get(spatialsy(current)), //sy
value/10, //sz
0, //rx
0, //ry
0, //rz
0, //red
min(value*11,255), //green
0, //blue
0,0,0); //no texture
}
}glNormal3d sets the normal vector of a polygon (facing straight out of the polygon), which is used in determining the lighting. If this vector is facing a light, the polygon is bright. If this vector is facing perpendicular to a light, the polygon is dark. I calculated the normal vector using a cross product of two vectors along the edges of the polygon. I'm not sure why, but it is calculating it wrong on the first row (when y0=0), so it's shading the first row wrong. Maybe there's a way to do it correctly automatically with an OpenGl command.
GL_CULL_FACE is supposed to be #defined to 2884, but just manually entering its integer value does the same thing as glDisable(GL_CULL_FACE); Back-face culling is an optimization that makes it not draw polygons that are facing away from the camera. It makes it look bad in the Cartesian graph, so I disabled it.
dalin cai
10-06-2011, 01:25 AM
Hi Alex, I need to turn off back face culling, however, either glDisable(GL_CULL_FACE) or glDisable(2884) doesn't work on my machine using Flexsim 5.02.
The glDisable(2884) works.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.