1999-02-23 00:33:55 +03:00
|
|
|
//
|
|
|
|
// CubeView class implementation for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1999-02-23 00:33:55 +03:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1999-02-23 00:33:55 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1999-02-23 00:33:55 +03:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "CubeView.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
1999-03-04 23:26:00 +03:00
|
|
|
#if HAVE_GL
|
1999-02-23 00:33:55 +03:00
|
|
|
CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
|
|
|
: Fl_Gl_Window(x,y,w,h,l)
|
1999-03-04 23:26:00 +03:00
|
|
|
#else
|
|
|
|
CubeView::CubeView(int x,int y,int w,int h,const char *l)
|
|
|
|
: Fl_Box(x,y,w,h,l)
|
|
|
|
#endif /* HAVE_GL */
|
1999-02-23 00:33:55 +03:00
|
|
|
{
|
2018-06-19 19:29:20 +03:00
|
|
|
Fl::use_high_res_GL(1);
|
1999-02-23 00:33:55 +03:00
|
|
|
vAng = 0.0;
|
|
|
|
hAng=0.0;
|
2001-12-21 17:35:34 +03:00
|
|
|
size=10.0;
|
2006-08-17 13:49:43 +04:00
|
|
|
xshift=0.0;
|
|
|
|
yshift=0.0;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
1999-02-23 00:33:55 +03:00
|
|
|
/* The cube definition. These are the vertices of a unit cube
|
|
|
|
* centered on the origin.*/
|
2020-07-01 19:03:10 +03:00
|
|
|
|
1999-02-23 00:33:55 +03:00
|
|
|
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;
|
1999-03-04 23:26:00 +03:00
|
|
|
|
|
|
|
#if !HAVE_GL
|
|
|
|
label("OpenGL is required for this demo to operate.");
|
|
|
|
align(FL_ALIGN_WRAP | FL_ALIGN_INSIDE);
|
|
|
|
#endif /* !HAVE_GL */
|
2001-04-25 17:34:43 +04:00
|
|
|
}
|
1999-02-23 00:33:55 +03:00
|
|
|
|
1999-03-04 23:26:00 +03:00
|
|
|
#if HAVE_GL
|
1999-02-23 00:33:55 +03:00
|
|
|
void CubeView::drawCube() {
|
|
|
|
/* Draw a colored cube */
|
1999-03-10 19:40:19 +03:00
|
|
|
#define ALPHA 0.5
|
|
|
|
glShadeModel(GL_FLAT);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glColor4f(0.0, 0.0, 1.0, ALPHA);
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
|
|
|
|
glColor4f(1.0, 1.0, 0.0, ALPHA);
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
|
|
|
|
glColor4f(0.0, 1.0, 1.0, ALPHA);
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
|
|
|
|
glColor4f(1.0, 0.0, 0.0, ALPHA);
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
|
|
|
|
glColor4f(1.0, 0.0, 1.0, ALPHA);
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
|
|
|
|
glColor4f(0.0, 1.0, 0.0, ALPHA);
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glColor3f(1.0, 1.0, 1.0);
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
|
|
|
|
glVertex3fv(boxv0);
|
|
|
|
glVertex3fv(boxv4);
|
|
|
|
|
|
|
|
glVertex3fv(boxv1);
|
|
|
|
glVertex3fv(boxv5);
|
|
|
|
|
|
|
|
glVertex3fv(boxv2);
|
|
|
|
glVertex3fv(boxv6);
|
|
|
|
|
|
|
|
glVertex3fv(boxv3);
|
|
|
|
glVertex3fv(boxv7);
|
|
|
|
glEnd();
|
2001-04-25 17:34:43 +04:00
|
|
|
}//drawCube
|
1999-02-23 00:33:55 +03:00
|
|
|
|
|
|
|
void CubeView::draw() {
|
|
|
|
if (!valid()) {
|
|
|
|
glLoadIdentity();
|
2018-02-15 10:02:26 +03:00
|
|
|
glViewport(0,0,pixel_w(),pixel_h());
|
2005-02-25 00:55:12 +03:00
|
|
|
glOrtho(-10,10,-10,10,-20050,10000);
|
1999-02-23 00:33:55 +03:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
|
2012-04-05 09:12:30 +04:00
|
|
|
glTranslatef((GLfloat) xshift, (GLfloat) yshift, 0);
|
|
|
|
glRotatef((GLfloat) hAng,0,1,0); glRotatef((GLfloat) vAng,1,0,0);
|
1999-02-23 00:33:55 +03:00
|
|
|
glScalef(float(size),float(size),float(size));
|
|
|
|
|
|
|
|
drawCube();
|
2020-07-01 19:03:10 +03:00
|
|
|
|
1999-02-23 00:33:55 +03:00
|
|
|
glPopMatrix();
|
2001-04-25 17:34:43 +04:00
|
|
|
}
|
1999-03-04 23:26:00 +03:00
|
|
|
#endif /* HAVE_GL */
|