Skip to content

Commit

Permalink
Port preview to gtkgldrawingare and re-factor / clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Meeks committed Dec 26, 2010
1 parent bbb71a7 commit 52b55e1
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 485 deletions.
3 changes: 1 addition & 2 deletions configure.ac
Expand Up @@ -7,7 +7,6 @@ AC_CONFIG_MACRO_DIR([m4])
dnl AC_CONFIG_AUX_DIR([config])

AM_INIT_AUTOMAKE([1.10 dist-bzip2 no-dist-gzip foreign])
AM_MAINTAINER_MODE

m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])

Expand All @@ -31,7 +30,7 @@ AM_GLIB_GNU_GETTEXT
PKG_PROG_PKG_CONFIG([0.22])

GLIB_GSETTINGS
PKG_CHECK_MODULES(GTK, gtk+-2.0 gobject-2.0 glib-2.0)
PKG_CHECK_MODULES(GTK, gtk+-2.0 gobject-2.0 glib-2.0 gthread-2.0 gtkglextmm-1.2 gdkglextmm-1.2)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

Expand Down
8 changes: 8 additions & 0 deletions libraries/polylib/GeometryBase.h
Expand Up @@ -26,10 +26,18 @@ using namespace vmml;
namespace PolyLib
{
#define PI 3.141592653589793238462643383279502884197169399375105820974944592308
#ifndef sqr
#define sqr(x) ((x)*(x))
#endif
#ifndef MIN
#define MIN(A,B) ((A)<(B)? (A):(B))
#endif
#ifndef MAX
#define MAX(A,B) ((A)>(B)? (A):(B))
#endif
#ifndef ABS
#define ABS(a) (((a) < 0) ? -(a) : (a))
#endif

// dot product (2D) which allows vector operations in arguments
#define dot(u,v) ((u).x * (v).x + (u).y * (v).y)
Expand Down
15 changes: 5 additions & 10 deletions src/Makefile.am
Expand Up @@ -16,22 +16,24 @@ WARNING_FLAGS = -Wall
AM_CPPFLAGS = \
-DHAVE_GTK $(GTK_CFLAGS) -I$(LIB_DIR) \
-I$(LIB_DIR)/vmmlib/include \
-I$(top_srcdir) \
-I/usr/include/boost \
-I/usr/include/lua5.1 \
-I$(LIB_DIR)/polylib \
-g -O0 $(WARNING_FLAGS)

SHARED_SRC=asyncserial.cpp stl.cpp reprapserial.cpp \
processcontroller.cpp printer.cpp modelviewcontroller.cpp \
gllight.cpp gcode.cpp arcball.cpp stdafx.cpp ui.cxx \
gllight.cpp gcode.cpp arcball.cpp stdafx.cpp \
rfo.cpp flu_dnd.cpp flu_pixmaps.cpp flu_simplestring.cpp \
flu_tree_browser.cpp ivcon.cpp file.cpp platform.cpp
flu_tree_browser.cpp ivcon.cpp file.cpp platform.cpp \
ui.cxx view.cxx

SHARED_INC=arcball.h asyncserial.h convert.h flu_dnd.h flu_enumerations.h \
flu_export.h flu_pixmaps.h flu_simplestring.h flu_tree_browser.h \
gcode.h gllight.h ivcon.h miniball.h modelviewcontroller.h \
printer.h processcontroller.h reprapserial.h rfo.h \
stdafx.h stl.h triangle.h ui.h platform.h
stdafx.h stl.h triangle.h platform.h view.h

# TEST_SOURCES=unittest.cpp

Expand All @@ -41,11 +43,4 @@ repsnapper_LDADD = $(GTK_LIBS) -L/usr/lib -lGLU -lGL -lfltk -lfltk_gl \
-lboost_system-mt -lconfig++ \
$(top_builddir)/libraries/polylib/libpolylib.a

BUILT_SOURCES = ui.cxx ui.h

# VERSION=$(shell date +%m.%d.%y)

%.cxx %.h:%.fl
rm -f $@ # fluid doesn't remove on failure.
fluid -c $<

29 changes: 23 additions & 6 deletions src/arcball.cpp
Expand Up @@ -49,7 +49,7 @@ THE SOFTWARE.
//Radius is 1.0f
//Radius squared is 1.0f

void ArcBall_t::_mapToSphere(const Point2fT* NewPt, Vector3fT* NewVec) const
void ArcBall::_mapToSphere(const Point2fT* NewPt, Vector3fT* NewVec) const
{
Point2fT TempPt;
GLfloat length;
Expand Down Expand Up @@ -87,7 +87,7 @@ void ArcBall_t::_mapToSphere(const Point2fT* NewPt, Vector3fT* NewVec) const
}

//Create/Destroy
ArcBall_t::ArcBall_t(GLfloat NewWidth, GLfloat NewHeight)
ArcBall::ArcBall(GLfloat NewWidth, GLfloat NewHeight)
{
//Clear initial values
this->StVec.s.X =
Expand All @@ -103,17 +103,24 @@ ArcBall_t::ArcBall_t(GLfloat NewWidth, GLfloat NewHeight)
}

//Mouse down
void ArcBall_t::click(const Point2fT* NewPt)
void ArcBall::click(GLfloat x, GLfloat y)
{
Point2fT NewPt;
NewPt.T[0] = x;
NewPt.T[1] = y;
//Map the point to the sphere
this->_mapToSphere(NewPt, &this->StVec);
this->_mapToSphere(&NewPt, &this->StVec);
}

//Mouse drag, calculate rotation
void ArcBall_t::drag(const Point2fT* NewPt, Quat4fT* NewRot)
void ArcBall::drag(GLfloat x, GLfloat y, Quat4fT* NewRot)
{
Point2fT NewPt;
NewPt.T[0] = x;
NewPt.T[1] = y;

//Map the point to the sphere
this->_mapToSphere(NewPt, &this->EnVec);
this->_mapToSphere(&NewPt, &this->EnVec);

//Return the quaternion equivalent to the rotation
if (NewRot)
Expand Down Expand Up @@ -144,3 +151,13 @@ void ArcBall_t::drag(const Point2fT* NewPt, Quat4fT* NewRot)
}
}

