Update fluid tutorial on CubeView and demo code
Format code according to the CMP, add instructions on how to copy the code to the fluid tutorial, and update the tutorial with the current code of test/CubeView.h and test/CubeView.cxx.
This commit is contained in:
parent
cbee4880f4
commit
da4d16b59a
@ -211,187 +211,222 @@ CubeViewUI, generated by FLUID.
|
|||||||
|
|
||||||
Here is the CubeView class definition, as given by its header file
|
Here is the CubeView class definition, as given by its header file
|
||||||
"test/CubeView.h":
|
"test/CubeView.h":
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Code copied from test/CubeView.h -->
|
||||||
\code
|
\code
|
||||||
|
#include <FL/Fl.H>
|
||||||
|
#include <FL/Fl_Gl_Window.H>
|
||||||
|
#include <FL/gl.h>
|
||||||
|
|
||||||
class CubeView : public Fl_Gl_Window {
|
class CubeView : public Fl_Gl_Window {
|
||||||
public:
|
|
||||||
CubeView(int x,int y,int w,int h,const char *l=0);
|
|
||||||
// this value determines the scaling factor used to draw the cube.
|
|
||||||
double size;
|
|
||||||
/* Set the rotation about the vertical (y) axis.
|
|
||||||
*
|
|
||||||
* This function is called by the horizontal roller in CubeViewUI
|
|
||||||
* and the initialize button in CubeViewUI.
|
|
||||||
*/
|
|
||||||
void v_angle(float angle){vAng=angle;};
|
|
||||||
// Return the rotation about the vertical (y) axis.
|
|
||||||
float v_angle(){return vAng;};
|
|
||||||
/* Set the rotation about the horizontal (x) axis.
|
|
||||||
*
|
|
||||||
* This function is called by the vertical roller in CubeViewUI
|
|
||||||
* and the initialize button in CubeViewUI.
|
|
||||||
*/
|
|
||||||
void h_angle(float angle){hAng=angle;};
|
|
||||||
// the rotation about the horizontal (x) axis.
|
|
||||||
float h_angle(){return hAng;};
|
|
||||||
/* Sets the x shift of the cube view camera.
|
|
||||||
*
|
|
||||||
* This function is called by the slider in CubeViewUI and the
|
|
||||||
* initialize button in CubeViewUI.
|
|
||||||
*/
|
|
||||||
void panx(float x){xshift=x;};
|
|
||||||
/* Sets the y shift of the cube view camera.
|
|
||||||
*
|
|
||||||
* This function is called by the slider in CubeViewUI and the
|
|
||||||
* initialize button in CubeViewUI.
|
|
||||||
*/
|
|
||||||
void pany(float y){yshift=y;};
|
|
||||||
/* The widget class draw() override.
|
|
||||||
* The draw() function initialize Gl for another round of
|
|
||||||
* drawing then calls specialized functions for drawing each
|
|
||||||
* of the entities displayed in the cube view.
|
|
||||||
*/
|
|
||||||
void draw();
|
|
||||||
|
|
||||||
private:
|
public:
|
||||||
/* Draw the cube boundaries
|
CubeView(int x, int y, int w, int h, const char *l = 0);
|
||||||
* Draw the faces of the cube using the boxv[] vertices, using
|
|
||||||
* GL_LINE_LOOP for the faces. The color is #defined by
|
|
||||||
* CUBECOLOR.
|
|
||||||
*/
|
|
||||||
void drawCube();
|
|
||||||
|
|
||||||
float vAng,hAng; float xshift,yshift;
|
// This value determines the scaling factor used to draw the cube.
|
||||||
|
double size;
|
||||||
|
|
||||||
float boxv0[3];float boxv1[3]; float boxv2[3];float boxv3[3];
|
/* Set the rotation about the vertical (y) axis.
|
||||||
float boxv4[3];float boxv5[3]; float boxv6[3];float boxv7[3];
|
*
|
||||||
|
* This function is called by the horizontal roller in
|
||||||
|
* CubeViewUI and the initialize button in CubeViewUI.
|
||||||
|
*/
|
||||||
|
void v_angle(double angle) { vAng = angle; }
|
||||||
|
|
||||||
|
// Return the rotation about the vertical (y) axis.
|
||||||
|
double v_angle() const { return vAng; }
|
||||||
|
|
||||||
|
/* Set the rotation about the horizontal (x) axis.
|
||||||
|
*
|
||||||
|
* This function is called by the vertical roller in
|
||||||
|
* CubeViewUI and the initialize button in CubeViewUI.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void h_angle(double angle) { hAng = angle; }
|
||||||
|
|
||||||
|
// The rotation about the horizontal (x) axis.
|
||||||
|
double h_angle() const { return hAng; }
|
||||||
|
|
||||||
|
/* Sets the x shift of the cube view camera.
|
||||||
|
*
|
||||||
|
* This function is called by the slider in CubeViewUI
|
||||||
|
* and the initialize button in CubeViewUI.
|
||||||
|
*/
|
||||||
|
void panx(double x) { xshift = x; }
|
||||||
|
|
||||||
|
/* Sets the y shift of the cube view camera.
|
||||||
|
*
|
||||||
|
* This function is called by the slider in CubeViewUI
|
||||||
|
* and the initialize button in CubeViewUI.
|
||||||
|
*/
|
||||||
|
void pany(double y) { yshift = y; }
|
||||||
|
|
||||||
|
/* The widget class draw() override.
|
||||||
|
*
|
||||||
|
* The draw() function initializes Gl for another round of
|
||||||
|
* drawing, then calls specialized functions for drawing each
|
||||||
|
* of the entities displayed in the cube view.
|
||||||
|
*/
|
||||||
|
void draw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/* Draw the cube boundaries.
|
||||||
|
*
|
||||||
|
* Draw the faces of the cube using the boxv[] vertices,
|
||||||
|
* using GL_LINE_LOOP for the faces.
|
||||||
|
*/
|
||||||
|
void drawCube();
|
||||||
|
|
||||||
|
double vAng, hAng;
|
||||||
|
double xshift, yshift;
|
||||||
|
|
||||||
|
float boxv0[3]; float boxv1[3];
|
||||||
|
float boxv2[3]; float boxv3[3];
|
||||||
|
float boxv4[3]; float boxv5[3];
|
||||||
|
float boxv6[3]; float boxv7[3];
|
||||||
};
|
};
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\par The CubeView Class Implementation
|
\par The CubeView Class Implementation
|
||||||
|
|
||||||
Here is the CubeView implementation. It is very similar to the
|
Here is the CubeView implementation. It is very similar to the
|
||||||
"cube" demo included with FLTK.
|
"CubeView" demo included with FLTK.
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Code copied from test/CubeView.cxx -->
|
||||||
\code
|
\code
|
||||||
#include "CubeView.h"
|
#include "CubeView.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
CubeView::CubeView(int x, int y, int w, int h, const char *l)
|
||||||
: Fl_Gl_Window(x,y,w,h,l)
|
: Fl_Gl_Window(x, y, w, h, l)
|
||||||
{
|
{
|
||||||
vAng = 0.0; hAng=0.0; size=10.0;
|
Fl::use_high_res_GL(1);
|
||||||
/* The cube definition. These are the vertices of a unit cube
|
vAng = 0.0;
|
||||||
* centered on the origin.*/
|
hAng = 0.0;
|
||||||
boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
|
size = 10.0;
|
||||||
boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
|
xshift = 0.0;
|
||||||
boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
|
yshift = 0.0;
|
||||||
boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
|
|
||||||
boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
|
|
||||||
boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
|
|
||||||
boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
|
|
||||||
boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
|
|
||||||
};
|
|
||||||
|
|
||||||
// The color used for the edges of the bounding cube.
|
/* The cube definition. These are the vertices of a unit cube
|
||||||
#define CUBECOLOR 255,255,255,255
|
* centered on the origin.*/
|
||||||
|
|
||||||
|
boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
|
||||||
|
boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
|
||||||
|
boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
|
||||||
|
boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
|
||||||
|
boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
|
||||||
|
boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
|
||||||
|
boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
|
||||||
|
boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
void CubeView::drawCube() {
|
void CubeView::drawCube() {
|
||||||
/* Draw a colored cube */
|
/* Draw a colored cube */
|
||||||
#define ALPHA 0.5
|
#define ALPHA 0.5
|
||||||
glShadeModel(GL_FLAT);
|
glShadeModel(GL_FLAT);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor4f(0.0, 0.0, 1.0, ALPHA);
|
glColor4f(0.0, 0.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glColor4f(1.0, 1.0, 0.0, ALPHA);
|
glColor4f(1.0, 1.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
|
|
||||||
glColor4f(0.0, 1.0, 1.0, ALPHA);
|
glColor4f(0.0, 1.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glColor4f(1.0, 0.0, 0.0, ALPHA);
|
glColor4f(1.0, 0.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
|
|
||||||
glColor4f(1.0, 0.0, 1.0, ALPHA);
|
glColor4f(1.0, 0.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glColor4f(0.0, 1.0, 0.0, ALPHA);
|
glColor4f(0.0, 1.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
|
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
|
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
|
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
|
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
|
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
|
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
|
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
|
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glEnd();
|
glEnd();
|
||||||
};//drawCube
|
} // drawCube
|
||||||
|
|
||||||
void CubeView::draw() {
|
void CubeView::draw() {
|
||||||
if (!valid()) {
|
if (!valid()) {
|
||||||
glLoadIdentity(); glViewport(0,0,w(),h());
|
glLoadIdentity();
|
||||||
glOrtho(-10,10,-10,10,-20000,10000); glEnable(GL_BLEND);
|
glViewport(0, 0, pixel_w(), pixel_h());
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glOrtho(-10, 10, -10, 10, -20050, 10000);
|
||||||
}
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glPushMatrix(); glTranslatef(xshift, yshift, 0);
|
|
||||||
glRotatef(hAng,0,1,0); glRotatef(vAng,1,0,0);
|
glPushMatrix();
|
||||||
glScalef(float(size),float(size),float(size)); drawCube();
|
|
||||||
glPopMatrix();
|
glTranslatef((GLfloat)xshift, (GLfloat)yshift, 0);
|
||||||
};
|
glRotatef((GLfloat)hAng, 0, 1, 0);
|
||||||
|
glRotatef((GLfloat)vAng, 1, 0, 0);
|
||||||
|
glScalef(float(size), float(size), float(size));
|
||||||
|
|
||||||
|
drawCube();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
\subsection fluid_cubeview_ui The CubeViewUI Class
|
\subsection fluid_cubeview_ui The CubeViewUI Class
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// CubeView class implementation for the Fast Light Tool Kit (FLTK).
|
// CubeView class implementation for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
// Copyright 1998-2010 by Bill Spitzak and others.
|
// Copyright 1998-2021 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// This library is free software. Distribution and use rights are outlined in
|
||||||
// the file "COPYING" which should have been included with this file. If this
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@ -14,40 +14,45 @@
|
|||||||
// https://www.fltk.org/bugs.php
|
// https://www.fltk.org/bugs.php
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Note to editor: the following code can and should be copied
|
||||||
|
// to the fluid tutorial in 'documentation/src/fluid.dox'
|
||||||
|
// *without* '#if HAVE_GL' preprocessor statements, leaving
|
||||||
|
// only those parts where the condition is true.
|
||||||
|
|
||||||
|
// [\code in documentation/src/fluid.dox]
|
||||||
#include "CubeView.h"
|
#include "CubeView.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_GL
|
#if HAVE_GL
|
||||||
CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
CubeView::CubeView(int x, int y, int w, int h, const char *l)
|
||||||
: Fl_Gl_Window(x,y,w,h,l)
|
: Fl_Gl_Window(x, y, w, h, l)
|
||||||
#else
|
#else
|
||||||
CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
CubeView::CubeView(int x, int y, int w, int h, const char *l)
|
||||||
: Fl_Box(x,y,w,h,l)
|
: Fl_Box(x, y, w, h, l)
|
||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
{
|
{
|
||||||
Fl::use_high_res_GL(1);
|
Fl::use_high_res_GL(1);
|
||||||
vAng = 0.0;
|
vAng = 0.0;
|
||||||
hAng=0.0;
|
hAng = 0.0;
|
||||||
size=10.0;
|
size = 10.0;
|
||||||
xshift=0.0;
|
xshift = 0.0;
|
||||||
yshift=0.0;
|
yshift = 0.0;
|
||||||
|
|
||||||
/* The cube definition. These are the vertices of a unit cube
|
/* The cube definition. These are the vertices of a unit cube
|
||||||
* centered on the origin.*/
|
* centered on the origin.*/
|
||||||
|
|
||||||
boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
|
boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
|
||||||
boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
|
boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
|
||||||
boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
|
boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
|
||||||
boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
|
boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
|
||||||
boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
|
boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
|
||||||
boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
|
boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
|
||||||
boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
|
boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
|
||||||
boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
|
boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
|
||||||
|
|
||||||
#if !HAVE_GL
|
#if !HAVE_GL
|
||||||
label("OpenGL is required for this demo to operate.");
|
label("OpenGL is required for this demo to operate.");
|
||||||
align(FL_ALIGN_WRAP | FL_ALIGN_INSIDE);
|
align(FL_ALIGN_WRAP | FL_ALIGN_INSIDE);
|
||||||
#endif /* !HAVE_GL */
|
#endif /* !HAVE_GL */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,105 +60,108 @@ CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
|||||||
void CubeView::drawCube() {
|
void CubeView::drawCube() {
|
||||||
/* Draw a colored cube */
|
/* Draw a colored cube */
|
||||||
#define ALPHA 0.5
|
#define ALPHA 0.5
|
||||||
glShadeModel(GL_FLAT);
|
glShadeModel(GL_FLAT);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor4f(0.0, 0.0, 1.0, ALPHA);
|
glColor4f(0.0, 0.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glColor4f(1.0, 1.0, 0.0, ALPHA);
|
glColor4f(1.0, 1.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
|
|
||||||
glColor4f(0.0, 1.0, 1.0, ALPHA);
|
glColor4f(0.0, 1.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glColor4f(1.0, 0.0, 0.0, ALPHA);
|
glColor4f(1.0, 0.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
|
|
||||||
glColor4f(1.0, 0.0, 1.0, ALPHA);
|
glColor4f(1.0, 0.0, 1.0, ALPHA);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glColor4f(0.0, 1.0, 0.0, ALPHA);
|
glColor4f(0.0, 1.0, 0.0, ALPHA);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
|
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
|
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
|
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
|
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
|
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
|
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
|
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glVertex3fv(boxv0);
|
glVertex3fv(boxv0);
|
||||||
glVertex3fv(boxv4);
|
glVertex3fv(boxv4);
|
||||||
|
|
||||||
glVertex3fv(boxv1);
|
glVertex3fv(boxv1);
|
||||||
glVertex3fv(boxv5);
|
glVertex3fv(boxv5);
|
||||||
|
|
||||||
glVertex3fv(boxv2);
|
glVertex3fv(boxv2);
|
||||||
glVertex3fv(boxv6);
|
glVertex3fv(boxv6);
|
||||||
|
|
||||||
glVertex3fv(boxv3);
|
glVertex3fv(boxv3);
|
||||||
glVertex3fv(boxv7);
|
glVertex3fv(boxv7);
|
||||||
glEnd();
|
glEnd();
|
||||||
}//drawCube
|
} // drawCube
|
||||||
|
|
||||||
void CubeView::draw() {
|
void CubeView::draw() {
|
||||||
if (!valid()) {
|
if (!valid()) {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glViewport(0,0,pixel_w(),pixel_h());
|
glViewport(0, 0, pixel_w(), pixel_h());
|
||||||
glOrtho(-10,10,-10,10,-20050,10000);
|
glOrtho(-10, 10, -10, 10, -20050, 10000);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
}
|
}
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
glTranslatef((GLfloat) xshift, (GLfloat) yshift, 0);
|
glTranslatef((GLfloat)xshift, (GLfloat)yshift, 0);
|
||||||
glRotatef((GLfloat) hAng,0,1,0); glRotatef((GLfloat) vAng,1,0,0);
|
glRotatef((GLfloat)hAng, 0, 1, 0);
|
||||||
glScalef(float(size),float(size),float(size));
|
glRotatef((GLfloat)vAng, 1, 0, 0);
|
||||||
|
glScalef(float(size), float(size), float(size));
|
||||||
|
|
||||||
drawCube();
|
drawCube();
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
// [\endcode in documentation/src/fluid.dox]
|
||||||
|
|
||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
|
131
test/CubeView.h
131
test/CubeView.h
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// CubeView class definitions for the Fast Light Tool Kit (FLTK).
|
// CubeView class definitions for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
// Copyright 1998-2010 by Bill Spitzak and others.
|
// Copyright 1998-2021 by Bill Spitzak and others.
|
||||||
//
|
//
|
||||||
// This library is free software. Distribution and use rights are outlined in
|
// This library is free software. Distribution and use rights are outlined in
|
||||||
// the file "COPYING" which should have been included with this file. If this
|
// the file "COPYING" which should have been included with this file. If this
|
||||||
@ -16,17 +16,23 @@
|
|||||||
|
|
||||||
#ifndef CUBEVIEW_H
|
#ifndef CUBEVIEW_H
|
||||||
#define CUBEVIEW_H 1
|
#define CUBEVIEW_H 1
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
// Note to editor: the following code can and should be copied
|
||||||
|
// to the fluid tutorial in 'documentation/src/fluid.dox'
|
||||||
|
// *without* '#if HAVE_GL' preprocessor statements, leaving
|
||||||
|
// only those parts where the condition is true.
|
||||||
|
|
||||||
|
// [\code in documentation/src/fluid.dox]
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#if HAVE_GL
|
#if HAVE_GL
|
||||||
# include <FL/Fl_Gl_Window.H>
|
#include <FL/Fl_Gl_Window.H>
|
||||||
# include <FL/gl.h>
|
#include <FL/gl.h>
|
||||||
#else
|
#else
|
||||||
# include <FL/Fl_Box.H>
|
#include <FL/Fl_Box.H>
|
||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if HAVE_GL
|
#if HAVE_GL
|
||||||
class CubeView : public Fl_Gl_Window {
|
class CubeView : public Fl_Gl_Window {
|
||||||
#else
|
#else
|
||||||
@ -34,76 +40,77 @@ class CubeView : public Fl_Box {
|
|||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// this value determines the scaling factor used to draw the cube.
|
CubeView(int x, int y, int w, int h, const char *l = 0);
|
||||||
double size;
|
|
||||||
|
|
||||||
CubeView(int x,int y,int w,int h,const char *l=0);
|
// This value determines the scaling factor used to draw the cube.
|
||||||
|
double size;
|
||||||
|
|
||||||
/* Set the rotation about the vertical (y ) axis.
|
/* Set the rotation about the vertical (y) axis.
|
||||||
*
|
*
|
||||||
* This function is called by the horizontal roller in CubeViewUI and the
|
* This function is called by the horizontal roller in
|
||||||
* initialize button in CubeViewUI.
|
* CubeViewUI and the initialize button in CubeViewUI.
|
||||||
*/
|
*/
|
||||||
void v_angle(double angle){vAng=angle;}
|
void v_angle(double angle) { vAng = angle; }
|
||||||
|
|
||||||
// Return the rotation about the vertical (y ) axis.
|
// Return the rotation about the vertical (y) axis.
|
||||||
double v_angle() const {return vAng;}
|
double v_angle() const { return vAng; }
|
||||||
|
|
||||||
/* Set the rotation about the horizontal (x ) axis.
|
/* Set the rotation about the horizontal (x) axis.
|
||||||
*
|
*
|
||||||
* This function is called by the vertical roller in CubeViewUI and the
|
* This function is called by the vertical roller in
|
||||||
* initialize button in CubeViewUI.
|
* CubeViewUI and the initialize button in CubeViewUI.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void h_angle(double angle){hAng=angle;}
|
void h_angle(double angle) { hAng = angle; }
|
||||||
|
|
||||||
// the rotation about the horizontal (x ) axis.
|
// The rotation about the horizontal (x) axis.
|
||||||
double h_angle() const {return hAng;}
|
double h_angle() const { return hAng; }
|
||||||
|
|
||||||
/* Sets the x shift of the cube view camera.
|
/* Sets the x shift of the cube view camera.
|
||||||
*
|
*
|
||||||
* This function is called by the slider in CubeViewUI and the
|
* This function is called by the slider in CubeViewUI
|
||||||
* initialize button in CubeViewUI.
|
* and the initialize button in CubeViewUI.
|
||||||
*/
|
*/
|
||||||
void panx(double x){xshift=x;}
|
void panx(double x) { xshift = x; }
|
||||||
/* Sets the y shift of the cube view camera.
|
|
||||||
*
|
/* Sets the y shift of the cube view camera.
|
||||||
* This function is called by the slider in CubeViewUI and the
|
*
|
||||||
* initialize button in CubeViewUI.
|
* This function is called by the slider in CubeViewUI
|
||||||
*/
|
* and the initialize button in CubeViewUI.
|
||||||
void pany(double y){yshift=y;}
|
*/
|
||||||
|
void pany(double y) { yshift = y; }
|
||||||
|
|
||||||
#if HAVE_GL
|
#if HAVE_GL
|
||||||
/*The widget class draw() override.
|
/* The widget class draw() override.
|
||||||
*
|
*
|
||||||
*The draw() function initialize Gl for another round o f drawing
|
* The draw() function initializes Gl for another round of
|
||||||
* then calls specialized functions for drawing each of the
|
* drawing, then calls specialized functions for drawing each
|
||||||
* entities displayed in the cube view.
|
* of the entities displayed in the cube view.
|
||||||
*
|
*/
|
||||||
*/
|
void draw();
|
||||||
void draw();
|
|
||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/* Draw the cube boundaries.
|
||||||
/* Draw the cube boundaries
|
*
|
||||||
*
|
* Draw the faces of the cube using the boxv[] vertices,
|
||||||
*Draw the faces of the cube using the boxv[] vertices, using
|
* using GL_LINE_LOOP for the faces.
|
||||||
* GL_LINE_LOOP for the faces. The color is \#defined by CUBECOLOR.
|
*/
|
||||||
*/
|
|
||||||
#if HAVE_GL
|
#if HAVE_GL
|
||||||
void drawCube();
|
void drawCube();
|
||||||
#else
|
#else
|
||||||
void drawCube() { }
|
void drawCube() {}
|
||||||
#endif /* HAVE_GL */
|
#endif /* HAVE_GL */
|
||||||
|
|
||||||
double vAng,hAng;
|
double vAng, hAng;
|
||||||
double xshift,yshift;
|
double xshift, yshift;
|
||||||
|
|
||||||
|
|
||||||
float boxv0[3];float boxv1[3];
|
|
||||||
float boxv2[3];float boxv3[3];
|
|
||||||
float boxv4[3];float boxv5[3];
|
|
||||||
float boxv6[3];float boxv7[3];
|
|
||||||
|
|
||||||
|
float boxv0[3]; float boxv1[3];
|
||||||
|
float boxv2[3]; float boxv3[3];
|
||||||
|
float boxv4[3]; float boxv5[3];
|
||||||
|
float boxv6[3]; float boxv7[3];
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
// [\endcode in documentation/src/fluid.dox]
|
||||||
|
|
||||||
|
#endif // CUBEVIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user