void ArcBall::dragAccumulate(GLfloat x, GLfloat y, Matrix4fT *transform)
{
Quat4fT tmpQuat;
Matrix3fT tmpRot;

drag(x, y, &tmpQuat);

Matrix3fSetRotationFromQuat4f(&tmpRot, &tmpQuat);
Matrix4fSetRotationFromMatrix3f(transform, &tmpRot);
}
47 changes: 7 additions & 40 deletions src/arcball.h
Expand Up @@ -142,10 +142,6 @@ THE SOFTWARE.
//Custom math, or speed overrides
#define FuncSqrt sqrtf

//utility macros
//assuming IEEE-754(GLfloat), which i believe has max precision of 7 bits
# define Epsilon 1.0e-5

//Math functions

/**
Expand Down Expand Up @@ -289,35 +285,6 @@ THE SOFTWARE.
NewObj->s.XZ = xz - wy; NewObj->s.YZ = yz + wx; NewObj->s.ZZ = 1.0f - (xx + yy);
}

/**
* Sets the value of this matrix to the result of multiplying itself
* with matrix m1.
* @param m1 the other matrix
*/
inline
static void Matrix3fMulMatrix3f(Matrix3fT* NewObj, const Matrix3fT* m1)
{
Matrix3fT Result; //safe not to initialize

assert(NewObj && m1);

// alias-safe way.
Result.s.M00 = (NewObj->s.M00 * m1->s.M00) + (NewObj->s.M01 * m1->s.M10) + (NewObj->s.M02 * m1->s.M20);
Result.s.M01 = (NewObj->s.M00 * m1->s.M01) + (NewObj->s.M01 * m1->s.M11) + (NewObj->s.M02 * m1->s.M21);
Result.s.M02 = (NewObj->s.M00 * m1->s.M02) + (NewObj->s.M01 * m1->s.M12) + (NewObj->s.M02 * m1->s.M22);

Result.s.M10 = (NewObj->s.M10 * m1->s.M00) + (NewObj->s.M11 * m1->s.M10) + (NewObj->s.M12 * m1->s.M20);
Result.s.M11 = (NewObj->s.M10 * m1->s.M01) + (NewObj->s.M11 * m1->s.M11) + (NewObj->s.M12 * m1->s.M21);
Result.s.M12 = (NewObj->s.M10 * m1->s.M02) + (NewObj->s.M11 * m1->s.M12) + (NewObj->s.M12 * m1->s.M22);

Result.s.M20 = (NewObj->s.M20 * m1->s.M00) + (NewObj->s.M21 * m1->s.M10) + (NewObj->s.M22 * m1->s.M20);
Result.s.M21 = (NewObj->s.M20 * m1->s.M01) + (NewObj->s.M21 * m1->s.M11) + (NewObj->s.M22 * m1->s.M21);
Result.s.M22 = (NewObj->s.M20 * m1->s.M02) + (NewObj->s.M21 * m1->s.M12) + (NewObj->s.M22 * m1->s.M22);

//copy result back to this
*NewObj = Result;
}

inline
static void Matrix4fSetRotationScaleFromMatrix4f(Matrix4fT* NewObj, const Matrix4fT* m1)
{
Expand Down Expand Up @@ -461,16 +428,16 @@ THE SOFTWARE.

// 8<--Snip here if you have your own math types/funcs-->8

typedef class ArcBall_t
class ArcBall
{
protected:
inline
void _mapToSphere(const Point2fT* NewPt, Vector3fT* NewVec) const;

public:
//Create/Destroy
ArcBall_t(GLfloat NewWidth, GLfloat NewHeight);
~ArcBall_t() { /* nothing to do */ };
ArcBall(GLfloat NewWidth = 2.0, GLfloat NewHeight = 2.0);
~ArcBall() { /* nothing to do */ };

//Set new bounds
inline
Expand All @@ -484,18 +451,18 @@ THE SOFTWARE.
}

//Mouse down
void click(const Point2fT* NewPt);
void click(GLfloat x, GLfloat y);

//Mouse drag, calculate rotation
void drag(const Point2fT* NewPt, Quat4fT* NewRot);
void drag(GLfloat x, GLfloat y, Quat4fT* NewRot);
void dragAccumulate(GLfloat x, GLfloat y, Matrix4fT *transform);

protected:
Vector3fT StVec; //Saved click vector
Vector3fT EnVec; //Saved drag vector
GLfloat AdjustWidth; //Mouse bounds width
GLfloat AdjustHeight; //Mouse bounds height

} ArcBallT;

};
#endif

26 changes: 0 additions & 26 deletions src/config.h

This file was deleted.

14 changes: 7 additions & 7 deletions src/gllight.cpp
Expand Up @@ -16,6 +16,8 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "stdafx.h"
#include "gllight.h"

gllight::gllight()
Expand All @@ -32,14 +34,12 @@ void gllight::Init(int position)
offset = position;
}

void gllight::On()
void gllight::Enable(bool on)
{
glEnable(offset);
}

void gllight::Off()
{
glDisable(offset);
if (on)
glEnable(offset);
else
glDisable(offset);
}

void gllight::SetAmbient(float r, float g, float b, float a)
Expand Down
14 changes: 8 additions & 6 deletions src/gllight.h
Expand Up @@ -16,18 +16,18 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include "stdafx.h"
#ifndef GL_LIGHT_H
#define GL_LIGHT_H

class gllight
{
public:
gllight();
~gllight();

void Init (int position);
void On();
void Off();

void Enable(bool on);

void SetAmbient(float r, float g, float b, float a);
void SetDiffuse(float r, float g, float b, float a);
void SetLocation(float x, float y, float z, float w);
Expand All @@ -36,3 +36,5 @@ class gllight
private:
int offset;
};

#endif // GL_LIGHT_H

0 comments on commit 52b55e1

Please sign in to comment.