Move libraries to new source directory.
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/source/dtolua/dtolua.dsp Wed Nov 04 00:39:03 2009 +0000
1.3 @@ -0,0 +1,113 @@
1.4 +# Microsoft Developer Studio Project File - Name="dtolua" - Package Owner=<4>
1.5 +# Microsoft Developer Studio Generated Build File, Format Version 6.00
1.6 +# ** DO NOT EDIT **
1.7 +
1.8 +# TARGTYPE "Win32 (x86) Console Application" 0x0103
1.9 +
1.10 +CFG=dtolua - Win32 Debug
1.11 +!MESSAGE This is not a valid makefile. To build this project using NMAKE,
1.12 +!MESSAGE use the Export Makefile command and run
1.13 +!MESSAGE
1.14 +!MESSAGE NMAKE /f "dtolua.mak".
1.15 +!MESSAGE
1.16 +!MESSAGE You can specify a configuration when running NMAKE
1.17 +!MESSAGE by defining the macro CFG on the command line. For example:
1.18 +!MESSAGE
1.19 +!MESSAGE NMAKE /f "dtolua.mak" CFG="dtolua - Win32 Debug"
1.20 +!MESSAGE
1.21 +!MESSAGE Possible choices for configuration are:
1.22 +!MESSAGE
1.23 +!MESSAGE "dtolua - Win32 Release" (based on "Win32 (x86) Console Application")
1.24 +!MESSAGE "dtolua - Win32 Debug" (based on "Win32 (x86) Console Application")
1.25 +!MESSAGE
1.26 +
1.27 +# Begin Project
1.28 +# PROP AllowPerConfigDependencies 0
1.29 +# PROP Scc_ProjName ""
1.30 +# PROP Scc_LocalPath ""
1.31 +CPP=cl.exe
1.32 +RSC=rc.exe
1.33 +
1.34 +!IF "$(CFG)" == "dtolua - Win32 Release"
1.35 +
1.36 +# PROP BASE Use_MFC 0
1.37 +# PROP BASE Use_Debug_Libraries 0
1.38 +# PROP BASE Output_Dir "Release"
1.39 +# PROP BASE Intermediate_Dir "Release"
1.40 +# PROP BASE Target_Dir ""
1.41 +# PROP Use_MFC 0
1.42 +# PROP Use_Debug_Libraries 0
1.43 +# PROP Output_Dir "Release"
1.44 +# PROP Intermediate_Dir "Release"
1.45 +# PROP Target_Dir ""
1.46 +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
1.47 +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\tolua++\include" /I "..\lua\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
1.48 +# ADD BASE RSC /l 0x809 /d "NDEBUG"
1.49 +# ADD RSC /l 0x809 /d "NDEBUG"
1.50 +BSC32=bscmake.exe
1.51 +# ADD BASE BSC32 /nologo
1.52 +# ADD BSC32 /nologo
1.53 +LINK32=link.exe
1.54 +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
1.55 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
1.56 +
1.57 +!ELSEIF "$(CFG)" == "dtolua - Win32 Debug"
1.58 +
1.59 +# PROP BASE Use_MFC 0
1.60 +# PROP BASE Use_Debug_Libraries 1
1.61 +# PROP BASE Output_Dir "Debug"
1.62 +# PROP BASE Intermediate_Dir "Debug"
1.63 +# PROP BASE Target_Dir ""
1.64 +# PROP Use_MFC 0
1.65 +# PROP Use_Debug_Libraries 1
1.66 +# PROP Output_Dir "..\tolua++\bin"
1.67 +# PROP Intermediate_Dir "Debug"
1.68 +# PROP Ignore_Export_Lib 0
1.69 +# PROP Target_Dir ""
1.70 +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
1.71 +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\tolua++\include" /I "..\lua\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
1.72 +# ADD BASE RSC /l 0x809 /d "_DEBUG"
1.73 +# ADD RSC /l 0x809 /d "_DEBUG"
1.74 +BSC32=bscmake.exe
1.75 +# ADD BASE BSC32 /nologo
1.76 +# ADD BSC32 /nologo
1.77 +LINK32=link.exe
1.78 +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
1.79 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
1.80 +
1.81 +!ENDIF
1.82 +
1.83 +# Begin Target
1.84 +
1.85 +# Name "dtolua - Win32 Release"
1.86 +# Name "dtolua - Win32 Debug"
1.87 +# Begin Group "Source Files"
1.88 +
1.89 +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
1.90 +# Begin Source File
1.91 +
1.92 +SOURCE="..\tolua++\src\bin\tolua.c"
1.93 +# End Source File
1.94 +# Begin Source File
1.95 +
1.96 +SOURCE="..\tolua++\src\bin\toluabind.c"
1.97 +# End Source File
1.98 +# Begin Source File
1.99 +
1.100 +SOURCE="..\tolua++\src\bin\toluabind.h"
1.101 +# End Source File
1.102 +# End Group
1.103 +# Begin Group "Header Files"
1.104 +
1.105 +# PROP Default_Filter "h;hpp;hxx;hm;inl"
1.106 +# Begin Source File
1.107 +
1.108 +SOURCE="..\tolua++\include\tolua++.h"
1.109 +# End Source File
1.110 +# End Group
1.111 +# Begin Group "Resource Files"
1.112 +
1.113 +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
1.114 +# End Group
1.115 +# End Target
1.116 +# End Project
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/source/dtolua/dtolua.vcproj Wed Nov 04 00:39:03 2009 +0000
2.3 @@ -0,0 +1,198 @@
2.4 +<?xml version="1.0" encoding="Windows-1252"?>
2.5 +<VisualStudioProject
2.6 + ProjectType="Visual C++"
2.7 + Version="7.10"
2.8 + Name="dtolua"
2.9 + SccProjectName=""
2.10 + SccLocalPath="">
2.11 + <Platforms>
2.12 + <Platform
2.13 + Name="Win32"/>
2.14 + </Platforms>
2.15 + <Configurations>
2.16 + <Configuration
2.17 + Name="Debug|Win32"
2.18 + OutputDirectory=".\..\tolua++\bin"
2.19 + IntermediateDirectory=".\Debug"
2.20 + ConfigurationType="1"
2.21 + UseOfMFC="0"
2.22 + ATLMinimizesCRunTimeLibraryUsage="FALSE"
2.23 + CharacterSet="2">
2.24 + <Tool
2.25 + Name="VCCLCompilerTool"
2.26 + Optimization="0"
2.27 + AdditionalIncludeDirectories="..\tolua++\include,..\lua\include"
2.28 + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
2.29 + BasicRuntimeChecks="3"
2.30 + RuntimeLibrary="5"
2.31 + UsePrecompiledHeader="2"
2.32 + PrecompiledHeaderFile=".\Debug/dtolua.pch"
2.33 + AssemblerListingLocation=".\Debug/"
2.34 + ObjectFile=".\Debug/"
2.35 + ProgramDataBaseFileName=".\Debug/"
2.36 + WarningLevel="3"
2.37 + SuppressStartupBanner="TRUE"
2.38 + DebugInformationFormat="4"
2.39 + CompileAs="0"/>
2.40 + <Tool
2.41 + Name="VCCustomBuildTool"/>
2.42 + <Tool
2.43 + Name="VCLinkerTool"
2.44 + OutputFile=".\..\tolua++\bin/dtolua.exe"
2.45 + LinkIncremental="1"
2.46 + SuppressStartupBanner="TRUE"
2.47 + GenerateDebugInformation="TRUE"
2.48 + ProgramDatabaseFile=".\..\tolua++\bin/dtolua.pdb"
2.49 + SubSystem="1"
2.50 + TargetMachine="1"/>
2.51 + <Tool
2.52 + Name="VCMIDLTool"
2.53 + TypeLibraryName=".\..\tolua++\bin/dtolua.tlb"
2.54 + HeaderFileName=""/>
2.55 + <Tool
2.56 + Name="VCPostBuildEventTool"/>
2.57 + <Tool
2.58 + Name="VCPreBuildEventTool"/>
2.59 + <Tool
2.60 + Name="VCPreLinkEventTool"/>
2.61 + <Tool
2.62 + Name="VCResourceCompilerTool"
2.63 + PreprocessorDefinitions="_DEBUG"
2.64 + Culture="2057"/>
2.65 + <Tool
2.66 + Name="VCWebServiceProxyGeneratorTool"/>
2.67 + <Tool
2.68 + Name="VCXMLDataGeneratorTool"/>
2.69 + <Tool
2.70 + Name="VCWebDeploymentTool"/>
2.71 + <Tool
2.72 + Name="VCManagedWrapperGeneratorTool"/>
2.73 + <Tool
2.74 + Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
2.75 + </Configuration>
2.76 + <Configuration
2.77 + Name="Release|Win32"
2.78 + OutputDirectory=".\Release"
2.79 + IntermediateDirectory=".\Release"
2.80 + ConfigurationType="1"
2.81 + UseOfMFC="0"
2.82 + ATLMinimizesCRunTimeLibraryUsage="FALSE"
2.83 + CharacterSet="2">
2.84 + <Tool
2.85 + Name="VCCLCompilerTool"
2.86 + Optimization="2"
2.87 + InlineFunctionExpansion="1"
2.88 + AdditionalIncludeDirectories="..\tolua++\include,..\lua\include"
2.89 + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
2.90 + StringPooling="TRUE"
2.91 + RuntimeLibrary="4"
2.92 + EnableFunctionLevelLinking="TRUE"
2.93 + UsePrecompiledHeader="2"
2.94 + PrecompiledHeaderFile=".\Release/dtolua.pch"
2.95 + AssemblerListingLocation=".\Release/"
2.96 + ObjectFile=".\Release/"
2.97 + ProgramDataBaseFileName=".\Release/"
2.98 + WarningLevel="3"
2.99 + SuppressStartupBanner="TRUE"
2.100 + CompileAs="0"/>
2.101 + <Tool
2.102 + Name="VCCustomBuildTool"/>
2.103 + <Tool
2.104 + Name="VCLinkerTool"
2.105 + OutputFile=".\Release/dtolua.exe"
2.106 + LinkIncremental="1"
2.107 + SuppressStartupBanner="TRUE"
2.108 + ProgramDatabaseFile=".\Release/dtolua.pdb"
2.109 + SubSystem="1"
2.110 + TargetMachine="1"/>
2.111 + <Tool
2.112 + Name="VCMIDLTool"
2.113 + TypeLibraryName=".\Release/dtolua.tlb"
2.114 + HeaderFileName=""/>
2.115 + <Tool
2.116 + Name="VCPostBuildEventTool"/>
2.117 + <Tool
2.118 + Name="VCPreBuildEventTool"/>
2.119 + <Tool
2.120 + Name="VCPreLinkEventTool"/>
2.121 + <Tool
2.122 + Name="VCResourceCompilerTool"
2.123 + PreprocessorDefinitions="NDEBUG"
2.124 + Culture="2057"/>
2.125 + <Tool
2.126 + Name="VCWebServiceProxyGeneratorTool"/>
2.127 + <Tool
2.128 + Name="VCXMLDataGeneratorTool"/>
2.129 + <Tool
2.130 + Name="VCWebDeploymentTool"/>
2.131 + <Tool
2.132 + Name="VCManagedWrapperGeneratorTool"/>
2.133 + <Tool
2.134 + Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
2.135 + </Configuration>
2.136 + </Configurations>
2.137 + <References>
2.138 + </References>
2.139 + <Files>
2.140 + <Filter
2.141 + Name="Source Files"
2.142 + Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
2.143 + <File
2.144 + RelativePath="..\tolua++\src\bin\tolua.c">
2.145 + <FileConfiguration
2.146 + Name="Debug|Win32">
2.147 + <Tool
2.148 + Name="VCCLCompilerTool"
2.149 + Optimization="0"
2.150 + AdditionalIncludeDirectories=""
2.151 + PreprocessorDefinitions=""
2.152 + BasicRuntimeChecks="3"/>
2.153 + </FileConfiguration>
2.154 + <FileConfiguration
2.155 + Name="Release|Win32">
2.156 + <Tool
2.157 + Name="VCCLCompilerTool"
2.158 + Optimization="2"
2.159 + AdditionalIncludeDirectories=""
2.160 + PreprocessorDefinitions=""/>
2.161 + </FileConfiguration>
2.162 + </File>
2.163 + <File
2.164 + RelativePath="..\tolua++\src\bin\toluabind.c">
2.165 + <FileConfiguration
2.166 + Name="Debug|Win32">
2.167 + <Tool
2.168 + Name="VCCLCompilerTool"
2.169 + Optimization="0"
2.170 + AdditionalIncludeDirectories=""
2.171 + PreprocessorDefinitions=""
2.172 + BasicRuntimeChecks="3"/>
2.173 + </FileConfiguration>
2.174 + <FileConfiguration
2.175 + Name="Release|Win32">
2.176 + <Tool
2.177 + Name="VCCLCompilerTool"
2.178 + Optimization="2"
2.179 + AdditionalIncludeDirectories=""
2.180 + PreprocessorDefinitions=""/>
2.181 + </FileConfiguration>
2.182 + </File>
2.183 + <File
2.184 + RelativePath="..\tolua++\src\bin\toluabind.h">
2.185 + </File>
2.186 + </Filter>
2.187 + <Filter
2.188 + Name="Header Files"
2.189 + Filter="h;hpp;hxx;hm;inl">
2.190 + <File
2.191 + RelativePath="..\tolua++\include\tolua++.h">
2.192 + </File>
2.193 + </Filter>
2.194 + <Filter
2.195 + Name="Resource Files"
2.196 + Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
2.197 + </Filter>
2.198 + </Files>
2.199 + <Globals>
2.200 + </Globals>
2.201 +</VisualStudioProject>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/source/freeglut/!DorisReadme.txt Wed Nov 04 00:39:03 2009 +0000
3.3 @@ -0,0 +1,5 @@
3.4 +
3.5 +The FreeGLUT files go in this directory. You can find them
3.6 +in src/libsrc/freeglut.tgz
3.7 +
3.8 +
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/source/glui/algebra3.cpp Wed Nov 04 00:39:03 2009 +0000
4.3 @@ -0,0 +1,1037 @@
4.4 +/**************************************************************************
4.5 +
4.6 + algebra3.cpp, algebra3.h - C++ Vector and Matrix Algebra routines
4.7 +
4.8 + There are three vector classes and two matrix classes: vec2, vec3,
4.9 + vec4, mat3, and mat4.
4.10 +
4.11 + All the standard arithmetic operations are defined, with '*'
4.12 + for dot product of two vectors and multiplication of two matrices,
4.13 + and '^' for cross product of two vectors.
4.14 +
4.15 + Additional functions include length(), normalize(), homogenize for
4.16 + vectors, and print(), set(), apply() for all classes.
4.17 +
4.18 + There is a function transpose() for matrices, but note that it
4.19 + does not actually change the matrix,
4.20 +
4.21 + When multiplied with a matrix, a vector is treated as a row vector
4.22 + if it precedes the matrix (v*M), and as a column vector if it
4.23 + follows the matrix (M*v).
4.24 +
4.25 + Matrices are stored in row-major form.
4.26 +
4.27 + A vector of one dimension (2d, 3d, or 4d) can be cast to a vector
4.28 + of a higher or lower dimension. If casting to a higher dimension,
4.29 + the new component is set by default to 1.0, unless a value is
4.30 + specified:
4.31 + vec3 a(1.0, 2.0, 3.0 );
4.32 + vec4 b( a, 4.0 ); // now b == {1.0, 2.0, 3.0, 4.0};
4.33 + When casting to a lower dimension, the vector is homogenized in
4.34 + the lower dimension. E.g., if a 4d {X,Y,Z,W} is cast to 3d, the
4.35 + resulting vector is {X/W, Y/W, Z/W}. It is up to the user to
4.36 + insure the fourth component is not zero before casting.
4.37 +
4.38 + There are also the following function for building matrices:
4.39 + identity2D(), translation2D(), rotation2D(),
4.40 + scaling2D(), identity3D(), translation3D(),
4.41 + rotation3D(), rotation3Drad(), scaling3D(),
4.42 + perspective3D()
4.43 +
4.44 +
4.45 + ---------------------------------------------------------------------
4.46 +
4.47 + Author: Jean-Francois DOUEg
4.48 + Revised: Paul Rademacher
4.49 + Version 3.2 - Feb 1998
4.50 +
4.51 +**************************************************************************/
4.52 +
4.53 +#include <math.h>
4.54 +#include "algebra3.h"
4.55 +#include <ctype.h>
4.56 +
4.57 +/****************************************************************
4.58 +* *
4.59 +* vec2 Member functions *
4.60 +* *
4.61 +****************************************************************/
4.62 +
4.63 +/******************** vec2 CONSTRUCTORS ********************/
4.64 +
4.65 +vec2::vec2(void)
4.66 +{n[VX] = n[VY] = 0.0; }
4.67 +
4.68 +vec2::vec2(const float x, const float y)
4.69 +{ n[VX] = x; n[VY] = y; }
4.70 +
4.71 +vec2::vec2(const float d)
4.72 +{ n[VX] = n[VY] = d; }
4.73 +
4.74 +vec2::vec2(const vec2& v)
4.75 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; }
4.76 +
4.77 +vec2::vec2(const vec3& v) // it is up to caller to avoid divide-by-zero
4.78 +{ n[VX] = v.n[VX]/v.n[VZ]; n[VY] = v.n[VY]/v.n[VZ]; };
4.79 +
4.80 +vec2::vec2(const vec3& v, int dropAxis) {
4.81 + switch (dropAxis) {
4.82 + case VX: n[VX] = v.n[VY]; n[VY] = v.n[VZ]; break;
4.83 + case VY: n[VX] = v.n[VX]; n[VY] = v.n[VZ]; break;
4.84 + default: n[VX] = v.n[VX]; n[VY] = v.n[VY]; break;
4.85 + }
4.86 +}
4.87 +
4.88 +
4.89 +/******************** vec2 ASSIGNMENT OPERATORS ******************/
4.90 +
4.91 +vec2& vec2::operator = (const vec2& v)
4.92 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; return *this; }
4.93 +
4.94 +vec2& vec2::operator += ( const vec2& v )
4.95 +{ n[VX] += v.n[VX]; n[VY] += v.n[VY]; return *this; }
4.96 +
4.97 +vec2& vec2::operator -= ( const vec2& v )
4.98 +{ n[VX] -= v.n[VX]; n[VY] -= v.n[VY]; return *this; }
4.99 +
4.100 +vec2& vec2::operator *= ( const float d )
4.101 +{ n[VX] *= d; n[VY] *= d; return *this; }
4.102 +
4.103 +vec2& vec2::operator /= ( const float d )
4.104 +{ float d_inv = 1./d; n[VX] *= d_inv; n[VY] *= d_inv; return *this; }
4.105 +
4.106 +float& vec2::operator [] ( int i) {
4.107 + if (i < VX || i > VY)
4.108 + //VEC_ERROR("vec2 [] operator: illegal access; index = " << i << '\n')
4.109 + VEC_ERROR("vec2 [] operator: illegal access" );
4.110 + return n[i];
4.111 +}
4.112 +
4.113 +
4.114 +/******************** vec2 SPECIAL FUNCTIONS ********************/
4.115 +
4.116 +float vec2::length(void)
4.117 +{ return sqrt(length2()); }
4.118 +
4.119 +float vec2::length2(void)
4.120 +{ return n[VX]*n[VX] + n[VY]*n[VY]; }
4.121 +
4.122 +vec2& vec2::normalize(void) // it is up to caller to avoid divide-by-zero
4.123 +{ *this /= length(); return *this; }
4.124 +
4.125 +vec2& vec2::apply(V_FCT_PTR fct)
4.126 +{ n[VX] = (*fct)(n[VX]); n[VY] = (*fct)(n[VY]); return *this; }
4.127 +
4.128 +void vec2::set( float x, float y )
4.129 +{ n[VX] = x; n[VY] = y; }
4.130 +
4.131 +/******************** vec2 FRIENDS *****************************/
4.132 +
4.133 +vec2 operator - (const vec2& a)
4.134 +{ return vec2(-a.n[VX],-a.n[VY]); }
4.135 +
4.136 +vec2 operator + (const vec2& a, const vec2& b)
4.137 +{ return vec2(a.n[VX]+ b.n[VX], a.n[VY] + b.n[VY]); }
4.138 +
4.139 +vec2 operator - (const vec2& a, const vec2& b)
4.140 +{ return vec2(a.n[VX]-b.n[VX], a.n[VY]-b.n[VY]); }
4.141 +
4.142 +vec2 operator * (const vec2& a, const float d)
4.143 +{ return vec2(d*a.n[VX], d*a.n[VY]); }
4.144 +
4.145 +vec2 operator * (const float d, const vec2& a)
4.146 +{ return a*d; }
4.147 +
4.148 +vec2 operator * (const mat3& a, const vec2& v) {
4.149 + vec3 av;
4.150 +
4.151 + av.n[VX] = a.v[0].n[VX]*v.n[VX] + a.v[0].n[VY]*v.n[VY] + a.v[0].n[VZ];
4.152 + av.n[VY] = a.v[1].n[VX]*v.n[VX] + a.v[1].n[VY]*v.n[VY] + a.v[1].n[VZ];
4.153 + av.n[VZ] = a.v[2].n[VX]*v.n[VX] + a.v[2].n[VY]*v.n[VY] + a.v[2].n[VZ];
4.154 + return av;
4.155 +}
4.156 +
4.157 +vec2 operator * (const vec2& v, mat3& a)
4.158 +{ return a.transpose() * v; }
4.159 +
4.160 +vec3 operator * (const mat3& a, const vec3& v) {
4.161 + vec3 av;
4.162 +
4.163 + av.n[VX] =
4.164 + a.v[0].n[VX]*v.n[VX] + a.v[0].n[VY]*v.n[VY] + a.v[0].n[VZ]*v.n[VZ];
4.165 + av.n[VY] =
4.166 + a.v[1].n[VX]*v.n[VX] + a.v[1].n[VY]*v.n[VY] + a.v[1].n[VZ]*v.n[VZ];
4.167 + av.n[VZ] =
4.168 + a.v[2].n[VX]*v.n[VX] + a.v[2].n[VY]*v.n[VY] + a.v[2].n[VZ]*v.n[VZ];
4.169 + return av;
4.170 +}
4.171 +
4.172 +vec3 operator * (const vec3& v, mat3& a)
4.173 +{ return a.transpose() * v; }
4.174 +
4.175 +float operator * (const vec2& a, const vec2& b)
4.176 +{ return (a.n[VX]*b.n[VX] + a.n[VY]*b.n[VY]); }
4.177 +
4.178 +vec2 operator / (const vec2& a, const float d)
4.179 +{ float d_inv = 1./d; return vec2(a.n[VX]*d_inv, a.n[VY]*d_inv); }
4.180 +
4.181 +vec3 operator ^ (const vec2& a, const vec2& b)
4.182 +{ return vec3(0.0, 0.0, a.n[VX] * b.n[VY] - b.n[VX] * a.n[VY]); }
4.183 +
4.184 +int operator == (const vec2& a, const vec2& b)
4.185 +{ return (a.n[VX] == b.n[VX]) && (a.n[VY] == b.n[VY]); }
4.186 +
4.187 +int operator != (const vec2& a, const vec2& b)
4.188 +{ return !(a == b); }
4.189 +
4.190 +/*ostream& operator << (ostream& s, vec2& v)
4.191 +{ return s << "| " << v.n[VX] << ' ' << v.n[VY] << " |"; }
4.192 +*/
4.193 +
4.194 +/*istream& operator >> (istream& s, vec2& v) {
4.195 + vec2 v_tmp;
4.196 + char c = ' ';
4.197 +
4.198 + while (isspace(c))
4.199 + s >> c;
4.200 + // The vectors can be formatted either as x y or | x y |
4.201 + if (c == '|') {
4.202 + s >> v_tmp[VX] >> v_tmp[VY];
4.203 + while (s >> c && isspace(c)) ;
4.204 + if (c != '|')
4.205 + ;//s.set(_bad);
4.206 + }
4.207 + else {
4.208 + s.putback(c);
4.209 + s >> v_tmp[VX] >> v_tmp[VY];
4.210 + }
4.211 + if (s)
4.212 + v = v_tmp;
4.213 + return s;
4.214 +}
4.215 +*/
4.216 +
4.217 +void swap(vec2& a, vec2& b)
4.218 +{ vec2 tmp(a); a = b; b = tmp; }
4.219 +
4.220 +vec2 min_vec(const vec2& a, const vec2& b)
4.221 +{ return vec2(MIN(a.n[VX], b.n[VX]), MIN(a.n[VY], b.n[VY])); }
4.222 +
4.223 +vec2 max_vec(const vec2& a, const vec2& b)
4.224 +{ return vec2(MAX(a.n[VX], b.n[VX]), MAX(a.n[VY], b.n[VY])); }
4.225 +
4.226 +vec2 prod(const vec2& a, const vec2& b)
4.227 +{ return vec2(a.n[VX] * b.n[VX], a.n[VY] * b.n[VY]); }
4.228 +
4.229 +/****************************************************************
4.230 +* *
4.231 +* vec3 Member functions *
4.232 +* *
4.233 +****************************************************************/
4.234 +
4.235 +// CONSTRUCTORS
4.236 +
4.237 +vec3::vec3(void)
4.238 +{n[VX] = n[VY] = n[VZ] = 0.0;}
4.239 +
4.240 +vec3::vec3(const float x, const float y, const float z)
4.241 +{ n[VX] = x; n[VY] = y; n[VZ] = z; }
4.242 +
4.243 +vec3::vec3(const float d)
4.244 +{ n[VX] = n[VY] = n[VZ] = d; }
4.245 +
4.246 +vec3::vec3(const vec3& v)
4.247 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; }
4.248 +
4.249 +vec3::vec3(const vec2& v)
4.250 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = 1.0; }
4.251 +
4.252 +vec3::vec3(const vec2& v, float d)
4.253 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = d; }
4.254 +
4.255 +vec3::vec3(const vec4& v) // it is up to caller to avoid divide-by-zero
4.256 +{ n[VX] = v.n[VX] / v.n[VW]; n[VY] = v.n[VY] / v.n[VW];
4.257 + n[VZ] = v.n[VZ] / v.n[VW]; }
4.258 +
4.259 +vec3::vec3(const vec4& v, int dropAxis) {
4.260 + switch (dropAxis) {
4.261 + case VX: n[VX] = v.n[VY]; n[VY] = v.n[VZ]; n[VZ] = v.n[VW]; break;
4.262 + case VY: n[VX] = v.n[VX]; n[VY] = v.n[VZ]; n[VZ] = v.n[VW]; break;
4.263 + case VZ: n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VW]; break;
4.264 + default: n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; break;
4.265 + }
4.266 +}
4.267 +
4.268 +
4.269 +// ASSIGNMENT OPERATORS
4.270 +
4.271 +vec3& vec3::operator = (const vec3& v)
4.272 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; return *this; }
4.273 +
4.274 +vec3& vec3::operator += ( const vec3& v )
4.275 +{ n[VX] += v.n[VX]; n[VY] += v.n[VY]; n[VZ] += v.n[VZ]; return *this; }
4.276 +
4.277 +vec3& vec3::operator -= ( const vec3& v )
4.278 +{ n[VX] -= v.n[VX]; n[VY] -= v.n[VY]; n[VZ] -= v.n[VZ]; return *this; }
4.279 +
4.280 +vec3& vec3::operator *= ( const float d )
4.281 +{ n[VX] *= d; n[VY] *= d; n[VZ] *= d; return *this; }
4.282 +
4.283 +vec3& vec3::operator /= ( const float d )
4.284 +{ float d_inv = 1./d; n[VX] *= d_inv; n[VY] *= d_inv; n[VZ] *= d_inv;
4.285 + return *this; }
4.286 +
4.287 +float& vec3::operator [] ( int i) {
4.288 + if (i < VX || i > VZ)
4.289 + //VEC_ERROR("vec3 [] operator: illegal access; index = " << i << '\n')
4.290 + VEC_ERROR("vec3 [] operator: illegal access" );
4.291 +
4.292 + return n[i];
4.293 +}
4.294 +
4.295 +
4.296 +// SPECIAL FUNCTIONS
4.297 +
4.298 +float vec3::length(void)
4.299 +{ return sqrt(length2()); }
4.300 +
4.301 +float vec3::length2(void)
4.302 +{ return n[VX]*n[VX] + n[VY]*n[VY] + n[VZ]*n[VZ]; }
4.303 +
4.304 +vec3& vec3::normalize(void) // it is up to caller to avoid divide-by-zero
4.305 +{ *this /= length(); return *this; }
4.306 +
4.307 +vec3& vec3::homogenize(void) // it is up to caller to avoid divide-by-zero
4.308 +{ n[VX] /= n[VZ]; n[VY] /= n[VZ]; n[VZ] = 1.0; return *this; }
4.309 +
4.310 +vec3& vec3::apply(V_FCT_PTR fct)
4.311 +{ n[VX] = (*fct)(n[VX]); n[VY] = (*fct)(n[VY]); n[VZ] = (*fct)(n[VZ]);
4.312 +return *this; }
4.313 +
4.314 +void vec3::set( float x, float y, float z ) // set vector
4.315 +{ n[VX] = x; n[VY] = y; n[VZ] = z; }
4.316 +
4.317 +void vec3::print( FILE *file, char *name ) // print vector to a file
4.318 +{
4.319 + fprintf( file, "%s: <%f, %f, %f>\n", name, n[VX], n[VY], n[VZ] );
4.320 +}
4.321 +
4.322 +// FRIENDS
4.323 +
4.324 +vec3 operator - (const vec3& a)
4.325 +{ return vec3(-a.n[VX],-a.n[VY],-a.n[VZ]); }
4.326 +
4.327 +vec3 operator + (const vec3& a, const vec3& b)
4.328 +{ return vec3(a.n[VX]+ b.n[VX], a.n[VY] + b.n[VY], a.n[VZ] + b.n[VZ]); }
4.329 +
4.330 +vec3 operator - (const vec3& a, const vec3& b)
4.331 +{ return vec3(a.n[VX]-b.n[VX], a.n[VY]-b.n[VY], a.n[VZ]-b.n[VZ]); }
4.332 +
4.333 +vec3 operator * (const vec3& a, const float d)
4.334 +{ return vec3(d*a.n[VX], d*a.n[VY], d*a.n[VZ]); }
4.335 +
4.336 +vec3 operator * (const float d, const vec3& a)
4.337 +{ return a*d; }
4.338 +
4.339 +vec3 operator * (const mat4& a, const vec3& v)
4.340 +{ return a * vec4(v); }
4.341 +
4.342 +vec3 operator * (const vec3& v, mat4& a)
4.343 +{ return a.transpose() * v; }
4.344 +
4.345 +float operator * (const vec3& a, const vec3& b)
4.346 +{ return (a.n[VX]*b.n[VX] + a.n[VY]*b.n[VY] + a.n[VZ]*b.n[VZ]); }
4.347 +
4.348 +vec3 operator / (const vec3& a, const float d)
4.349 +{ float d_inv = 1./d; return vec3(a.n[VX]*d_inv, a.n[VY]*d_inv,
4.350 + a.n[VZ]*d_inv); }
4.351 +
4.352 +vec3 operator ^ (const vec3& a, const vec3& b) {
4.353 + return vec3(a.n[VY]*b.n[VZ] - a.n[VZ]*b.n[VY],
4.354 + a.n[VZ]*b.n[VX] - a.n[VX]*b.n[VZ],
4.355 + a.n[VX]*b.n[VY] - a.n[VY]*b.n[VX]);
4.356 +}
4.357 +
4.358 +int operator == (const vec3& a, const vec3& b)
4.359 +{ return (a.n[VX] == b.n[VX]) && (a.n[VY] == b.n[VY]) && (a.n[VZ] == b.n[VZ]);
4.360 +}
4.361 +
4.362 +int operator != (const vec3& a, const vec3& b)
4.363 +{ return !(a == b); }
4.364 +
4.365 +/*ostream& operator << (ostream& s, vec3& v)
4.366 +{ return s << "| " << v.n[VX] << ' ' << v.n[VY] << ' ' << v.n[VZ] << " |"; }
4.367 +
4.368 +istream& operator >> (istream& s, vec3& v) {
4.369 + vec3 v_tmp;
4.370 + char c = ' ';
4.371 +
4.372 + while (isspace(c))
4.373 + s >> c;
4.374 + // The vectors can be formatted either as x y z or | x y z |
4.375 + if (c == '|') {
4.376 + s >> v_tmp[VX] >> v_tmp[VY] >> v_tmp[VZ];
4.377 + while (s >> c && isspace(c)) ;
4.378 + if (c != '|')
4.379 + ;//s.set(_bad);
4.380 + }
4.381 + else {
4.382 + s.putback(c);
4.383 + s >> v_tmp[VX] >> v_tmp[VY] >> v_tmp[VZ];
4.384 + }
4.385 + if (s)
4.386 + v = v_tmp;
4.387 + return s;
4.388 +}
4.389 +*/
4.390 +
4.391 +void swap(vec3& a, vec3& b)
4.392 +{ vec3 tmp(a); a = b; b = tmp; }
4.393 +
4.394 +vec3 min_vec(const vec3& a, const vec3& b)
4.395 +{ return vec3(MIN(a.n[VX], b.n[VX]), MIN(a.n[VY], b.n[VY]), MIN(a.n[VZ],
4.396 + b.n[VZ])); }
4.397 +
4.398 +vec3 max_vec(const vec3& a, const vec3& b)
4.399 +{ return vec3(MAX(a.n[VX], b.n[VX]), MAX(a.n[VY], b.n[VY]), MAX(a.n[VZ],
4.400 + b.n[VZ])); }
4.401 +
4.402 +vec3 prod(const vec3& a, const vec3& b)
4.403 +{ return vec3(a.n[VX] * b.n[VX], a.n[VY] * b.n[VY], a.n[VZ] * b.n[VZ]); }
4.404 +
4.405 +/****************************************************************
4.406 +* *
4.407 +* vec4 Member functions *
4.408 +* *
4.409 +****************************************************************/
4.410 +
4.411 +// CONSTRUCTORS
4.412 +
4.413 +vec4::vec4(void)
4.414 +{n[VX] = n[VY] = n[VZ] = 0.0; n[VW] = 1.0; }
4.415 +
4.416 +vec4::vec4(const float x, const float y, const float z, const float w)
4.417 +{ n[VX] = x; n[VY] = y; n[VZ] = z; n[VW] = w; }
4.418 +
4.419 +vec4::vec4(const float d)
4.420 +{ n[VX] = n[VY] = n[VZ] = n[VW] = d; }
4.421 +
4.422 +vec4::vec4(const vec4& v)
4.423 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; n[VW] = v.n[VW]; }
4.424 +
4.425 +vec4::vec4(const vec3& v)
4.426 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; n[VW] = 1.0; }
4.427 +
4.428 +vec4::vec4(const vec3& v, const float d)
4.429 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; n[VW] = d; }
4.430 +
4.431 +
4.432 +// ASSIGNMENT OPERATORS
4.433 +
4.434 +vec4& vec4::operator = (const vec4& v)
4.435 +{ n[VX] = v.n[VX]; n[VY] = v.n[VY]; n[VZ] = v.n[VZ]; n[VW] = v.n[VW];
4.436 +return *this; }
4.437 +
4.438 +vec4& vec4::operator += ( const vec4& v )
4.439 +{ n[VX] += v.n[VX]; n[VY] += v.n[VY]; n[VZ] += v.n[VZ]; n[VW] += v.n[VW];
4.440 +return *this; }
4.441 +
4.442 +vec4& vec4::operator -= ( const vec4& v )
4.443 +{ n[VX] -= v.n[VX]; n[VY] -= v.n[VY]; n[VZ] -= v.n[VZ]; n[VW] -= v.n[VW];
4.444 +return *this; }
4.445 +
4.446 +vec4& vec4::operator *= ( const float d )
4.447 +{ n[VX] *= d; n[VY] *= d; n[VZ] *= d; n[VW] *= d; return *this; }
4.448 +
4.449 +vec4& vec4::operator /= ( const float d )
4.450 +{ float d_inv = 1./d; n[VX] *= d_inv; n[VY] *= d_inv; n[VZ] *= d_inv;
4.451 + n[VW] *= d_inv; return *this; }
4.452 +
4.453 +float& vec4::operator [] ( int i) {
4.454 + if (i < VX || i > VW)
4.455 + //VEC_ERROR("vec4 [] operator: illegal access; index = " << i << '\n')
4.456 + VEC_ERROR("vec4 [] operator: illegal access" );
4.457 +
4.458 + return n[i];
4.459 +}
4.460 +
4.461 +
4.462 +// SPECIAL FUNCTIONS
4.463 +
4.464 +float vec4::length(void)
4.465 +{ return sqrt(length2()); }
4.466 +
4.467 +float vec4::length2(void)
4.468 +{ return n[VX]*n[VX] + n[VY]*n[VY] + n[VZ]*n[VZ] + n[VW]*n[VW]; }
4.469 +
4.470 +vec4& vec4::normalize(void) // it is up to caller to avoid divide-by-zero
4.471 +{ *this /= length(); return *this; }
4.472 +
4.473 +vec4& vec4::homogenize(void) // it is up to caller to avoid divide-by-zero
4.474 +{ n[VX] /= n[VW]; n[VY] /= n[VW]; n[VZ] /= n[VW]; n[VW] = 1.0; return *this; }
4.475 +
4.476 +vec4& vec4::apply(V_FCT_PTR fct)
4.477 +{ n[VX] = (*fct)(n[VX]); n[VY] = (*fct)(n[VY]); n[VZ] = (*fct)(n[VZ]);
4.478 +n[VW] = (*fct)(n[VW]); return *this; }
4.479 +
4.480 +void vec4::print( FILE *file, char *name ) // print vector to a file
4.481 +{
4.482 + fprintf( file, "%s: <%f, %f, %f, %f>\n", name, n[VX], n[VY], n[VZ], n[VW] );
4.483 +}
4.484 +
4.485 +void vec4::set( float x, float y, float z, float a )
4.486 +{
4.487 + n[0] = x; n[1] = y; n[2] = z; n[3] = a;
4.488 +}
4.489 +
4.490 +
4.491 +// FRIENDS
4.492 +
4.493 +vec4 operator - (const vec4& a)
4.494 +{ return vec4(-a.n[VX],-a.n[VY],-a.n[VZ],-a.n[VW]); }
4.495 +
4.496 +vec4 operator + (const vec4& a, const vec4& b)
4.497 +{ return vec4(a.n[VX] + b.n[VX], a.n[VY] + b.n[VY], a.n[VZ] + b.n[VZ],
4.498 + a.n[VW] + b.n[VW]); }
4.499 +
4.500 +vec4 operator - (const vec4& a, const vec4& b)
4.501 +{ return vec4(a.n[VX] - b.n[VX], a.n[VY] - b.n[VY], a.n[VZ] - b.n[VZ],
4.502 + a.n[VW] - b.n[VW]); }
4.503 +
4.504 +vec4 operator * (const vec4& a, const float d)
4.505 +{ return vec4(d*a.n[VX], d*a.n[VY], d*a.n[VZ], d*a.n[VW] ); }
4.506 +
4.507 +vec4 operator * (const float d, const vec4& a)
4.508 +{ return a*d; }
4.509 +
4.510 +vec4 operator * (const mat4& a, const vec4& v) {
4.511 + #define ROWCOL(i) a.v[i].n[0]*v.n[VX] + a.v[i].n[1]*v.n[VY] \
4.512 + + a.v[i].n[2]*v.n[VZ] + a.v[i].n[3]*v.n[VW]
4.513 + return vec4(ROWCOL(0), ROWCOL(1), ROWCOL(2), ROWCOL(3));
4.514 + #undef ROWCOL
4.515 +}
4.516 +
4.517 +vec4 operator * (const vec4& v, mat4& a)
4.518 +{ return a.transpose() * v; }
4.519 +
4.520 +float operator * (const vec4& a, const vec4& b)
4.521 +{ return (a.n[VX]*b.n[VX] + a.n[VY]*b.n[VY] + a.n[VZ]*b.n[VZ] +
4.522 + a.n[VW]*b.n[VW]); }
4.523 +
4.524 +vec4 operator / (const vec4& a, const float d)
4.525 +{ float d_inv = 1./d; return vec4(a.n[VX]*d_inv, a.n[VY]*d_inv, a.n[VZ]*d_inv,
4.526 + a.n[VW]*d_inv); }
4.527 +
4.528 +int operator == (const vec4& a, const vec4& b)
4.529 +{ return (a.n[VX] == b.n[VX]) && (a.n[VY] == b.n[VY]) && (a.n[VZ] == b.n[VZ])
4.530 + && (a.n[VW] == b.n[VW]); }
4.531 +
4.532 +int operator != (const vec4& a, const vec4& b)
4.533 +{ return !(a == b); }
4.534 +
4.535 +/*ostream& operator << (ostream& s, vec4& v)
4.536 +{ return s << "| " << v.n[VX] << ' ' << v.n[VY] << ' ' << v.n[VZ] << ' '
4.537 + << v.n[VW] << " |"; }
4.538 +
4.539 +istream& operator >> (istream& s, vec4& v) {
4.540 + vec4 v_tmp;
4.541 + char c = ' ';
4.542 +
4.543 + while (isspace(c))
4.544 + s >> c;
4.545 + // The vectors can be formatted either as x y z w or | x y z w |
4.546 + if (c == '|') {
4.547 + s >> v_tmp[VX] >> v_tmp[VY] >> v_tmp[VZ] >> v_tmp[VW];
4.548 + while (s >> c && isspace(c)) ;
4.549 + if (c != '|')
4.550 + ;//s.set(_bad);
4.551 + }
4.552 + else {
4.553 + s.putback(c);
4.554 + s >> v_tmp[VX] >> v_tmp[VY] >> v_tmp[VZ] >> v_tmp[VW];
4.555 + }
4.556 + if (s)
4.557 + v = v_tmp;
4.558 + return s;
4.559 +}
4.560 +*/
4.561 +void swap(vec4& a, vec4& b)
4.562 +{ vec4 tmp(a); a = b; b = tmp; }
4.563 +
4.564 +vec4 min_vec(const vec4& a, const vec4& b)
4.565 +{ return vec4(MIN(a.n[VX], b.n[VX]), MIN(a.n[VY], b.n[VY]), MIN(a.n[VZ],
4.566 + b.n[VZ]), MIN(a.n[VW], b.n[VW])); }
4.567 +
4.568 +vec4 max_vec(const vec4& a, const vec4& b)
4.569 +{ return vec4(MAX(a.n[VX], b.n[VX]), MAX(a.n[VY], b.n[VY]), MAX(a.n[VZ],
4.570 + b.n[VZ]), MAX(a.n[VW], b.n[VW])); }
4.571 +
4.572 +vec4 prod(const vec4& a, const vec4& b)
4.573 +{ return vec4(a.n[VX] * b.n[VX], a.n[VY] * b.n[VY], a.n[VZ] * b.n[VZ],
4.574 + a.n[VW] * b.n[VW]); }
4.575 +
4.576 +
4.577 +/****************************************************************
4.578 +* *
4.579 +* mat3 member functions *
4.580 +* *
4.581 +****************************************************************/
4.582 +
4.583 +// CONSTRUCTORS
4.584 +
4.585 +mat3::mat3(void) { *this = identity2D(); }
4.586 +
4.587 +mat3::mat3(const vec3& v0, const vec3& v1, const vec3& v2)
4.588 +{ this->set( v0, v1, v2 ); };
4.589 +
4.590 +mat3::mat3(const float d)
4.591 +{ v[0] = v[1] = v[2] = vec3(d); }
4.592 +
4.593 +mat3::mat3(const mat3& m)
4.594 +{ v[0] = m.v[0]; v[1] = m.v[1]; v[2] = m.v[2]; }
4.595 +
4.596 +
4.597 +// ASSIGNMENT OPERATORS
4.598 +
4.599 +mat3& mat3::operator = ( const mat3& m )
4.600 +{ v[0] = m.v[0]; v[1] = m.v[1]; v[2] = m.v[2]; return *this; }
4.601 +
4.602 +mat3& mat3::operator += ( const mat3& m )
4.603 +{ v[0] += m.v[0]; v[1] += m.v[1]; v[2] += m.v[2]; return *this; }
4.604 +
4.605 +mat3& mat3::operator -= ( const mat3& m )
4.606 +{ v[0] -= m.v[0]; v[1] -= m.v[1]; v[2] -= m.v[2]; return *this; }
4.607 +
4.608 +mat3& mat3::operator *= ( const float d )
4.609 +{ v[0] *= d; v[1] *= d; v[2] *= d; return *this; }
4.610 +
4.611 +mat3& mat3::operator /= ( const float d )
4.612 +{ v[0] /= d; v[1] /= d; v[2] /= d; return *this; }
4.613 +
4.614 +vec3& mat3::operator [] ( int i) {
4.615 + if (i < VX || i > VZ)
4.616 + //VEC_ERROR("mat3 [] operator: illegal access; index = " << i << '\n')
4.617 + VEC_ERROR("mat3 [] operator: illegal access" );
4.618 + return v[i];
4.619 +}
4.620 +
4.621 +void mat3::set( const vec3& v0, const vec3& v1, const vec3& v2 ) {
4.622 + v[0] = v0; v[1] = v1; v[2] = v2;
4.623 +}
4.624 +
4.625 +// SPECIAL FUNCTIONS
4.626 +
4.627 +mat3 mat3::transpose(void) {
4.628 + return mat3(vec3(v[0][0], v[1][0], v[2][0]),
4.629 + vec3(v[0][1], v[1][1], v[2][1]),
4.630 + vec3(v[0][2], v[1][2], v[2][2]));
4.631 +}
4.632 +
4.633 +mat3 mat3::inverse(void) // Gauss-Jordan elimination with partial pivoting
4.634 + {
4.635 + mat3 a(*this), // As a evolves from original mat into identity
4.636 + b(identity2D()); // b evolves from identity into inverse(a)
4.637 + int i, j, i1;
4.638 +
4.639 + // Loop over cols of a from left to right, eliminating above and below diag
4.640 + for (j=0; j<3; j++) { // Find largest pivot in column j among rows j..2
4.641 + i1 = j; // Row with largest pivot candidate
4.642 + for (i=j+1; i<3; i++)
4.643 + if (fabs(a.v[i].n[j]) > fabs(a.v[i1].n[j]))
4.644 + i1 = i;
4.645 +
4.646 + // Swap rows i1 and j in a and b to put pivot on diagonal
4.647 + swap(a.v[i1], a.v[j]);
4.648 + swap(b.v[i1], b.v[j]);
4.649 +
4.650 + // Scale row j to have a unit diagonal
4.651 + if (a.v[j].n[j]==0.)
4.652 + VEC_ERROR("mat3::inverse: singular matrix; can't invert\n");
4.653 + b.v[j] /= a.v[j].n[j];
4.654 + a.v[j] /= a.v[j].n[j];
4.655 +
4.656 + // Eliminate off-diagonal elems in col j of a, doing identical ops to b
4.657 + for (i=0; i<3; i++)
4.658 + if (i!=j) {
4.659 + b.v[i] -= a.v[i].n[j]*b.v[j];
4.660 + a.v[i] -= a.v[i].n[j]*a.v[j];
4.661 + }
4.662 + }
4.663 + return b;
4.664 +}
4.665 +
4.666 +mat3& mat3::apply(V_FCT_PTR fct) {
4.667 + v[VX].apply(fct);
4.668 + v[VY].apply(fct);
4.669 + v[VZ].apply(fct);
4.670 + return *this;
4.671 +}
4.672 +
4.673 +
4.674 +// FRIENDS
4.675 +
4.676 +mat3 operator - (const mat3& a)
4.677 +{ return mat3(-a.v[0], -a.v[1], -a.v[2]); }
4.678 +
4.679 +mat3 operator + (const mat3& a, const mat3& b)
4.680 +{ return mat3(a.v[0] + b.v[0], a.v[1] + b.v[1], a.v[2] + b.v[2]); }
4.681 +
4.682 +mat3 operator - (const mat3& a, const mat3& b)
4.683 +{ return mat3(a.v[0] - b.v[0], a.v[1] - b.v[1], a.v[2] - b.v[2]); }
4.684 +
4.685 +mat3 operator * (mat3& a, mat3& b) {
4.686 + #define ROWCOL(i, j) \
4.687 + a.v[i].n[0]*b.v[0][j] + a.v[i].n[1]*b.v[1][j] + a.v[i].n[2]*b.v[2][j]
4.688 + return mat3(vec3(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2)),
4.689 + vec3(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2)),
4.690 + vec3(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2)));
4.691 + #undef ROWCOL
4.692 +}
4.693 +
4.694 +mat3 operator * (const mat3& a, const float d)
4.695 +{ return mat3(a.v[0] * d, a.v[1] * d, a.v[2] * d); }
4.696 +
4.697 +mat3 operator * (const float d, const mat3& a)
4.698 +{ return a*d; }
4.699 +
4.700 +mat3 operator / (const mat3& a, const float d)
4.701 +{ return mat3(a.v[0] / d, a.v[1] / d, a.v[2] / d); }
4.702 +
4.703 +int operator == (const mat3& a, const mat3& b)
4.704 +{ return (a.v[0] == b.v[0]) && (a.v[1] == b.v[1]) && (a.v[2] == b.v[2]); }
4.705 +
4.706 +int operator != (const mat3& a, const mat3& b)
4.707 +{ return !(a == b); }
4.708 +
4.709 +/*ostream& operator << (ostream& s, mat3& m)
4.710 +{ return s << m.v[VX] << '\n' << m.v[VY] << '\n' << m.v[VZ]; }
4.711 +
4.712 +istream& operator >> (istream& s, mat3& m) {
4.713 + mat3 m_tmp;
4.714 +
4.715 + s >> m_tmp[VX] >> m_tmp[VY] >> m_tmp[VZ];
4.716 + if (s)
4.717 + m = m_tmp;
4.718 + return s;
4.719 +}
4.720 +*/
4.721 +
4.722 +void swap(mat3& a, mat3& b)
4.723 +{ mat3 tmp(a); a = b; b = tmp; }
4.724 +
4.725 +void mat3::print( FILE *file, char *name )
4.726 +{
4.727 + int i, j;
4.728 +
4.729 + fprintf( stderr, "%s:\n", name );
4.730 +
4.731 + for( i = 0; i < 3; i++ )
4.732 + {
4.733 + fprintf( stderr, " " );
4.734 + for( j = 0; j < 3; j++ )
4.735 + {
4.736 + fprintf( stderr, "%f ", v[i][j] );
4.737 + }
4.738 + fprintf( stderr, "\n" );
4.739 + }
4.740 +}
4.741 +
4.742 +
4.743 +
4.744 +/****************************************************************
4.745 +* *
4.746 +* mat4 member functions *
4.747 +* *
4.748 +****************************************************************/
4.749 +
4.750 +// CONSTRUCTORS
4.751 +
4.752 +mat4::mat4(void) { *this = identity3D();}
4.753 +
4.754 +mat4::mat4(const vec4& v0, const vec4& v1, const vec4& v2, const vec4& v3)
4.755 +{ v[0] = v0; v[1] = v1; v[2] = v2; v[3] = v3; }
4.756 +
4.757 +mat4::mat4(const float d)
4.758 +{ v[0] = v[1] = v[2] = v[3] = vec4(d); }
4.759 +
4.760 +mat4::mat4(const mat4& m)
4.761 +{ v[0] = m.v[0]; v[1] = m.v[1]; v[2] = m.v[2]; v[3] = m.v[3]; }
4.762 +
4.763 +mat4::mat4(const float a00, const float a01, const float a02, const float a03,
4.764 + const float a10, const float a11, const float a12, const float a13,
4.765 + const float a20, const float a21, const float a22, const float a23,
4.766 + const float a30, const float a31, const float a32, const float a33 )
4.767 +{
4.768 + v[0][0] = a00; v[0][1] = a01; v[0][2] = a02; v[0][3] = a03;
4.769 + v[1][0] = a10; v[1][1] = a11; v[1][2] = a12; v[1][3] = a13;
4.770 + v[2][0] = a20; v[2][1] = a21; v[2][2] = a22; v[2][3] = a23;
4.771 + v[3][0] = a30; v[3][1] = a31; v[3][2] = a32; v[3][3] = a33;
4.772 +}
4.773 +
4.774 +// ASSIGNMENT OPERATORS
4.775 +
4.776 +mat4& mat4::operator = ( const mat4& m )
4.777 +{ v[0] = m.v[0]; v[1] = m.v[1]; v[2] = m.v[2]; v[3] = m.v[3];
4.778 +return *this; }
4.779 +
4.780 +mat4& mat4::operator += ( const mat4& m )
4.781 +{ v[0] += m.v[0]; v[1] += m.v[1]; v[2] += m.v[2]; v[3] += m.v[3];
4.782 +return *this; }
4.783 +
4.784 +mat4& mat4::operator -= ( const mat4& m )
4.785 +{ v[0] -= m.v[0]; v[1] -= m.v[1]; v[2] -= m.v[2]; v[3] -= m.v[3];
4.786 +return *this; }
4.787 +
4.788 +mat4& mat4::operator *= ( const float d )
4.789 +{ v[0] *= d; v[1] *= d; v[2] *= d; v[3] *= d; return *this; }
4.790 +
4.791 +mat4& mat4::operator /= ( const float d )
4.792 +{ v[0] /= d; v[1] /= d; v[2] /= d; v[3] /= d; return *this; }
4.793 +
4.794 +vec4& mat4::operator [] ( int i) {
4.795 + if (i < VX || i > VW)
4.796 + //VEC_ERROR("mat4 [] operator: illegal access; index = " << i << '\n')
4.797 + VEC_ERROR("mat4 [] operator: illegal access" );
4.798 + return v[i];
4.799 +}
4.800 +
4.801 +// SPECIAL FUNCTIONS;
4.802 +
4.803 +mat4 mat4::transpose(void) {
4.804 + return mat4(vec4(v[0][0], v[1][0], v[2][0], v[3][0]),
4.805 + vec4(v[0][1], v[1][1], v[2][1], v[3][1]),
4.806 + vec4(v[0][2], v[1][2], v[2][2], v[3][2]),
4.807 + vec4(v[0][3], v[1][3], v[2][3], v[3][3]));
4.808 +}
4.809 +
4.810 +mat4 mat4::inverse(void) // Gauss-Jordan elimination with partial pivoting
4.811 +{
4.812 + mat4 a(*this), // As a evolves from original mat into identity
4.813 + b(identity3D()); // b evolves from identity into inverse(a)
4.814 + int i, j, i1;
4.815 +
4.816 + // Loop over cols of a from left to right, eliminating above and below diag
4.817 + for (j=0; j<4; j++) { // Find largest pivot in column j among rows j..3
4.818 + i1 = j; // Row with largest pivot candidate
4.819 + for (i=j+1; i<4; i++)
4.820 + if (fabs(a.v[i].n[j]) > fabs(a.v[i1].n[j]))
4.821 + i1 = i;
4.822 +
4.823 + // Swap rows i1 and j in a and b to put pivot on diagonal
4.824 + swap(a.v[i1], a.v[j]);
4.825 + swap(b.v[i1], b.v[j]);
4.826 +
4.827 + // Scale row j to have a unit diagonal
4.828 + if (a.v[j].n[j]==0.)
4.829 + VEC_ERROR("mat4::inverse: singular matrix; can't invert\n");
4.830 + b.v[j] /= a.v[j].n[j];
4.831 + a.v[j] /= a.v[j].n[j];
4.832 +
4.833 + // Eliminate off-diagonal elems in col j of a, doing identical ops to b
4.834 + for (i=0; i<4; i++)
4.835 + if (i!=j) {
4.836 + b.v[i] -= a.v[i].n[j]*b.v[j];
4.837 + a.v[i] -= a.v[i].n[j]*a.v[j];
4.838 + }
4.839 + }
4.840 + return b;
4.841 +}
4.842 +
4.843 +mat4& mat4::apply(V_FCT_PTR fct)
4.844 +{ v[VX].apply(fct); v[VY].apply(fct); v[VZ].apply(fct); v[VW].apply(fct);
4.845 +return *this; }
4.846 +
4.847 +
4.848 +void mat4::print( FILE *file, char *name )
4.849 +{
4.850 + int i, j;
4.851 +
4.852 + fprintf( stderr, "%s:\n", name );
4.853 +
4.854 + for( i = 0; i < 4; i++ )
4.855 + {
4.856 + fprintf( stderr, " " );
4.857 + for( j = 0; j < 4; j++ )
4.858 + {
4.859 + fprintf( stderr, "%f ", v[i][j] );
4.860 + }
4.861 + fprintf( stderr, "\n" );
4.862 + }
4.863 +}
4.864 +
4.865 +void mat4::swap_rows( int i, int j )
4.866 +{
4.867 + vec4 t;
4.868 +
4.869 + t = v[i];
4.870 + v[i] = v[j];
4.871 + v[j] = t;
4.872 +}
4.873 +
4.874 +void mat4::swap_cols( int i, int j )
4.875 +{
4.876 + float t;
4.877 + int k;
4.878 +
4.879 + for(k=0; k<4; k++ ) {
4.880 + t = v[k][i];
4.881 + v[k][i] = v[k][j];
4.882 + v[k][j] = t;
4.883 + }
4.884 +}
4.885 +
4.886 +
4.887 +// FRIENDS
4.888 +
4.889 +mat4 operator - (const mat4& a)
4.890 +{ return mat4(-a.v[0], -a.v[1], -a.v[2], -a.v[3]); }
4.891 +
4.892 +mat4 operator + (const mat4& a, const mat4& b)
4.893 +{ return mat4(a.v[0] + b.v[0], a.v[1] + b.v[1], a.v[2] + b.v[2],
4.894 + a.v[3] + b.v[3]);
4.895 +}
4.896 +
4.897 +mat4 operator - (const mat4& a, const mat4& b)
4.898 +{ return mat4(a.v[0] - b.v[0], a.v[1] - b.v[1], a.v[2] - b.v[2], a.v[3] - b.v[3]); }
4.899 +
4.900 +mat4 operator * (mat4& a, mat4& b) {
4.901 + #define ROWCOL(i, j) a.v[i].n[0]*b.v[0][j] + a.v[i].n[1]*b.v[1][j] + \
4.902 + a.v[i].n[2]*b.v[2][j] + a.v[i].n[3]*b.v[3][j]
4.903 + return mat4(
4.904 + vec4(ROWCOL(0,0), ROWCOL(0,1), ROWCOL(0,2), ROWCOL(0,3)),
4.905 + vec4(ROWCOL(1,0), ROWCOL(1,1), ROWCOL(1,2), ROWCOL(1,3)),
4.906 + vec4(ROWCOL(2,0), ROWCOL(2,1), ROWCOL(2,2), ROWCOL(2,3)),
4.907 + vec4(ROWCOL(3,0), ROWCOL(3,1), ROWCOL(3,2), ROWCOL(3,3))
4.908 + );
4.909 +}
4.910 +
4.911 +mat4 operator * (const mat4& a, const float d)
4.912 +{ return mat4(a.v[0] * d, a.v[1] * d, a.v[2] * d, a.v[3] * d); }
4.913 +
4.914 +mat4 operator * (const float d, const mat4& a)
4.915 +{ return a*d; }
4.916 +
4.917 +mat4 operator / (const mat4& a, const float d)
4.918 +{ return mat4(a.v[0] / d, a.v[1] / d, a.v[2] / d, a.v[3] / d); }
4.919 +
4.920 +int operator == (const mat4& a, const mat4& b)
4.921 +{ return ((a.v[0] == b.v[0]) && (a.v[1] == b.v[1]) && (a.v[2] == b.v[2]) &&
4.922 + (a.v[3] == b.v[3])); }
4.923 +
4.924 +int operator != (const mat4& a, const mat4& b)
4.925 +{ return !(a == b); }
4.926 +
4.927 +/*ostream& operator << (ostream& s, mat4& m)
4.928 +{ return s << m.v[VX] << '\n' << m.v[VY] << '\n' << m.v[VZ] << '\n' << m.v[VW]; }
4.929 +
4.930 +istream& operator >> (istream& s, mat4& m)
4.931 +{
4.932 + mat4 m_tmp;
4.933 +
4.934 + s >> m_tmp[VX] >> m_tmp[VY] >> m_tmp[VZ] >> m_tmp[VW];
4.935 + if (s)
4.936 + m = m_tmp;
4.937 + return s;
4.938 +}
4.939 +*/
4.940 +void swap(mat4& a, mat4& b)
4.941 +{ mat4 tmp(a); a = b; b = tmp; }
4.942 +
4.943 +
4.944 +/****************************************************************
4.945 +* *
4.946 +* 2D functions and 3D functions *
4.947 +* *
4.948 +****************************************************************/
4.949 +
4.950 +mat3 identity2D(void)
4.951 +{ return mat3(vec3(1.0, 0.0, 0.0),
4.952 + vec3(0.0, 1.0, 0.0),
4.953 + vec3(0.0, 0.0, 1.0)); }
4.954 +
4.955 +mat3 translation2D(vec2& v)
4.956 +{ return mat3(vec3(1.0, 0.0, v[VX]),
4.957 + vec3(0.0, 1.0, v[VY]),
4.958 + vec3(0.0, 0.0, 1.0)); }
4.959 +
4.960 +mat3 rotation2D(vec2& Center, const float angleDeg) {
4.961 + float angleRad = angleDeg * M_PI / 180.0,
4.962 + c = cos(angleRad),
4.963 + s = sin(angleRad);
4.964 +
4.965 + return mat3(vec3(c, -s, Center[VX] * (1.0-c) + Center[VY] * s),
4.966 + vec3(s, c, Center[VY] * (1.0-c) - Center[VX] * s),
4.967 + vec3(0.0, 0.0, 1.0));
4.968 +}
4.969 +
4.970 +mat3 scaling2D(vec2& scaleVector)
4.971 +{ return mat3(vec3(scaleVector[VX], 0.0, 0.0),
4.972 + vec3(0.0, scaleVector[VY], 0.0),
4.973 + vec3(0.0, 0.0, 1.0)); }
4.974 +
4.975 +mat4 identity3D(void)
4.976 +{ return mat4(vec4(1.0, 0.0, 0.0, 0.0),
4.977 + vec4(0.0, 1.0, 0.0, 0.0),
4.978 + vec4(0.0, 0.0, 1.0, 0.0),
4.979 + vec4(0.0, 0.0, 0.0, 1.0)); }
4.980 +
4.981 +mat4 translation3D(vec3& v)
4.982 +{ return mat4(vec4(1.0, 0.0, 0.0, v[VX]),
4.983 + vec4(0.0, 1.0, 0.0, v[VY]),
4.984 + vec4(0.0, 0.0, 1.0, v[VZ]),
4.985 + vec4(0.0, 0.0, 0.0, 1.0)); }
4.986 +
4.987 +mat4 rotation3D(vec3& Axis, const float angleDeg) {
4.988 + float angleRad = angleDeg * M_PI / 180.0,
4.989 + c = cos(angleRad),
4.990 + s = sin(angleRad),
4.991 + t = 1.0 - c;
4.992 +
4.993 + Axis.normalize();
4.994 + return mat4(vec4(t * Axis[VX] * Axis[VX] + c,
4.995 + t * Axis[VX] * Axis[VY] - s * Axis[VZ],
4.996 + t * Axis[VX] * Axis[VZ] + s * Axis[VY],
4.997 + 0.0),
4.998 + vec4(t * Axis[VX] * Axis[VY] + s * Axis[VZ],
4.999 + t * Axis[VY] * Axis[VY] + c,
4.1000 + t * Axis[VY] * Axis[VZ] - s * Axis[VX],
4.1001 + 0.0),
4.1002 + vec4(t * Axis[VX] * Axis[VZ] - s * Axis[VY],
4.1003 + t * Axis[VY] * Axis[VZ] + s * Axis[VX],
4.1004 + t * Axis[VZ] * Axis[VZ] + c,
4.1005 + 0.0),
4.1006 + vec4(0.0, 0.0, 0.0, 1.0));
4.1007 +}
4.1008 +
4.1009 +mat4 rotation3Drad(vec3& Axis, const float angleRad) {
4.1010 + float c = cos(angleRad),
4.1011 + s = sin(angleRad),
4.1012 + t = 1.0 - c;
4.1013 +
4.1014 + Axis.normalize();
4.1015 + return mat4(vec4(t * Axis[VX] * Axis[VX] + c,
4.1016 + t * Axis[VX] * Axis[VY] - s * Axis[VZ],
4.1017 + t * Axis[VX] * Axis[VZ] + s * Axis[VY],
4.1018 + 0.0),
4.1019 + vec4(t * Axis[VX] * Axis[VY] + s * Axis[VZ],
4.1020 + t * Axis[VY] * Axis[VY] + c,
4.1021 + t * Axis[VY] * Axis[VZ] - s * Axis[VX],
4.1022 + 0.0),
4.1023 + vec4(t * Axis[VX] * Axis[VZ] - s * Axis[VY],
4.1024 + t * Axis[VY] * Axis[VZ] + s * Axis[VX],
4.1025 + t * Axis[VZ] * Axis[VZ] + c,
4.1026 + 0.0),
4.1027 + vec4(0.0, 0.0, 0.0, 1.0));
4.1028 +}
4.1029 +
4.1030 +mat4 scaling3D(vec3& scaleVector)
4.1031 +{ return mat4(vec4(scaleVector[VX], 0.0, 0.0, 0.0),
4.1032 + vec4(0.0, scaleVector[VY], 0.0, 0.0),
4.1033 + vec4(0.0, 0.0, scaleVector[VZ], 0.0),
4.1034 + vec4(0.0, 0.0, 0.0, 1.0)); }
4.1035 +
4.1036 +mat4 perspective3D(const float d)
4.1037 +{ return mat4(vec4(1.0, 0.0, 0.0, 0.0),
4.1038 + vec4(0.0, 1.0, 0.0, 0.0),
4.1039 + vec4(0.0, 0.0, 1.0, 0.0),
4.1040 + vec4(0.0, 0.0, 1.0/d, 0.0)); }
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/source/glui/algebra3.h Wed Nov 04 00:39:03 2009 +0000
5.3 @@ -0,0 +1,474 @@
5.4 +/**************************************************************************
5.5 +
5.6 + algebra3.cpp, algebra3.h - C++ Vector and Matrix Algebra routines
5.7 +
5.8 + There are three vector classes and two matrix classes: vec2, vec3,
5.9 + vec4, mat3, and mat4.
5.10 +
5.11 + All the standard arithmetic operations are defined, with '*'
5.12 + for dot product of two vectors and multiplication of two matrices,
5.13 + and '^' for cross product of two vectors.
5.14 +
5.15 + Additional functions include length(), normalize(), homogenize for
5.16 + vectors, and print(), set(), apply() for all classes.
5.17 +
5.18 + There is a function transpose() for matrices, but note that it
5.19 + does not actually change the matrix,
5.20 +
5.21 + When multiplied with a matrix, a vector is treated as a row vector
5.22 + if it precedes the matrix (v*M), and as a column vector if it
5.23 + follows the matrix (M*v).
5.24 +
5.25 + Matrices are stored in row-major form.
5.26 +
5.27 + A vector of one dimension (2d, 3d, or 4d) can be cast to a vector
5.28 + of a higher or lower dimension. If casting to a higher dimension,
5.29 + the new component is set by default to 1.0, unless a value is
5.30 + specified:
5.31 + vec3 a(1.0, 2.0, 3.0 );
5.32 + vec4 b( a, 4.0 ); // now b == {1.0, 2.0, 3.0, 4.0};
5.33 + When casting to a lower dimension, the vector is homogenized in
5.34 + the lower dimension. E.g., if a 4d {X,Y,Z,W} is cast to 3d, the
5.35 + resulting vector is {X/W, Y/W, Z/W}. It is up to the user to
5.36 + insure the fourth component is not zero before casting.
5.37 +
5.38 + There are also the following function for building matrices:
5.39 + identity2D(), translation2D(), rotation2D(),
5.40 + scaling2D(), identity3D(), translation3D(),
5.41 + rotation3D(), rotation3Drad(), scaling3D(),
5.42 + perspective3D()
5.43 +
5.44 + NOTE: When compiling for Windows, include this file first, to avoid
5.45 + certain name conflicts
5.46 +
5.47 + ---------------------------------------------------------------------
5.48 +
5.49 + Author: Jean-Francois DOUEg
5.50 + Revised: Paul Rademacher
5.51 + Version 3.2 - Feb 1998
5.52 +
5.53 +**************************************************************************/
5.54 +
5.55 +#ifndef _ALGEBRA3_H_
5.56 +#define _ALGEBRA3_H_
5.57 +
5.58 +#include <math.h>
5.59 +#include <stdio.h>
5.60 +#include <stdlib.h>
5.61 +
5.62 +// this line defines a new type: pointer to a function which returns a
5.63 +// float and takes as argument a float
5.64 +typedef float (*V_FCT_PTR)(float);
5.65 +
5.66 +// min-max macros
5.67 +#ifndef MIN
5.68 +#define MIN(A,B) ((A) < (B) ? (A) : (B))
5.69 +#define MAX(A,B) ((A) > (B) ? (A) : (B))
5.70 +#endif
5.71 +
5.72 +//#include <stream.h>
5.73 +// error handling macro
5.74 +//#define VEC_ERROR(E) { cerr << E; exit(1); }
5.75 +/*#define <<
5.76 +#define >>*/
5.77 +
5.78 +#ifdef VEC_ERROR_FATAL
5.79 +#ifndef VEC_ERROR
5.80 +#define VEC_ERROR(E) { printf( "VERROR %s\n", E ); exit(1); }
5.81 +#endif
5.82 +#else
5.83 +#ifndef VEC_ERROR
5.84 +#define VEC_ERROR(E) { printf( "VERROR %s\n", E ); }
5.85 +#endif
5.86 +#endif
5.87 +
5.88 +class vec2;
5.89 +class vec3;
5.90 +class vec4;
5.91 +class mat3;
5.92 +class mat4;
5.93 +
5.94 +/*#ifndef X
5.95 +enum {X,Y,Z,W};
5.96 +#endif
5.97 +*/
5.98 +
5.99 +/*#ifndef R
5.100 +enum {R,G,B,ALPHA};
5.101 +#endif
5.102 +*/
5.103 +
5.104 +#ifndef M_PI
5.105 +#define M_PI 3.141592654
5.106 +#endif
5.107 +
5.108 +
5.109 +enum {VX, VY, VZ, VW}; // axes
5.110 +enum {PA, PB, PC, PD}; // planes
5.111 +enum {RED, GREEN, BLUE, ALPHA}; // colors
5.112 +enum {KA, KD, KS, ES}; // phong coefficients
5.113 +
5.114 +/****************************************************************
5.115 +* *
5.116 +* 2D Vector *
5.117 +* *
5.118 +****************************************************************/
5.119 +
5.120 +class vec2
5.121 +{
5.122 +protected:
5.123 +
5.124 + float n[2];
5.125 +
5.126 +public:
5.127 +
5.128 + // Constructors
5.129 +
5.130 + vec2(void);
5.131 + vec2(const float x, const float y);
5.132 + vec2(const float d);
5.133 + vec2(const vec2& v); // copy constructor
5.134 + vec2(const vec3& v); // cast v3 to v2
5.135 + vec2(const vec3& v, int dropAxis); // cast v3 to v2
5.136 +
5.137 + // Assignment operators
5.138 +
5.139 + vec2& operator = ( const vec2& v ); // assignment of a vec2
5.140 + vec2& operator += ( const vec2& v ); // incrementation by a vec2
5.141 + vec2& operator -= ( const vec2& v ); // decrementation by a vec2
5.142 + vec2& operator *= ( const float d ); // multiplication by a constant
5.143 + vec2& operator /= ( const float d ); // division by a constant
5.144 + float& operator [] ( int i); // indexing
5.145 +
5.146 + // special functions
5.147 +
5.148 + float length(void); // length of a vec2
5.149 + float length2(void); // squared length of a vec2
5.150 + vec2& normalize(void); // normalize a vec2
5.151 + vec2& apply(V_FCT_PTR fct); // apply a func. to each component
5.152 + void set( float x, float y ); // set vector
5.153 +
5.154 + // friends
5.155 +
5.156 + friend vec2 operator - (const vec2& v); // -v1
5.157 + friend vec2 operator + (const vec2& a, const vec2& b); // v1 + v2
5.158 + friend vec2 operator - (const vec2& a, const vec2& b); // v1 - v2
5.159 + friend vec2 operator * (const vec2& a, const float d); // v1 * 3.0
5.160 + friend vec2 operator * (const float d, const vec2& a); // 3.0 * v1
5.161 + friend vec2 operator * (const mat3& a, const vec2& v); // M . v
5.162 + friend vec2 operator * (const vec2& v, mat3& a); // v . M
5.163 + friend float operator * (const vec2& a, const vec2& b); // dot product
5.164 + friend vec2 operator / (const vec2& a, const float d); // v1 / 3.0
5.165 + friend vec3 operator ^ (const vec2& a, const vec2& b); // cross product
5.166 + friend int operator == (const vec2& a, const vec2& b); // v1 == v2 ?
5.167 + friend int operator != (const vec2& a, const vec2& b); // v1 != v2 ?
5.168 + //friend ostream& operator << (ostream& s, vec2& v); // output to stream
5.169 + //friend istream& operator >> (istream& s, vec2& v); // input from strm.
5.170 + friend void swap(vec2& a, vec2& b); // swap v1 & v2
5.171 + friend vec2 min_vec(const vec2& a, const vec2& b); // min(v1, v2)
5.172 + friend vec2 max_vec(const vec2& a, const vec2& b); // max(v1, v2)
5.173 + friend vec2 prod(const vec2& a, const vec2& b); // term by term *
5.174 +
5.175 + // necessary friend declarations
5.176 +
5.177 + friend class vec3;
5.178 +};
5.179 +
5.180 +/****************************************************************
5.181 +* *
5.182 +* 3D Vector *
5.183 +* *
5.184 +****************************************************************/
5.185 +
5.186 +class vec3
5.187 +{
5.188 +protected:
5.189 +
5.190 + float n[3];
5.191 +
5.192 +public:
5.193 +
5.194 + // Constructors
5.195 +
5.196 + vec3(void);
5.197 + vec3(const float x, const float y, const float z);
5.198 + vec3(const float d);
5.199 + vec3(const vec3& v); // copy constructor
5.200 + vec3(const vec2& v); // cast v2 to v3
5.201 + vec3(const vec2& v, float d); // cast v2 to v3
5.202 + vec3(const vec4& v); // cast v4 to v3
5.203 + vec3(const vec4& v, int dropAxis); // cast v4 to v3
5.204 +
5.205 + // Assignment operators
5.206 +
5.207 + vec3& operator = ( const vec3& v ); // assignment of a vec3
5.208 + vec3& operator += ( const vec3& v ); // incrementation by a vec3
5.209 + vec3& operator -= ( const vec3& v ); // decrementation by a vec3
5.210 + vec3& operator *= ( const float d ); // multiplication by a constant
5.211 + vec3& operator /= ( const float d ); // division by a constant
5.212 + float& operator [] ( int i); // indexing
5.213 +
5.214 + // special functions
5.215 +
5.216 + float length(void); // length of a vec3
5.217 + float length2(void); // squared length of a vec3
5.218 + vec3& normalize(void); // normalize a vec3
5.219 + vec3& homogenize(void); // homogenize (div by Z)
5.220 + vec3& apply(V_FCT_PTR fct); // apply a func. to each component
5.221 + void set( float x, float y, float z ); // set vector
5.222 + void print( FILE *file, char *name ); // print vector to a file
5.223 +
5.224 + // friends
5.225 +
5.226 + friend vec3 operator - (const vec3& v); // -v1
5.227 + friend vec3 operator + (const vec3& a, const vec3& b); // v1 + v2
5.228 + friend vec3 operator - (const vec3& a, const vec3& b); // v1 - v2
5.229 + friend vec3 operator * (const vec3& a, const float d); // v1 * 3.0
5.230 + friend vec3 operator * (const float d, const vec3& a); // 3.0 * v1
5.231 + friend vec3 operator * (const mat4& a, const vec3& v); // M . v
5.232 + friend vec3 operator * (const vec3& v, mat4& a); // v . M
5.233 + friend float operator * (const vec3& a, const vec3& b); // dot product
5.234 + friend vec3 operator / (const vec3& a, const float d); // v1 / 3.0
5.235 + friend vec3 operator ^ (const vec3& a, const vec3& b); // cross product
5.236 + friend int operator == (const vec3& a, const vec3& b); // v1 == v2 ?
5.237 + friend int operator != (const vec3& a, const vec3& b); // v1 != v2 ?
5.238 + //friend ostream& operator << (ostream& s, vec3& v); // output to stream
5.239 + //friend istream& operator >> (istream& s, vec3& v); // input from strm.
5.240 + friend void swap(vec3& a, vec3& b); // swap v1 & v2
5.241 + friend vec3 min_vec(const vec3& a, const vec3& b); // min(v1, v2)
5.242 + friend vec3 max_vec(const vec3& a, const vec3& b); // max(v1, v2)
5.243 + friend vec3 prod(const vec3& a, const vec3& b); // term by term *
5.244 +
5.245 + // necessary friend declarations
5.246 +
5.247 + friend class vec2;
5.248 + friend class vec4;
5.249 + friend class mat3;
5.250 + friend vec2 operator * (const mat3& a, const vec2& v); // linear transform
5.251 + friend vec3 operator * (const mat3& a, const vec3& v); // linear transform
5.252 + friend mat3 operator * (mat3& a, mat3& b); // matrix 3 product
5.253 +
5.254 +};
5.255 +
5.256 +/****************************************************************
5.257 +* *
5.258 +* 4D Vector *
5.259 +* *
5.260 +****************************************************************/
5.261 +
5.262 +class vec4
5.263 +{
5.264 +protected:
5.265 +
5.266 + float n[4];
5.267 +
5.268 +public:
5.269 +
5.270 + // Constructors
5.271 +
5.272 + vec4(void);
5.273 + vec4(const float x, const float y, const float z, const float w);
5.274 + vec4(const float d);
5.275 + vec4(const vec4& v); // copy constructor
5.276 + vec4(const vec3& v); // cast vec3 to vec4
5.277 + vec4(const vec3& v, const float d); // cast vec3 to vec4
5.278 +
5.279 + // Assignment operators
5.280 +
5.281 + vec4& operator = ( const vec4& v ); // assignment of a vec4
5.282 + vec4& operator += ( const vec4& v ); // incrementation by a vec4
5.283 + vec4& operator -= ( const vec4& v ); // decrementation by a vec4
5.284 + vec4& operator *= ( const float d ); // multiplication by a constant
5.285 + vec4& operator /= ( const float d ); // division by a constant
5.286 + float& operator [] ( int i); // indexing
5.287 +
5.288 + // special functions
5.289 +
5.290 + float length(void); // length of a vec4
5.291 + float length2(void); // squared length of a vec4
5.292 + vec4& normalize(void); // normalize a vec4
5.293 + vec4& apply(V_FCT_PTR fct); // apply a func. to each component
5.294 + vec4& homogenize(void);
5.295 + void print( FILE *file, char *name ); // print vector to a file
5.296 + void set( float x, float y, float z, float a );
5.297 +
5.298 + // friends
5.299 +
5.300 + friend vec4 operator - (const vec4& v); // -v1
5.301 + friend vec4 operator + (const vec4& a, const vec4& b); // v1 + v2
5.302 + friend vec4 operator - (const vec4& a, const vec4& b); // v1 - v2
5.303 + friend vec4 operator * (const vec4& a, const float d); // v1 * 3.0
5.304 + friend vec4 operator * (const float d, const vec4& a); // 3.0 * v1
5.305 + friend vec4 operator * (const mat4& a, const vec4& v); // M . v
5.306 + friend vec4 operator * (const vec4& v, mat4& a); // v . M
5.307 + friend float operator * (const vec4& a, const vec4& b); // dot product
5.308 + friend vec4 operator / (const vec4& a, const float d); // v1 / 3.0
5.309 + friend int operator == (const vec4& a, const vec4& b); // v1 == v2 ?
5.310 + friend int operator != (const vec4& a, const vec4& b); // v1 != v2 ?
5.311 + //friend ostream& operator << (ostream& s, vec4& v); // output to stream
5.312 + //friend istream& operator >> (istream& s, vec4& v); // input from strm.
5.313 + friend void swap(vec4& a, vec4& b); // swap v1 & v2
5.314 + friend vec4 min_vec(const vec4& a, const vec4& b); // min(v1, v2)
5.315 + friend vec4 max_vec(const vec4& a, const vec4& b); // max(v1, v2)
5.316 + friend vec4 prod(const vec4& a, const vec4& b); // term by term *
5.317 +
5.318 + // necessary friend declarations
5.319 +
5.320 + friend class vec3;
5.321 + friend class mat4;
5.322 + friend vec3 operator * (const mat4& a, const vec3& v); // linear transform
5.323 + friend mat4 operator * (mat4& a, mat4& b); // matrix 4 product
5.324 +};
5.325 +
5.326 +/****************************************************************
5.327 +* *
5.328 +* 3x3 Matrix *
5.329 +* *
5.330 +****************************************************************/
5.331 +
5.332 +class mat3
5.333 +{
5.334 +protected:
5.335 +
5.336 + vec3 v[3];
5.337 +
5.338 +public:
5.339 +
5.340 + // Constructors
5.341 +
5.342 + mat3(void);
5.343 + mat3(const vec3& v0, const vec3& v1, const vec3& v2);
5.344 + mat3(const float d);
5.345 + mat3(const mat3& m);
5.346 +
5.347 + // Assignment operators
5.348 +
5.349 + mat3& operator = ( const mat3& m ); // assignment of a mat3
5.350 + mat3& operator += ( const mat3& m ); // incrementation by a mat3
5.351 + mat3& operator -= ( const mat3& m ); // decrementation by a mat3
5.352 + mat3& operator *= ( const float d ); // multiplication by a constant
5.353 + mat3& operator /= ( const float d ); // division by a constant
5.354 + vec3& operator [] ( int i); // indexing
5.355 +
5.356 + // special functions
5.357 +
5.358 + mat3 transpose(void); // transpose
5.359 + mat3 inverse(void); // inverse
5.360 + mat3& apply(V_FCT_PTR fct); // apply a func. to each element
5.361 + void print( FILE *file, char *name ); // print matrix to a file
5.362 + void set(const vec3& v0, const vec3& v1, const vec3& v2);
5.363 +
5.364 +
5.365 + // friends
5.366 +
5.367 + friend mat3 operator - (const mat3& a); // -m1
5.368 + friend mat3 operator + (const mat3& a, const mat3& b); // m1 + m2
5.369 + friend mat3 operator - (const mat3& a, const mat3& b); // m1 - m2
5.370 + friend mat3 operator * (mat3& a, mat3& b); // m1 * m2
5.371 + friend mat3 operator * (const mat3& a, const float d); // m1 * 3.0
5.372 + friend mat3 operator * (const float d, const mat3& a); // 3.0 * m1
5.373 + friend mat3 operator / (const mat3& a, const float d); // m1 / 3.0
5.374 + friend int operator == (const mat3& a, const mat3& b); // m1 == m2 ?
5.375 + friend int operator != (const mat3& a, const mat3& b); // m1 != m2 ?
5.376 + //friend ostream& operator << (ostream& s, mat3& m); // output to stream
5.377 + //friend istream& operator >> (istream& s, mat3& m); // input from strm.
5.378 + friend void swap(mat3& a, mat3& b); // swap m1 & m2
5.379 +
5.380 + // necessary friend declarations
5.381 +
5.382 + friend vec3 operator * (const mat3& a, const vec3& v); // linear transform
5.383 + friend vec2 operator * (const mat3& a, const vec2& v); // linear transform
5.384 +};
5.385 +
5.386 +/****************************************************************
5.387 +* *
5.388 +* 4x4 Matrix *
5.389 +* *
5.390 +****************************************************************/
5.391 +
5.392 +class mat4
5.393 +{
5.394 +protected:
5.395 +public:
5.396 +
5.397 + vec4 v[4];
5.398 +
5.399 +
5.400 + // Constructors
5.401 +
5.402 + mat4(void);
5.403 + mat4(const vec4& v0, const vec4& v1, const vec4& v2, const vec4& v3);
5.404 + mat4(const float d);
5.405 + mat4(const mat4& m);
5.406 + mat4(const float a00, const float a01, const float a02, const float a03,
5.407 + const float a10, const float a11, const float a12, const float a13,
5.408 + const float a20, const float a21, const float a22, const float a23,
5.409 + const float a30, const float a31, const float a32, const float a33 );
5.410 +
5.411 +
5.412 + // Assignment operators
5.413 +
5.414 + mat4& operator = ( const mat4& m ); // assignment of a mat4
5.415 + mat4& operator += ( const mat4& m ); // incrementation by a mat4
5.416 + mat4& operator -= ( const mat4& m ); // decrementation by a mat4
5.417 + mat4& operator *= ( const float d ); // multiplication by a constant
5.418 + mat4& operator /= ( const float d ); // division by a constant
5.419 + vec4& operator [] ( int i); // indexing
5.420 +
5.421 + // special functions
5.422 +
5.423 + mat4 transpose(void); // transpose
5.424 + mat4 inverse(void); // inverse
5.425 + mat4& apply(V_FCT_PTR fct); // apply a func. to each element
5.426 + void print( FILE *file, char *name ); // print matrix to a file
5.427 + void swap_rows( int i, int j ); // swap rows i and j
5.428 + void swap_cols( int i, int j ); // swap cols i and j
5.429 +
5.430 + // friends
5.431 +
5.432 + friend mat4 operator - (const mat4& a); // -m1
5.433 + friend mat4 operator + (const mat4& a, const mat4& b); // m1 + m2
5.434 + friend mat4 operator - (const mat4& a, const mat4& b); // m1 - m2
5.435 + friend mat4 operator * (mat4& a, mat4& b); // m1 * m2
5.436 + friend mat4 operator * (const mat4& a, const float d); // m1 * 4.0
5.437 + friend mat4 operator * (const float d, const mat4& a); // 4.0 * m1
5.438 + friend mat4 operator / (const mat4& a, const float d); // m1 / 3.0
5.439 + friend int operator == (const mat4& a, const mat4& b); // m1 == m2 ?
5.440 + friend int operator != (const mat4& a, const mat4& b); // m1 != m2 ?
5.441 + //friend ostream& operator << (ostream& s, mat4& m); // output to stream
5.442 + //friend istream& operator >> (istream& s, mat4& m); // input from strm.
5.443 + friend void swap(mat4& a, mat4& b); // swap m1 & m2
5.444 +
5.445 + // necessary friend declarations
5.446 +
5.447 + friend vec4 operator * (const mat4& a, const vec4& v); // linear transform
5.448 + //friend vec4 operator * (const vec4& v, const mat4& a); // linear transform
5.449 + friend vec3 operator * (const mat4& a, const vec3& v); // linear transform
5.450 + friend vec3 operator * (const vec3& v, const mat4& a); // linear transform
5.451 +};
5.452 +
5.453 +/****************************************************************
5.454 +* *
5.455 +* 2D functions and 3D functions *
5.456 +* *
5.457 +****************************************************************/
5.458 +
5.459 +mat3 identity2D(void); // identity 2D
5.460 +mat3 translation2D(vec2& v); // translation 2D
5.461 +mat3 rotation2D(vec2& Center, const float angleDeg); // rotation 2D
5.462 +mat3 scaling2D(vec2& scaleVector); // scaling 2D
5.463 +mat4 identity3D(void); // identity 3D
5.464 +mat4 translation3D(vec3& v); // translation 3D
5.465 +mat4 rotation3D(vec3& Axis, const float angleDeg); // rotation 3D
5.466 +mat4 rotation3Drad(vec3& Axis, const float angleRad); // rotation 3D
5.467 +mat4 scaling3D(vec3& scaleVector); // scaling 3D
5.468 +mat4 perspective3D(const float d); // perspective 3D
5.469 +
5.470 +
5.471 +vec3 operator * (const vec3& v, mat3& a);
5.472 +vec2 operator * (const vec2& v, mat3& a);
5.473 +vec3 operator * (const vec3& v, mat4& a);
5.474 +vec4 operator * (const vec4& v, mat4& a);
5.475 +
5.476 +
5.477 +#endif
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/source/glui/arcball.cpp Wed Nov 04 00:39:03 2009 +0000
6.3 @@ -0,0 +1,223 @@
6.4 +/**********************************************************************
6.5 +
6.6 + arcball.cpp
6.7 +
6.8 +
6.9 + --------------------------------------------------
6.10 +
6.11 + Copyright (c) 1998 Paul Rademacher
6.12 +
6.13 + This program is freely distributable without licensing fees and is
6.14 + provided without guarantee or warrantee expressed or implied. This
6.15 + program is -not- in the public domain.
6.16 +
6.17 +**********************************************************************/
6.18 +
6.19 +
6.20 +#include "arcball.h"
6.21 +#include <stdio.h>
6.22 +
6.23 +
6.24 +/**************************************** Arcball::Arcball() ****/
6.25 +/* Default (void) constructor for Arcball */
6.26 +
6.27 +Arcball::Arcball( void )
6.28 +{
6.29 + rot_ptr = &rot;
6.30 +
6.31 + init();
6.32 +}
6.33 +
6.34 +
6.35 +/**************************************** Arcball::Arcball() ****/
6.36 +/* Takes as argument a mat4 to use instead of the internal rot */
6.37 +
6.38 +Arcball::Arcball( mat4 *mtx )
6.39 +{
6.40 + rot_ptr = mtx;
6.41 +}
6.42 +
6.43 +
6.44 +/**************************************** Arcball::Arcball() ****/
6.45 +/* A constructor that accepts the screen center and arcball radius*/
6.46 +
6.47 +Arcball::Arcball( vec2 _center, float _radius )
6.48 +{
6.49 + rot_ptr = &rot;
6.50 +
6.51 + init();
6.52 + set_params( _center, _radius );
6.53 +}
6.54 +
6.55 +
6.56 +/************************************** Arcball::set_params() ****/
6.57 +
6.58 +void Arcball::set_params( vec2 _center, float _radius )
6.59 +{
6.60 + center = _center;
6.61 + radius = _radius;
6.62 +}
6.63 +
6.64 +
6.65 +/*************************************** Arcball::init() **********/
6.66 +
6.67 +void Arcball::init( void )
6.68 +{
6.69 + center.set( 0.0, 0.0 );
6.70 + radius = 1.0;
6.71 + q_now = quat_identity();
6.72 + *rot_ptr = identity3D();
6.73 + q_increment = quat_identity();
6.74 + rot_increment = identity3D();
6.75 + is_mouse_down = false;
6.76 + is_spinning = false;
6.77 + damp_factor = 0.0;
6.78 + zero_increment = true;
6.79 +}
6.80 +
6.81 +
6.82 +/*********************************** Arcball::mouse_to_sphere() ****/
6.83 +
6.84 +vec3 Arcball::mouse_to_sphere( vec2 p )
6.85 +{
6.86 + float mag;
6.87 + vec2 v2 = (p - center) / radius;
6.88 + vec3 v3( v2[0], v2[1], 0.0 );
6.89 +
6.90 + mag = v2*v2;
6.91 +
6.92 + if ( mag > 1.0 ) {
6.93 + v3.normalize();
6.94 + }
6.95 + else {
6.96 + v3[VZ] = sqrt( 1.0 - mag );
6.97 + }
6.98 +
6.99 + /* Now we add constraints - X takes precedence over Y */
6.100 + if ( constraint_x ) {
6.101 + v3 = constrain_vector( v3, vec3( 1.0, 0.0, 0.0 ));
6.102 + } else if ( constraint_y ) {
6.103 + v3 = constrain_vector( v3, vec3( 0.0, 1.0, 0.0 ));
6.104 + }
6.105 +
6.106 + return v3;
6.107 +}
6.108 +
6.109 +
6.110 +/************************************ Arcball::constrain_vector() ****/
6.111 +
6.112 +vec3 Arcball::constrain_vector( vec3 vector, vec3 axis )
6.113 +{
6.114 + return (vector-(vector*axis)*axis).normalize();
6.115 +}
6.116 +
6.117 +/************************************ Arcball::mouse_down() **********/
6.118 +
6.119 +void Arcball::mouse_down( int x, int y )
6.120 +{
6.121 + down_pt.set( (float)x, (float) y );
6.122 + is_mouse_down = true;
6.123 +
6.124 + q_increment = quat_identity();
6.125 + rot_increment = identity3D();
6.126 + zero_increment = true;
6.127 +}
6.128 +
6.129 +
6.130 +/************************************ Arcball::mouse_up() **********/
6.131 +
6.132 +void Arcball::mouse_up( void )
6.133 +{
6.134 + q_now = q_drag * q_now;
6.135 + is_mouse_down = false;
6.136 +}
6.137 +
6.138 +
6.139 +/********************************** Arcball::mouse_motion() **********/
6.140 +
6.141 +void Arcball::mouse_motion( int x, int y, int shift, int ctrl, int alt )
6.142 +{
6.143 + /* Set the X constraint if CONTROL key is pressed, Y if ALT key */
6.144 + set_constraints( ctrl != 0, alt != 0 );
6.145 +
6.146 + vec2 new_pt( (float)x, (float) y );
6.147 + vec3 v0 = mouse_to_sphere( down_pt );
6.148 + vec3 v1 = mouse_to_sphere( new_pt );
6.149 +
6.150 + vec3 cross = v0^v1;
6.151 +
6.152 + q_drag.set( cross, v0 * v1 );
6.153 +
6.154 + // *rot_ptr = (q_drag * q_now).to_mat4();
6.155 + mat4 temp = q_drag.to_mat4();
6.156 + *rot_ptr = *rot_ptr * temp;
6.157 +
6.158 + down_pt = new_pt;
6.159 +
6.160 + /* We keep a copy of the current incremental rotation (= q_drag) */
6.161 + q_increment = q_drag;
6.162 + rot_increment = q_increment.to_mat4();
6.163 +
6.164 + set_constraints( false, false );
6.165 +
6.166 + if ( q_increment.s < .999999 ) {
6.167 + is_spinning = true;
6.168 +
6.169 + zero_increment = false;
6.170 + }
6.171 + else {
6.172 + is_spinning = false;
6.173 + zero_increment = true;
6.174 + }
6.175 +}
6.176 +
6.177 +
6.178 +/********************************** Arcball::mouse_motion() **********/
6.179 +
6.180 +void Arcball::mouse_motion( int x, int y )
6.181 +{
6.182 + mouse_motion( x, y, 0, 0, 0 );
6.183 +}
6.184 +
6.185 +
6.186 +/***************************** Arcball::set_constraints() **********/
6.187 +
6.188 +void Arcball::set_constraints( Bool _constraint_x, Bool _constraint_y )
6.189 +{
6.190 + constraint_x = _constraint_x;
6.191 + constraint_y = _constraint_y;
6.192 +}
6.193 +
6.194 +/***************************** Arcball::idle() *********************/
6.195 +
6.196 +void Arcball::idle( void )
6.197 +{
6.198 + if ( is_mouse_down ) {
6.199 + is_spinning = false;
6.200 + zero_increment = true;
6.201 + }
6.202 +
6.203 + if ( damp_factor < 1.0 ) {
6.204 + q_increment.scale_angle( 1.0 - damp_factor );
6.205 + }
6.206 +
6.207 + rot_increment = q_increment.to_mat4();
6.208 +
6.209 + if ( q_increment.s >= .999999 ) {
6.210 + is_spinning = false;
6.211 + zero_increment = true;
6.212 + }
6.213 +}
6.214 +
6.215 +
6.216 +/************************ Arcball::set_damping() *********************/
6.217 +
6.218 +void Arcball::set_damping( float d )
6.219 +{
6.220 + damp_factor = d;
6.221 +}
6.222 +
6.223 +
6.224 +
6.225 +
6.226 +
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/source/glui/arcball.h Wed Nov 04 00:39:03 2009 +0000
7.3 @@ -0,0 +1,80 @@
7.4 +/**********************************************************************
7.5 +
7.6 + Arcball.h
7.7 +
7.8 + A C++ class that implements the Arcball, as described by Ken
7.9 + Shoemake in Graphics Gems IV.
7.10 + This class takes as input mouse events (mouse down, mouse drag,
7.11 + mouse up), and creates the appropriate quaternions and 4x4 matrices
7.12 + to represent the rotation given by the mouse.
7.13 +
7.14 + This class is used as follows:
7.15 + - initialize [either in the constructor or with set_params()], the
7.16 + center position (x,y) of the arcball on the screen, and the radius
7.17 + - on mouse down, call mouse_down(x,y) with the mouse position
7.18 + - as the mouse is dragged, repeatedly call mouse_motion() with the
7.19 + current x and y positions. One can optionally pass in the current
7.20 + state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
7.21 + are not pressed, non-zero otherwise), which constrains
7.22 + the rotation to certain axes (X for CONTROL, Y for ALT).
7.23 + - when the mouse button is released, call mouse_up()
7.24 +
7.25 + Axis constraints can also be explicitly set with the
7.26 + set_constraints() function.
7.27 +
7.28 + The current rotation is stored in the 4x4 float matrix 'rot'.
7.29 + It is also stored in the quaternion 'q_now'.
7.30 +
7.31 + ------------------------------------------------------------------
7.32 +
7.33 + Feb 25, 1998 - Paul Rademacher (rademach@cs.unc.edu)
7.34 +
7.35 +**********************************************************************/
7.36 +
7.37 +
7.38 +#ifndef _ARCBALL_H_
7.39 +#define _ARCBALL_H_
7.40 +
7.41 +
7.42 +#include "stdinc.h"
7.43 +#include "algebra3.h"
7.44 +#include "quaternion.h"
7.45 +#include <GL/glut.h>
7.46 +
7.47 +class Arcball {
7.48 +public:
7.49 + Bool constraint_x, constraint_y;
7.50 + vec2 center;
7.51 + float radius, damp_factor;
7.52 + int zero_increment;
7.53 +
7.54 + vec3 constrain_vector( vec3 vector, vec3 axis );
7.55 + vec3 mouse_to_sphere( vec2 p );
7.56 +
7.57 + //public:
7.58 + int is_mouse_down; /* true for down, false for up */
7.59 + int is_spinning;
7.60 + quat q_now, q_down, q_drag, q_increment;
7.61 + vec2 down_pt;
7.62 + mat4 rot, rot_increment;
7.63 + mat4 *rot_ptr;
7.64 +
7.65 + void set_damping( float d );
7.66 + void idle( void );
7.67 + void mouse_down( int x, int y );
7.68 + void mouse_up( void );
7.69 + void mouse_motion( int x, int y, int shift, int ctrl, int alt );
7.70 + void mouse_motion( int x, int y );
7.71 + void set_constraints( Bool constrain_x, Bool constrain_y );
7.72 + void set_params( vec2 center, float radius );
7.73 + void reset_mouse( void );
7.74 + void init( void );
7.75 +
7.76 + Arcball( void );
7.77 + Arcball( mat4 *mtx );
7.78 + Arcball( vec2 center, float radius );
7.79 +};
7.80 +
7.81 +
7.82 +#endif
7.83 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/source/glui/glui.cpp Wed Nov 04 00:39:03 2009 +0000
8.3 @@ -0,0 +1,1956 @@
8.4 +/****************************************************************************
8.5 +
8.6 + GLUI User Interface Toolkit
8.7 + ---------------------------
8.8 +
8.9 + glui.cpp
8.10 +
8.11 +
8.12 + --------------------------------------------------
8.13 +
8.14 + Copyright (c) 1998 Paul Rademacher
8.15 +
8.16 + This program is freely distributable without licensing fees and is
8.17 + provided without guarantee or warrantee expressed or implied. This
8.18 + program is -not- in the public domain.
8.19 +
8.20 +*****************************************************************************/
8.21 +
8.22 +#include "glui.h"
8.23 +#include "stdinc.h"
8.24 +#include <GL/glut.h>
8.25 +
8.26 +
8.27 +/*** This object must be used to create a GLUI ***/
8.28 +
8.29 +GLUI_Master_Object GLUI_Master;
8.30 +
8.31 +
8.32 +/************************************ finish_drawing() ************/
8.33 +
8.34 +void finish_drawing( void )
8.35 +{
8.36 + glFinish();
8.37 +}
8.38 +
8.39 +/************************************************ GLUI::GLUI() **********/
8.40 +
8.41 +int GLUI::init( char *text, long flags, int x, int y, int parent_window )
8.42 +{
8.43 + int old_glut_window;
8.44 +
8.45 + this->flags = flags;
8.46 +
8.47 + strncpy( window_name.string, text, sizeof(GLUI_String));
8.48 +
8.49 + /*** We copy over the current window callthroughs ***/
8.50 + /*** (I think this might actually only be needed for subwindows) ***/
8.51 + /* glut_keyboard_CB = GLUI_Master.glut_keyboard_CB;
8.52 + glut_reshape_CB = GLUI_Master.glut_reshape_CB;
8.53 + glut_special_CB = GLUI_Master.glut_special_CB;
8.54 + glut_mouse_CB = GLUI_Master.glut_mouse_CB;*/
8.55 +
8.56 +
8.57 + if ( (flags & GLUI_SUBWINDOW) != GLUI_SUBWINDOW ) {
8.58 + old_glut_window = glutGetWindow();
8.59 +
8.60 + create_standalone_window( window_name, x, y );
8.61 + setup_default_glut_callbacks();
8.62 +
8.63 + if ( old_glut_window > 0 )
8.64 + glutSetWindow( old_glut_window );
8.65 +
8.66 + top_level_glut_window_id = glut_window_id;
8.67 + }
8.68 + else {
8.69 + old_glut_window = glutGetWindow();
8.70 +
8.71 + create_subwindow( parent_window, flags );
8.72 + setup_default_glut_callbacks();
8.73 +
8.74 + if ( old_glut_window > 0 )
8.75 + glutSetWindow( old_glut_window );
8.76 +
8.77 + top_level_glut_window_id = parent_window;
8.78 +
8.79 + /*
8.80 + glutReshapeFunc( glui_parent_window_reshape_func );
8.81 + glutSpecialFunc( glui_parent_window_special_func );
8.82 + glutKeyboardFunc( glui_parent_window_keyboard_func );
8.83 + glutMouseFunc( glui_parent_window_mouse_func );
8.84 + */
8.85 +
8.86 + }
8.87 +
8.88 + return true;
8.89 +}
8.90 +
8.91 +
8.92 +/**************************** GLUI_Main::create_standalone_window() ********/
8.93 +
8.94 +void GLUI_Main::create_standalone_window( char *name, int x, int y )
8.95 +{
8.96 + glutInitWindowSize( 100, 100 );
8.97 + if ( x >= 0 OR y >= 0 )
8.98 + glutInitWindowPosition( x, y );
8.99 + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE ); /* | GLUT_DOUBLE ); */
8.100 + glut_window_id = glutCreateWindow( name );
8.101 + glDisable( GL_DEPTH_TEST );
8.102 + glCullFace( GL_BACK );
8.103 + glDisable( GL_CULL_FACE );
8.104 + glDisable( GL_LIGHTING );
8.105 + glDrawBuffer( GL_FRONT );
8.106 +}
8.107 +
8.108 +
8.109 +/******************************** GLUI_Main::create_subwindow() **********/
8.110 +
8.111 +void GLUI_Main::create_subwindow( int parent_window, int window_alignment )
8.112 +{
8.113 + glut_window_id = glutCreateSubWindow( parent_window, 0,0, 100, 100 );
8.114 + glDisable( GL_DEPTH_TEST );
8.115 + glCullFace( GL_BACK );
8.116 + glDisable( GL_CULL_FACE );
8.117 + glDisable( GL_LIGHTING );
8.118 + glDrawBuffer( GL_FRONT );
8.119 +
8.120 + this->parent_window = parent_window;
8.121 +}
8.122 +
8.123 +
8.124 +/**************************** GLUI_Main::setup_default_glut_callbacks() *****/
8.125 +
8.126 +void GLUI_Main::setup_default_glut_callbacks( void )
8.127 +{
8.128 + glutDisplayFunc( glui_display_func );
8.129 + glutReshapeFunc( glui_reshape_func );
8.130 + glutKeyboardFunc( glui_keyboard_func );
8.131 + glutSpecialFunc( glui_special_func );
8.132 + glutMouseFunc( glui_mouse_func );
8.133 + glutMotionFunc( glui_motion_func );
8.134 + glutPassiveMotionFunc( glui_passive_motion_func );
8.135 + glutEntryFunc( glui_entry_func );
8.136 + glutVisibilityFunc( glui_visibility_func );
8.137 + /* glutIdleFunc( glui_idle_func ); */
8.138 +}
8.139 +
8.140 +
8.141 +/********************************************** glui_display_func() ********/
8.142 +
8.143 +void glui_display_func( void )
8.144 +{
8.145 + GLUI *glui;
8.146 +
8.147 + /* printf( "display func\n" ); */
8.148 +
8.149 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.150 +
8.151 + if ( glui ) {
8.152 + glui->display();
8.153 + /*
8.154 + Do not do anything after the above line, b/c the GLUI
8.155 + window might have just closed itself
8.156 + */
8.157 + }
8.158 +}
8.159 +
8.160 +
8.161 +/********************************************** glui_reshape_func() ********/
8.162 +
8.163 +void glui_reshape_func( int w, int h )
8.164 +{
8.165 + GLUI *glui;
8.166 + GLUI_Glut_Window *glut_window;
8.167 + int current_window;
8.168 +
8.169 + /*printf( "glui_reshape_func(): %d w/h: %d/%d\n", glutGetWindow(), w, h ); */
8.170 +
8.171 + current_window = glutGetWindow();
8.172 +
8.173 + /*** First check if this is main glut window ***/
8.174 + glut_window = GLUI_Master.find_glut_window( current_window );
8.175 + if ( glut_window ) {
8.176 + glut_window->glut_reshape_CB(w,h);
8.177 +
8.178 + /*** Now send reshape events to all subwindows ***/
8.179 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.180 + while(glui) {
8.181 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.182 + glui->parent_window == current_window ) {
8.183 + glutSetWindow( glui->get_glut_window_id());
8.184 + glui->reshape(w,h);
8.185 + /* glui->check_subwindow_position(); */
8.186 + }
8.187 + glui = (GLUI*) glui->next();
8.188 + }
8.189 + }
8.190 + else {
8.191 + /*** A standalone GLUI window ***/
8.192 +
8.193 + glui = GLUI_Master.find_glui_by_window_id( current_window );
8.194 +
8.195 + if ( glui ) {
8.196 + glui->reshape(w,h);
8.197 + }
8.198 + }
8.199 +}
8.200 +
8.201 +/********************************************** glui_keyboard_func() ********/
8.202 +
8.203 +void glui_keyboard_func(unsigned char key, int x, int y)
8.204 +{
8.205 + GLUI *glui;
8.206 + int current_window;
8.207 + GLUI_Glut_Window *glut_window;
8.208 +
8.209 + current_window = glutGetWindow();
8.210 + glut_window = GLUI_Master.find_glut_window( current_window );
8.211 +
8.212 + /*printf( "key: %d\n", current_window ); */
8.213 +
8.214 + if ( glut_window ) { /** Was event in a GLUT window? **/
8.215 + if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
8.216 + glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
8.217 +
8.218 + GLUI_Master.active_control_glui->keyboard(key,x,y);
8.219 + finish_drawing();
8.220 +
8.221 + glutSetWindow( current_window );
8.222 + }
8.223 + else {
8.224 + glut_window->glut_keyboard_CB( key, x, y );
8.225 + }
8.226 + }
8.227 + else { /*** Nope, event was in a standalone GLUI window **/
8.228 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.229 +
8.230 + if ( glui ) {
8.231 + glui->keyboard(key,x,y);
8.232 + finish_drawing();
8.233 + }
8.234 + }
8.235 +}
8.236 +
8.237 +
8.238 +/************************************************ glui_special_func() ********/
8.239 +
8.240 +void glui_special_func(int key, int x, int y)
8.241 +{
8.242 + GLUI *glui;
8.243 + int current_window;
8.244 + GLUI_Glut_Window *glut_window;
8.245 +
8.246 + current_window = glutGetWindow();
8.247 + glut_window = GLUI_Master.find_glut_window( current_window );
8.248 +
8.249 + if ( glut_window ) { /** Was event in a GLUT window? **/
8.250 + if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
8.251 + glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
8.252 +
8.253 + GLUI_Master.active_control_glui->special(key,x,y);
8.254 + finish_drawing();
8.255 +
8.256 + glutSetWindow( current_window );
8.257 + }
8.258 + else {
8.259 + glut_window->glut_special_CB( key, x, y );
8.260 + }
8.261 + }
8.262 + else { /*** Nope, event was in a standalone GLUI window **/
8.263 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.264 +
8.265 + if ( glui ) {
8.266 + glui->special(key,x,y);
8.267 + finish_drawing();
8.268 + }
8.269 + }
8.270 +}
8.271 +
8.272 +
8.273 +
8.274 +/********************************************** glui_mouse_func() ********/
8.275 +
8.276 +void glui_mouse_func(int button, int state, int x, int y)
8.277 +{
8.278 + GLUI *glui;
8.279 + int current_window;
8.280 + GLUI_Glut_Window *glut_window;
8.281 +
8.282 + current_window = glutGetWindow();
8.283 + glut_window = GLUI_Master.find_glut_window( current_window );
8.284 +
8.285 + if ( glut_window ) { /** Was event in a GLUT window? **/
8.286 + if ( GLUI_Master.active_control_glui != NULL )
8.287 + GLUI_Master.active_control_glui->disactivate_current_control();
8.288 +
8.289 + glut_window->glut_mouse_CB( button, state, x, y );
8.290 + finish_drawing();
8.291 + }
8.292 + else { /** Nope - event was in a GLUI standalone window **/
8.293 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.294 + if ( glui ) {
8.295 + glui->passive_motion( 0,0 );
8.296 + glui->mouse( button, state, x, y );
8.297 + finish_drawing();
8.298 + }
8.299 + }
8.300 +}
8.301 +
8.302 +
8.303 +/********************************************** glui_motion_func() ********/
8.304 +
8.305 +void glui_motion_func(int x, int y)
8.306 +{
8.307 + GLUI *glui;
8.308 +
8.309 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.310 +
8.311 + if ( glui ) {
8.312 + glui->motion(x,y);
8.313 + finish_drawing();
8.314 + }
8.315 +
8.316 +}
8.317 +
8.318 +
8.319 +/**************************************** glui_passive_motion_func() ********/
8.320 +
8.321 +void glui_passive_motion_func(int x, int y)
8.322 +{
8.323 + GLUI *glui;
8.324 +
8.325 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.326 +
8.327 + if ( glui ) {
8.328 + glui->passive_motion(x,y);
8.329 + finish_drawing();
8.330 + }
8.331 +}
8.332 +
8.333 +
8.334 +/********************************************** glui_entry_func() ********/
8.335 +
8.336 +void glui_entry_func(int state)
8.337 +{
8.338 + GLUI *glui;
8.339 +
8.340 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.341 +
8.342 + if ( glui ) {
8.343 + glui->entry(state);
8.344 + }
8.345 +}
8.346 +
8.347 +
8.348 +/******************************************** glui_visibility_func() ********/
8.349 +
8.350 +void glui_visibility_func(int state)
8.351 +{
8.352 + GLUI *glui;
8.353 +
8.354 + /* printf( "IN GLUI VISIBILITY()\n" ); */
8.355 + /* fflush( stdout ); */
8.356 +
8.357 + glui = GLUI_Master.find_glui_by_window_id( glutGetWindow() );
8.358 +
8.359 + if ( glui ) {
8.360 + glui->visibility(state);
8.361 + }
8.362 +}
8.363 +
8.364 +
8.365 +/********************************************** glui_idle_func() ********/
8.366 +/* Send idle event to each glui, then to the main window */
8.367 +
8.368 +void glui_idle_func(void)
8.369 +{
8.370 + GLUI *glui;
8.371 +
8.372 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.373 + while( glui ) {
8.374 + glui->idle();
8.375 + finish_drawing();
8.376 +
8.377 + glui = (GLUI*) glui->next();
8.378 + }
8.379 +
8.380 + if ( GLUI_Master.glut_idle_CB ) {
8.381 + /*** We set the current glut window before calling the user's
8.382 + idle function, even though glut explicitly says the window id is
8.383 + undefined in an idle callback. ***/
8.384 +
8.385 + /** Check what the current window is first ***/
8.386 +
8.387 + /*** Arbitrarily set the window id to the main gfx window of the
8.388 + first glui window ***/
8.389 + /* int current_window, new_window; */
8.390 + /* current_window = glutGetWindow(); */
8.391 + /* if (GLUI_Master.gluis.first_child() != NULL ) { */
8.392 + /* new_window = ((GLUI_Main*)GLUI_Master.gluis.first_child())-> */
8.393 + /* main_gfx_window_id; */
8.394 + /* if ( new_window > 0 AND new_window != old_window ) { */
8.395 + /* --- Window is changed only if its not already the current window ---*/
8.396 + /* glutSetWindow( new_window ); */
8.397 + /* } */
8.398 + /*} */
8.399 +
8.400 + GLUI_Master.glut_idle_CB();
8.401 + }
8.402 +}
8.403 +
8.404 +
8.405 +/*********************************** GLUI_Master_Object::create_glui() ******/
8.406 +
8.407 +GLUI *GLUI_Master_Object::create_glui( char *name, long flags,int x,int y )
8.408 +{
8.409 + GLUI *new_glui;
8.410 +
8.411 + new_glui = new GLUI;
8.412 +
8.413 + if ( new_glui ) {
8.414 + new_glui->init( name, flags, x, y, -1 );
8.415 + new_glui->link_this_to_parent_last( &this->gluis );
8.416 + return new_glui;
8.417 + }
8.418 + else {
8.419 + return NULL;
8.420 + }
8.421 +}
8.422 +
8.423 +
8.424 +/************************** GLUI_Master_Object::create_glui_subwindow() ******/
8.425 +
8.426 +GLUI *GLUI_Master_Object::create_glui_subwindow( int parent_window,
8.427 + long flags )
8.428 +{
8.429 + GLUI *new_glui;
8.430 + char new_name[80];
8.431 +
8.432 + new_glui = new GLUI;
8.433 +
8.434 + if ( new_glui ) {
8.435 + sprintf( new_name, "subwin_%p", this );
8.436 +
8.437 + new_glui->init( new_name, flags | GLUI_SUBWINDOW, 0,0,
8.438 + parent_window );
8.439 + new_glui->main_panel->set_int_val( GLUI_PANEL_EMBOSSED );
8.440 + new_glui->link_this_to_parent_last( &this->gluis );
8.441 + return new_glui;
8.442 + }
8.443 + else {
8.444 + return NULL;
8.445 + }
8.446 +}
8.447 +
8.448 +
8.449 +
8.450 +/********************** GLUI_Master_Object::find_glui_by_window_id() ********/
8.451 +
8.452 +GLUI *GLUI_Master_Object::find_glui_by_window_id( int window_id )
8.453 +{
8.454 + GLUI_Node *node;
8.455 +
8.456 + node = gluis.first_child();
8.457 + while( node ) {
8.458 + if ( ((GLUI*)node)->get_glut_window_id() == window_id )
8.459 + return (GLUI*) node;
8.460 +
8.461 + node = node->next();
8.462 + }
8.463 + return NULL;
8.464 +}
8.465 +
8.466 +
8.467 +/******************************************** GLUI_Main::display() **********/
8.468 +
8.469 +void GLUI_Main::display( void )
8.470 +{
8.471 + int win_w, win_h;
8.472 +
8.473 + /*glutSetWindow(1);///WOW WHAT A HACK */
8.474 +
8.475 + /**** This function is used as a special place to do 'safe' processing,
8.476 + e.g., handling window close requests.
8.477 + That is, we can't close the window directly in the callback, so
8.478 + we set a flag, post a redisplay message (which eventually calls
8.479 + this function), then close the window safely in here. ****/
8.480 + if ( closing == true ) {
8.481 + close_internal();
8.482 + return;
8.483 + }
8.484 +
8.485 + /* if ( TEST_AND( this->flags, GLUI_SUBWINDOW ))
8.486 + check_subwindow_position();
8.487 + */
8.488 +
8.489 + /******* Draw GLUI window ******/
8.490 +
8.491 + glClearColor( (float) bkgd_color.r / 255.0,
8.492 + (float) bkgd_color.g / 255.0,
8.493 + (float) bkgd_color.b / 255.0,
8.494 + 1.0 );
8.495 + glClear( GL_COLOR_BUFFER_BIT ); /* | GL_DEPTH_BUFFER_BIT ); */
8.496 +
8.497 + /* glutSwapBuffers(); //performs flush also // %%%%%%%%%% */
8.498 + /* return; */
8.499 +
8.500 + win_w = glutGet( GLUT_WINDOW_WIDTH );
8.501 + win_h = glutGet( GLUT_WINDOW_HEIGHT );
8.502 +
8.503 + /*** Check here if the window needs resizing ***/
8.504 + if ( win_w != main_panel->w OR win_h != main_panel->h ) {
8.505 + glutReshapeWindow( main_panel->w, main_panel->h );
8.506 + return;
8.507 + }
8.508 +
8.509 + set_ortho_projection();
8.510 +
8.511 + glMatrixMode( GL_MODELVIEW );
8.512 + glLoadIdentity();
8.513 +
8.514 + /*** Rotate image so y increases upwards, contrary to OpenGL axes ***/
8.515 + glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
8.516 + glRotatef( 180.0, 0.0, 1.0, 0.0 );
8.517 + glRotatef( 180.0, 0.0, 0.0, 1.0 );
8.518 + glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
8.519 +
8.520 + /* glDrawBuffer( GL_BACK ); // Is there ever a need to draw to back buffer?? */
8.521 +
8.522 + // main_panel->draw_bkgd_box( 0, 0, win_w, win_h );
8.523 + main_panel->draw_recursive( 0, 0 );
8.524 +
8.525 + /*glutSwapBuffers(); //performs flush also */
8.526 + finish_drawing();
8.527 +}
8.528 +
8.529 +
8.530 +
8.531 +
8.532 +/*************************************** _glutBitmapWidthString() **********/
8.533 +
8.534 +int _glutBitmapWidthString( void *font, char *s )
8.535 +{
8.536 + char *p = s;
8.537 + int width = 0;
8.538 +
8.539 + while( *p != '\0' ) {
8.540 + width += glutBitmapWidth( font, *p );
8.541 + p++;
8.542 + }
8.543 +
8.544 + return width;
8.545 +}
8.546 +
8.547 +/************************************ _glutBitmapString *********************/
8.548 +/* Displays the contents of a string using GLUT's bitmap character function */
8.549 +/* Does not handle newlines */
8.550 +
8.551 +void _glutBitmapString( void *font, char *s )
8.552 +{
8.553 + char *p = s;
8.554 +
8.555 + while( *p != '\0' ) {
8.556 + glutBitmapCharacter( font, *p );
8.557 + p++;
8.558 + }
8.559 +}
8.560 +
8.561 +
8.562 +
8.563 +/****************************** GLUI_Main::reshape() **************/
8.564 +
8.565 +void GLUI_Main::reshape( int reshape_w, int reshape_h )
8.566 +{
8.567 + int new_w, new_h;
8.568 +
8.569 + pack_controls();
8.570 +
8.571 + new_w = main_panel->w;/* + 1; */
8.572 + new_h = main_panel->h;/* + 1; */
8.573 +
8.574 + if ( reshape_w != new_w OR reshape_h != new_h ) {
8.575 + this->w = new_w;
8.576 + this->h = new_h;
8.577 +
8.578 + glutReshapeWindow( new_w, new_h );
8.579 + }
8.580 + else {
8.581 + }
8.582 +
8.583 + if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
8.584 + check_subwindow_position();
8.585 +
8.586 + /***** if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
8.587 + }
8.588 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
8.589 + }
8.590 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
8.591 + }
8.592 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
8.593 + }
8.594 + ****/
8.595 + }
8.596 +
8.597 + glViewport( 0, 0, new_w, new_h );
8.598 +
8.599 + /* printf( "%d: %d\n", glutGetWindow(), this->flags ); */
8.600 +
8.601 + /* glutPostRedisplay(); */
8.602 +}
8.603 +
8.604 +
8.605 +/****************************** GLUI_Main::keyboard() **************/
8.606 +
8.607 +void GLUI_Main::keyboard(unsigned char key, int x, int y)
8.608 +{
8.609 + GLUI_Control *new_control;
8.610 +
8.611 + curr_modifiers = glutGetModifiers();
8.612 +
8.613 + /*** If it's a tab or shift tab, we don't pass it on to the controls.
8.614 + Instead, we use it to cycle through active controls ***/
8.615 + if ( key == '\t' AND mouse_button_down == false ) {
8.616 + if ( curr_modifiers & GLUT_ACTIVE_SHIFT ) {
8.617 + new_control = find_prev_control( active_control );
8.618 + }
8.619 + else {
8.620 + new_control = find_next_control( active_control );
8.621 + }
8.622 +
8.623 + /* if ( new_control )
8.624 + printf( "new_control: %s\n", new_control->name );
8.625 + */
8.626 +
8.627 + disactivate_current_control();
8.628 + activate_control( new_control, GLUI_ACTIVATE_TAB );
8.629 + }
8.630 + else if ( key == ' ' AND active_control
8.631 + AND active_control->spacebar_mouse_click == true ) {
8.632 + /*** If the user presses the spacebar, and a non-edittext control
8.633 + is active, we send it a mouse down event followed by a mouse up
8.634 + event (simulated mouse-click) ***/
8.635 +
8.636 + active_control->mouse_down_handler( 0, 0 );
8.637 + active_control->mouse_up_handler( 0, 0, true );
8.638 + } else {
8.639 + /*** Pass the keystroke onto the active control, if any ***/
8.640 + if ( active_control != NULL )
8.641 + active_control->key_handler( key, curr_modifiers );
8.642 + }
8.643 +}
8.644 +
8.645 +
8.646 +/****************************** GLUI_Main::special() **************/
8.647 +
8.648 +void GLUI_Main::special(int key, int x, int y)
8.649 +{
8.650 + curr_modifiers = glutGetModifiers();
8.651 +
8.652 + /*** Pass the keystroke onto the active control, if any ***/
8.653 + if ( active_control != NULL )
8.654 + active_control->special_handler( key, glutGetModifiers() );
8.655 +}
8.656 +
8.657 +
8.658 +
8.659 +/****************************** GLUI_Main::mouse() **************/
8.660 +
8.661 +void GLUI_Main::mouse(int button, int state, int x, int y)
8.662 +{
8.663 + int callthrough;
8.664 + GLUI_Control *control;
8.665 +
8.666 + /* printf( "MOUSE: %d %d\n", button, state ); */
8.667 +
8.668 + callthrough = true;
8.669 +
8.670 + curr_modifiers = glutGetModifiers();
8.671 +
8.672 + if ( button == GLUT_LEFT ) {
8.673 + control = find_control( x, y );
8.674 +
8.675 + /*if ( control ) printf( "control: %s\n", control->name.string ); */
8.676 +
8.677 + if ( mouse_button_down AND active_control != NULL AND
8.678 + state == GLUT_UP ) {
8.679 + /** We just released the mouse, which was depressed at some
8.680 + control **/
8.681 +
8.682 + callthrough = active_control->
8.683 + mouse_up_handler( x, y, control==active_control);
8.684 + glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
8.685 +
8.686 + if ( active_control AND
8.687 + active_control->active_type ==
8.688 + GLUI_CONTROL_ACTIVE_MOUSEDOWN AND 0){
8.689 + /*** This is a control that needs to be disactivated when the
8.690 + mouse button is released ****/
8.691 + disactivate_current_control();
8.692 + }
8.693 + }
8.694 + else {
8.695 + if ( control ) {
8.696 + if ( NOT mouse_button_down AND state == GLUT_DOWN ) {
8.697 + /*** We just pressed the mouse down at some control ***/
8.698 +
8.699 + if ( active_control != control ) {
8.700 + if ( active_control != NULL ) {
8.701 + /** There is an active control still - disactivate it ***/
8.702 + disactivate_current_control();
8.703 + }
8.704 + }
8.705 +
8.706 + if ( control->enabled ) {
8.707 + activate_control( control, GLUI_ACTIVATE_MOUSE );
8.708 + callthrough = control->mouse_down_handler( x, y );
8.709 + }
8.710 + }
8.711 + }
8.712 + }
8.713 +
8.714 + if ( state == GLUT_DOWN )
8.715 + mouse_button_down = true;
8.716 + else if ( state == GLUT_UP )
8.717 + mouse_button_down = false;
8.718 + }
8.719 +
8.720 + /**
8.721 + NO CALLTHROUGH NEEDED FOR MOUSE EVENTS
8.722 + if ( callthrough AND glut_mouse_CB )
8.723 + glut_mouse_CB( button, state, x, y );
8.724 + **/
8.725 +
8.726 + callthrough=callthrough; /* To get rid of compiler warnings */
8.727 +}
8.728 +
8.729 +
8.730 +/****************************** GLUI_Main::motion() **************/
8.731 +
8.732 +void GLUI_Main::motion(int x, int y)
8.733 +{
8.734 + int callthrough;
8.735 + GLUI_Control *control;
8.736 +
8.737 + /* printf( "MOTION: %d %d\n", x, y ); */
8.738 +
8.739 + callthrough = true;
8.740 +
8.741 + control = find_control(x,y);
8.742 +
8.743 + if ( mouse_button_down AND active_control != NULL ) {
8.744 + callthrough =
8.745 + active_control->mouse_held_down_handler(x,y,control==active_control);
8.746 + }
8.747 +
8.748 + /**
8.749 + NO CALLTHROUGH NEEDED FOR MOUSE EVENTS
8.750 +
8.751 + if ( callthrough AND glut_motion_CB )
8.752 + glut_motion_CB(x,y);
8.753 + **/
8.754 +
8.755 + callthrough=callthrough; /* To get rid of compiler warnings */
8.756 +}
8.757 +
8.758 +
8.759 +/*********************** GLUI_Main::passive_motion() **************/
8.760 +
8.761 +void GLUI_Main::passive_motion(int x, int y)
8.762 +{
8.763 + GLUI_Control *control;
8.764 +
8.765 + control = find_control( x, y );
8.766 +
8.767 + /* printf( "%p %p\n", control, mouse_over_control ); */
8.768 +
8.769 + if ( control != mouse_over_control ) {
8.770 + if ( mouse_over_control ) {
8.771 + mouse_over_control->mouse_over( false, x, y );
8.772 + }
8.773 +
8.774 + if ( control ) {
8.775 + control->mouse_over( true, x, y );
8.776 + mouse_over_control = control;
8.777 + }
8.778 + }
8.779 +
8.780 + /*
8.781 + if ( curr_cursor != GLUT_CURSOR_INHERIT ) {
8.782 + curr_cursor = GLUT_CURSOR_INHERIT;
8.783 + glutSetCursor( GLUT_CURSOR_INHERIT );
8.784 + }*/
8.785 +
8.786 +}
8.787 +
8.788 +
8.789 +/****************************** GLUI_Main::entry() **************/
8.790 +
8.791 +void GLUI_Main::entry(int state)
8.792 +{
8.793 + /*if ( NOT active_control OR ( active_control AND ( active_control->type == GLUI_CONTROL_EDITTEXT
8.794 + OR active_control->type == GLUI_CONTROL_SPINNER) ) )*/
8.795 + glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
8.796 +}
8.797 +
8.798 +
8.799 +/****************************** GLUI_Main::visibility() **************/
8.800 +
8.801 +void GLUI_Main::visibility(int state)
8.802 +{
8.803 +}
8.804 +
8.805 +
8.806 +/****************************** GLUI_Main::idle() **************/
8.807 +
8.808 +void GLUI_Main::idle(void)
8.809 +{
8.810 + /*** Pass the idle event onto the active control, if any ***/
8.811 +
8.812 + /* printf( "IDLE \t" ); */
8.813 +
8.814 + if ( active_control != NULL ) {
8.815 + /* First we check if the control actually needs the idle right now.
8.816 + Otherwise, let's avoid wasting cycles and OpenGL context switching */
8.817 +
8.818 + if ( active_control->needs_idle() ) {
8.819 + /*** Set the current glut window to the glui window */
8.820 + /*** But don't change the window if we're already at that window ***/
8.821 +
8.822 + if ( glut_window_id > 0 AND glutGetWindow() != glut_window_id ) {
8.823 + glutSetWindow( glut_window_id );
8.824 + }
8.825 +
8.826 + active_control->idle();
8.827 + }
8.828 + }
8.829 +}
8.830 +
8.831 +
8.832 +/******************************************* GLUI_Main::find_control() ******/
8.833 +
8.834 +GLUI_Control *GLUI_Main::find_control( int x, int y )
8.835 +{
8.836 + GLUI_Control *node, *last_container;
8.837 +
8.838 + last_container = NULL;
8.839 +
8.840 + node = main_panel;
8.841 + while( node != NULL ) {
8.842 + if ( node->type != GLUI_CONTROL_COLUMN AND
8.843 + PT_IN_BOX( x, y,
8.844 + node->x_abs, node->x_abs + node->w,
8.845 + node->y_abs, node->y_abs + node->h ) ) {
8.846 + /*** Point is inside current node ***/
8.847 +
8.848 + if ( node->first_child() == NULL ) {
8.849 + /*** SPECIAL CASE: for edittext boxes, we make sure click is
8.850 + in box, and not on name string. This should be generalized
8.851 + for all controls later... ***/
8.852 + if ( node->type == GLUI_CONTROL_EDITTEXT ) {
8.853 + if ( x < node->x_abs + ((GLUI_EditText*)node)->text_x_offset )
8.854 + return (GLUI_Control*) node->parent();
8.855 + }
8.856 +
8.857 + return node; /* point is inside this node, and node has no children,
8.858 + so return this node as the selected node */
8.859 + }
8.860 + else {
8.861 + /*** This is a container class ***/
8.862 + last_container = node;
8.863 + node = (GLUI_Control*) node->first_child(); /* Descend into child */
8.864 + }
8.865 +
8.866 + }
8.867 + else {
8.868 + node = (GLUI_Control*) node->next();
8.869 + }
8.870 + }
8.871 +
8.872 + /** No leaf-level nodes found to accept the mouse click, so
8.873 + return the last container control found which DOES accept the click **/
8.874 +
8.875 + if ( last_container ) {
8.876 + /* printf( "ctrl: '%s'\n", last_container->name ); */
8.877 +
8.878 + return last_container;
8.879 + }
8.880 + else {
8.881 + return NULL;
8.882 + }
8.883 +}
8.884 +
8.885 +
8.886 +/************************************* GLUI_Main::pack_controls() ***********/
8.887 +
8.888 +void GLUI_Main::pack_controls( void )
8.889 +{
8.890 + main_panel->pack(0,0);
8.891 +
8.892 + /**** Now align controls within their bounds ****/
8.893 + align_controls( main_panel );
8.894 +
8.895 + /*** If this is a subwindow, expand panel to fit parent window ***/
8.896 + if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
8.897 + int parent_h, parent_w;
8.898 + int orig_window;
8.899 +
8.900 + orig_window = glutGetWindow();
8.901 + glutSetWindow( this->top_level_glut_window_id );
8.902 + parent_h = glutGet( GLUT_WINDOW_HEIGHT );
8.903 + parent_w = glutGet( GLUT_WINDOW_WIDTH );
8.904 +
8.905 + glutSetWindow( orig_window );
8.906 +
8.907 + /* printf( "%d %d\n", parent_h, parent_w ); */
8.908 +
8.909 + if ( 1 ) {
8.910 + if ( TEST_AND(this->flags,GLUI_SUBWINDOW_TOP )) {
8.911 + main_panel->w = MAX( main_panel->w, parent_w );
8.912 + }
8.913 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
8.914 + main_panel->h = MAX( main_panel->h, parent_h );
8.915 + }
8.916 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_BOTTOM )) {
8.917 + main_panel->w = MAX( main_panel->w, parent_w );
8.918 + }
8.919 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
8.920 + main_panel->h = MAX( main_panel->h, parent_h );
8.921 + }
8.922 + }
8.923 + }
8.924 +
8.925 + this->w = main_panel->w;
8.926 + this->h = main_panel->h;
8.927 +}
8.928 +
8.929 +
8.930 +/************************************ GLUI_Main::align_controls() **********/
8.931 +
8.932 +void GLUI_Main::align_controls( GLUI_Control *control )
8.933 +{
8.934 + GLUI_Control *child;
8.935 +
8.936 + control->align();
8.937 +
8.938 + child = (GLUI_Control*) control->first_child();
8.939 +
8.940 + while( child != NULL ) {
8.941 + align_controls( child );
8.942 +
8.943 + child = (GLUI_Control*)child->next();
8.944 + }
8.945 +}
8.946 +
8.947 +
8.948 +
8.949 +/*********************************** GLUI::set_main_gfx_window() ************/
8.950 +
8.951 +void GLUI::set_main_gfx_window( int window_id )
8.952 +{
8.953 + main_gfx_window_id = window_id;
8.954 +}
8.955 +
8.956 +
8.957 +/********************************* GLUI_Main::post_update_main_gfx() ********/
8.958 +
8.959 +void GLUI_Main::post_update_main_gfx( void )
8.960 +{
8.961 + int old_window;
8.962 +
8.963 + if ( main_gfx_window_id > 0 ) {
8.964 + old_window = glutGetWindow();
8.965 + glutSetWindow( main_gfx_window_id );
8.966 + glutPostRedisplay();
8.967 + if( old_window > 0 )
8.968 + glutSetWindow( old_window );
8.969 + }
8.970 +}
8.971 +
8.972 +
8.973 +/********************************* GLUI_Main::set_front_draw_buffer() ********/
8.974 +
8.975 +int GLUI_Main::set_front_draw_buffer( void )
8.976 +{
8.977 + GLint state;
8.978 +
8.979 + glGetIntegerv( GL_DRAW_BUFFER, &state );
8.980 +
8.981 + glDrawBuffer( GL_FRONT );
8.982 +
8.983 + return (int)state;
8.984 +}
8.985 +
8.986 +
8.987 +/********************************* GLUI_Main::restore_draw_buffer() **********/
8.988 +
8.989 +void GLUI_Main::restore_draw_buffer( int buffer_state )
8.990 +{
8.991 + glDrawBuffer( buffer_state );
8.992 +}
8.993 +
8.994 +
8.995 +/******************************************** GLUI_Main::GLUI_Main() ********/
8.996 +
8.997 +GLUI_Main::GLUI_Main( void )
8.998 +{
8.999 + mouse_button_down = false;
8.1000 + w = 0;
8.1001 + h = 0;
8.1002 + active_control = NULL;
8.1003 + mouse_over_control = NULL;
8.1004 + main_gfx_window_id = -1;
8.1005 + glut_window_id = -1;
8.1006 + curr_modifiers = 0;
8.1007 + closing = false;
8.1008 + parent_window = -1;
8.1009 + glui_id = GLUI_Master.glui_id_counter;
8.1010 + GLUI_Master.glui_id_counter++;
8.1011 +
8.1012 + font = GLUT_BITMAP_HELVETICA_12;
8.1013 + curr_cursor = GLUT_CURSOR_LEFT_ARROW;
8.1014 +
8.1015 + bkgd_color.set( 200, 200, 200 );
8.1016 + bkgd_color_f[0] = 200.0 / 255.0;
8.1017 + bkgd_color_f[1] = 200.0 / 255.0;
8.1018 + bkgd_color_f[2] = 200.0 / 255.0;
8.1019 +
8.1020 + /*** Create the main panel ***/
8.1021 + main_panel = new GLUI_Panel;
8.1022 + main_panel->set_int_val( GLUI_PANEL_NONE );
8.1023 + main_panel->glui = (GLUI*) this;
8.1024 + main_panel->name = "\0";
8.1025 +}
8.1026 +
8.1027 +/************************************ GLUI_Main::draw_raised_box() **********/
8.1028 +
8.1029 +void GLUI_Main::draw_raised_box( int x, int y, int w, int h )
8.1030 +{
8.1031 + w = w+x;
8.1032 + h = h+y;
8.1033 +
8.1034 + glColor3ub( bkgd_color.r, bkgd_color.g, bkgd_color.b );
8.1035 + glBegin( GL_LINE_LOOP );
8.1036 + glVertex2i( x+1, y+1 ); glVertex2i( w-1, y+1 );
8.1037 + glVertex2i( w-1, h-1 ); glVertex2i( x+1, h-1 );
8.1038 + glEnd();
8.1039 +
8.1040 + glColor3d( 1.0, 1.0, 1.0 );
8.1041 + glBegin( GL_LINE_STRIP );
8.1042 + glVertex2i( x, h ); glVertex2i( x, y ); glVertex2i( w, y );
8.1043 + glEnd();
8.1044 +
8.1045 + glColor3d( 0.0, 0.0, 0.0 );
8.1046 + glBegin( GL_LINE_STRIP );
8.1047 + glVertex2i( w, y ); glVertex2i( w, h ); glVertex2i( x, h );
8.1048 + glEnd();
8.1049 +
8.1050 + glColor3d( .5, .5, .5 );
8.1051 + glBegin( GL_LINE_STRIP );
8.1052 + glVertex2i( w-1, y+1 ); glVertex2i( w-1, h-1 ); glVertex2i( x+1, h-1 );
8.1053 + glEnd();
8.1054 +}
8.1055 +
8.1056 +
8.1057 +/************************************ GLUI_Main::draw_lowered_box() **********/
8.1058 +/* Not quite perfect... **/
8.1059 +
8.1060 +void GLUI_Main::draw_lowered_box( int x, int y, int w, int h )
8.1061 +{
8.1062 + w = w+x;
8.1063 + h = h+y;
8.1064 +
8.1065 + glColor3ub( bkgd_color.r, bkgd_color.g, bkgd_color.b );
8.1066 + glBegin( GL_LINE_LOOP );
8.1067 + glVertex2i( x+1, y+1 ); glVertex2i( w-1, y+1 );
8.1068 + glVertex2i( w-1, h-1 ); glVertex2i( x+1, h-1 );
8.1069 + glEnd();
8.1070 +
8.1071 + glColor3d( 0.0, 0.0, 0.0 );
8.1072 + glBegin( GL_LINE_STRIP );
8.1073 + glVertex2i( x, h ); glVertex2i( x, y ); glVertex2i( w, y );
8.1074 + glEnd();
8.1075 +
8.1076 + glColor3d( 1.0, 1.0, 1.0 );
8.1077 + glBegin( GL_LINE_STRIP );
8.1078 + glVertex2i( w, y ); glVertex2i( w, h ); glVertex2i( x, h );
8.1079 + glEnd();
8.1080 +
8.1081 + glColor3d( .5, .5, .5 );
8.1082 + glBegin( GL_LINE_STRIP );
8.1083 + glVertex2i( w-1, y+1 ); glVertex2i( w-1, h-1 ); glVertex2i( x+1, h-1 );
8.1084 + glEnd();
8.1085 +}
8.1086 +
8.1087 +
8.1088 +/************************************* GLUI_Main::activate_control() *********/
8.1089 +
8.1090 +void GLUI_Main::activate_control( GLUI_Control *control, int how )
8.1091 +{
8.1092 + /** Are we not activating a control in the same window as the
8.1093 + previous active control? */
8.1094 + if ( GLUI_Master.active_control_glui AND
8.1095 + this != (GLUI_Main*) GLUI_Master.active_control_glui ) {
8.1096 + GLUI_Master.active_control_glui->disactivate_current_control();
8.1097 + }
8.1098 +
8.1099 + /******* Now activate it *****/
8.1100 + if ( control != NULL AND control->can_activate AND control->enabled ) {
8.1101 + active_control = control;
8.1102 +
8.1103 + control->activate(how);
8.1104 +
8.1105 + /*if ( NOT active_control->is_container OR */
8.1106 + /* active_control->type == GLUI_CONTROL_ROLLOUT) { */
8.1107 + active_control->translate_and_draw_front();
8.1108 + /*} */
8.1109 + }
8.1110 + else {
8.1111 + active_control = NULL;
8.1112 + }
8.1113 +
8.1114 + /* printf( "activate: %d\n", glutGetWindow() ); */
8.1115 + GLUI_Master.active_control = active_control;
8.1116 + GLUI_Master.active_control_glui = (GLUI*) this;
8.1117 +}
8.1118 +
8.1119 +
8.1120 +/************************* GLUI_Main::disactivate_current_control() **********/
8.1121 +
8.1122 +void GLUI_Main::disactivate_current_control( void )
8.1123 +{
8.1124 + int orig;
8.1125 +
8.1126 + if ( active_control != NULL ) {
8.1127 + orig = active_control->set_to_glut_window();
8.1128 +
8.1129 + active_control->disactivate();
8.1130 +
8.1131 + /** If this isn't a container control, then redraw it in its
8.1132 + disactivated state. Container controls, such as panels, look
8.1133 + the same activated or not **/
8.1134 +
8.1135 + /*if ( NOT active_control->is_container OR */
8.1136 + /* active_control->type == GLUI_CONTROL_ROLLOUT ) { */
8.1137 + active_control->translate_and_draw_front();
8.1138 + /*} */
8.1139 +
8.1140 + active_control->restore_window( orig );
8.1141 +
8.1142 + active_control = NULL;
8.1143 + }
8.1144 +
8.1145 + /* printf( "disactivate: %d\n", glutGetWindow() ); */
8.1146 + GLUI_Master.active_control = NULL;
8.1147 + GLUI_Master.active_control_glui = NULL;
8.1148 +}
8.1149 +
8.1150 +
8.1151 +/****************************** GLUI_Main::find_next_control() **************/
8.1152 +
8.1153 +GLUI_Control *GLUI_Main::find_next_control_( GLUI_Control *control )
8.1154 +{
8.1155 + /*** THIS IS NOT find_next_control()! This is an unused older
8.1156 + version (look at the underscore at the end) ***/
8.1157 +
8.1158 + if ( control == NULL )
8.1159 + return find_next_control_rec( main_panel );
8.1160 + else
8.1161 + return find_next_control_rec( control );
8.1162 +}
8.1163 +
8.1164 +/****************************** GLUI_Main::find_next_control() **************/
8.1165 +
8.1166 +GLUI_Control *GLUI_Main::find_next_control_rec( GLUI_Control *control )
8.1167 +{
8.1168 + GLUI_Control *child = NULL, *rec_control, *sibling;
8.1169 +
8.1170 + /*** Recursively investigate children ***/
8.1171 + child = (GLUI_Control*) control->first_child();
8.1172 + if ( child ) {
8.1173 + /*** If we can activate the first child, then do so ***/
8.1174 + if ( child->can_activate AND child->enabled )
8.1175 + return child;
8.1176 + else /*** Recurse into first child ***/
8.1177 + rec_control = find_next_control_rec( child );
8.1178 +
8.1179 + if ( rec_control )
8.1180 + return rec_control;
8.1181 + }
8.1182 +
8.1183 + /*** At this point, either we don't have children, or the child cannot
8.1184 + be activated. So let's try the next sibling ***/
8.1185 +
8.1186 + sibling = (GLUI_Control*) control->next();
8.1187 + if ( sibling ) {
8.1188 + if ( sibling->can_activate AND sibling->enabled )
8.1189 + return sibling;
8.1190 + else /*** Recurse into sibling ***/
8.1191 + rec_control = find_next_control_rec( sibling );
8.1192 +
8.1193 + if ( rec_control )
8.1194 + return rec_control;
8.1195 + }
8.1196 +
8.1197 + return NULL;
8.1198 +}
8.1199 +
8.1200 +
8.1201 +/****************************** GLUI_Main::find_next_control() **************/
8.1202 +
8.1203 +GLUI_Control *GLUI_Main::find_next_control( GLUI_Control *control )
8.1204 +{
8.1205 + GLUI_Control *tmp_control = NULL;
8.1206 + int back_up;
8.1207 +
8.1208 + if ( control == NULL )
8.1209 + control = main_panel;
8.1210 +
8.1211 + while( control != NULL ) {
8.1212 + /** see if this control has a child **/
8.1213 + tmp_control = (GLUI_Control*) control->first_child();
8.1214 +
8.1215 + if ( tmp_control != NULL ) {
8.1216 + if ( tmp_control->can_activate AND tmp_control->enabled )
8.1217 + return tmp_control;
8.1218 +
8.1219 + control = tmp_control; /* Descend into child */
8.1220 + continue;
8.1221 + }
8.1222 +
8.1223 + /*** At this point, control has no children ***/
8.1224 +
8.1225 + /** see if this control has a next sibling **/
8.1226 + tmp_control = (GLUI_Control*) control->next();
8.1227 +
8.1228 + if ( tmp_control != NULL ) {
8.1229 + if ( tmp_control->can_activate AND tmp_control->enabled )
8.1230 + return tmp_control;
8.1231 +
8.1232 + control = tmp_control;
8.1233 + continue;
8.1234 + }
8.1235 +
8.1236 + /** back up until we find a sibling of an ancestor **/
8.1237 + back_up = true;
8.1238 + while ( control->parent() AND back_up ) {
8.1239 + control = (GLUI_Control*) control->parent();
8.1240 +
8.1241 + if ( control->next() ) {
8.1242 + control = (GLUI_Control*) control->next();
8.1243 + if ( control->can_activate AND control->enabled )
8.1244 + return control;
8.1245 + else
8.1246 + back_up = false;
8.1247 +
8.1248 + /*** if ( control->is_container ) {
8.1249 + tmp_control = control;
8.1250 + control = NULL;
8.1251 + break;
8.1252 + }
8.1253 + else {
8.1254 + back_up = false;
8.1255 + }
8.1256 + ***/
8.1257 + }
8.1258 + }
8.1259 +
8.1260 + /** Check if we've cycled back to the top... if so, return NULL **/
8.1261 + if ( control == main_panel ) {
8.1262 + return NULL;
8.1263 + }
8.1264 + }
8.1265 + /*
8.1266 + if ( tmp_control != NULL AND tmp_control->can_activate AND
8.1267 + tmp_control->enabled ) {
8.1268 + return tmp_control;
8.1269 + }*/
8.1270 +
8.1271 + return NULL;
8.1272 +}
8.1273 +
8.1274 +
8.1275 +/****************************** GLUI_Main::find_prev_control() **************/
8.1276 +
8.1277 +GLUI_Control *GLUI_Main::find_prev_control( GLUI_Control *control )
8.1278 +{
8.1279 + GLUI_Control *tmp_control, *next_control;
8.1280 +
8.1281 + if ( control == NULL ) { /* here we find the last valid control */
8.1282 + next_control = main_panel;
8.1283 +
8.1284 + do {
8.1285 + tmp_control = next_control;
8.1286 + next_control = find_next_control( tmp_control );
8.1287 + } while( next_control != NULL );
8.1288 +
8.1289 + return tmp_control;
8.1290 + }
8.1291 + else { /* here we find the actual previous control */
8.1292 + next_control = main_panel;
8.1293 +
8.1294 + do {
8.1295 + tmp_control = next_control;
8.1296 + next_control = find_next_control( tmp_control );
8.1297 + } while( next_control != NULL AND next_control != control );
8.1298 +
8.1299 + if ( next_control == NULL OR tmp_control == main_panel )
8.1300 + return NULL;
8.1301 + else
8.1302 + return tmp_control;
8.1303 + }
8.1304 +}
8.1305 +
8.1306 +/************************* GLUI_Master_Object::set_glutIdleFunc() ***********/
8.1307 +
8.1308 +void GLUI_Master_Object::set_glutIdleFunc(void (*f)(void))
8.1309 +{
8.1310 + glut_idle_CB = f;
8.1311 + glutIdleFunc( glui_idle_func );
8.1312 +}
8.1313 +
8.1314 +
8.1315 +/**************************************** GLUI::disable() ********************/
8.1316 +
8.1317 +void GLUI::disable( void )
8.1318 +{
8.1319 + disactivate_current_control();
8.1320 + main_panel->disable();
8.1321 +}
8.1322 +
8.1323 +
8.1324 +/******************************************** GLUI::sync_live() **************/
8.1325 +
8.1326 +void GLUI::sync_live( void )
8.1327 +{
8.1328 + main_panel->sync_live(true, true);
8.1329 +}
8.1330 +
8.1331 +
8.1332 +/********************************* GLUI_Master_Object::sync_live_all() *****/
8.1333 +
8.1334 +void GLUI_Master_Object::sync_live_all( void )
8.1335 +{
8.1336 + GLUI *glui;
8.1337 +
8.1338 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1339 + while( glui ) {
8.1340 +
8.1341 + glui->sync_live(); /** sync it **/
8.1342 +
8.1343 + glui = (GLUI*) glui->next();
8.1344 + }
8.1345 +}
8.1346 +
8.1347 +
8.1348 +/************************************* GLUI_Master_Object::close() **********/
8.1349 +
8.1350 +void GLUI_Master_Object::close_all( void )
8.1351 +{
8.1352 + GLUI *glui;
8.1353 +
8.1354 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1355 + while( glui ) {
8.1356 +
8.1357 + glui->close(); /** Set flag to close **/
8.1358 +
8.1359 + glui = (GLUI*) glui->next();
8.1360 + }
8.1361 +}
8.1362 +
8.1363 +
8.1364 +/************************************* GLUI_Main::close_internal() **********/
8.1365 +
8.1366 +void GLUI_Main::close_internal( void )
8.1367 +{
8.1368 + glutDestroyWindow(glutGetWindow()); /** Close this window **/
8.1369 +
8.1370 + this->unlink();
8.1371 +
8.1372 + if ( GLUI_Master.active_control_glui == this ) {
8.1373 + GLUI_Master.active_control = NULL;
8.1374 + GLUI_Master.active_control_glui = NULL;
8.1375 + }
8.1376 +
8.1377 + if ( parent_window != -1 ) {
8.1378 + glutSetWindow( parent_window );
8.1379 + int win_w = glutGet( GLUT_WINDOW_WIDTH );
8.1380 + int win_h = glutGet( GLUT_WINDOW_HEIGHT );
8.1381 + glutReshapeWindow(win_w+1, win_h);
8.1382 + glutReshapeWindow(win_w-1, win_h);
8.1383 + }
8.1384 +
8.1385 + delete this->main_panel;
8.1386 +
8.1387 + delete this;
8.1388 +}
8.1389 +
8.1390 +
8.1391 +/************************************************** GLUI::close() **********/
8.1392 +
8.1393 +void GLUI::close( void )
8.1394 +{
8.1395 + int old_glut_window;
8.1396 +
8.1397 + closing = true;
8.1398 +
8.1399 + old_glut_window = glutGetWindow();
8.1400 + glutSetWindow( get_glut_window_id() );
8.1401 + glutPostRedisplay();
8.1402 +
8.1403 + glutSetWindow( old_glut_window );
8.1404 +}
8.1405 +
8.1406 +
8.1407 +/************************** GLUI_Main::check_subwindow_position() **********/
8.1408 +
8.1409 +void GLUI_Main::check_subwindow_position( void )
8.1410 +{
8.1411 + /*** Reposition this window if subwindow ***/
8.1412 + if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
8.1413 +
8.1414 + int parent_w, parent_h, new_x, new_y;
8.1415 + int old_window = glutGetWindow();
8.1416 +
8.1417 + glutSetWindow( glut_window_id );
8.1418 +
8.1419 + glutSetWindow( glutGet( GLUT_WINDOW_PARENT ));
8.1420 + parent_w = glutGet( GLUT_WINDOW_WIDTH );
8.1421 + parent_h = glutGet( GLUT_WINDOW_HEIGHT );
8.1422 +
8.1423 + glutSetWindow( glut_window_id );
8.1424 +
8.1425 + if ( TEST_AND(this->flags,GLUI_SUBWINDOW_RIGHT )) {
8.1426 + new_x = parent_w - this->w;
8.1427 + new_y = 0;
8.1428 + }
8.1429 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_LEFT )) {
8.1430 + new_x = 0;
8.1431 + new_y = 0;
8.1432 + }
8.1433 + else if ( TEST_AND(this->flags,GLUI_SUBWINDOW_BOTTOM )) {
8.1434 + new_x = 0;
8.1435 + new_y = parent_h - this->h;
8.1436 + }
8.1437 + else { /*** GLUI_SUBWINDOW_TOP ***/
8.1438 + new_x = 0;
8.1439 + new_y = 0;
8.1440 + }
8.1441 +
8.1442 + /** Now make adjustments based on presence of other subwindows **/
8.1443 + GLUI *curr_glui;
8.1444 + curr_glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1445 + while( curr_glui ) {
8.1446 + if ( TEST_AND( curr_glui->flags, GLUI_SUBWINDOW) AND
8.1447 + curr_glui->parent_window == this->parent_window ) {
8.1448 +
8.1449 + if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
8.1450 + }
8.1451 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
8.1452 + }
8.1453 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
8.1454 + }
8.1455 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) AND
8.1456 + ( TEST_AND( this->flags,GLUI_SUBWINDOW_LEFT ) OR
8.1457 + TEST_AND( this->flags,GLUI_SUBWINDOW_RIGHT ) ) ) {
8.1458 + /** If we are a RIGHT or LEFT subwindow, and there exists some
8.1459 + TOP subwindow, bump our position down **/
8.1460 +
8.1461 + new_y += curr_glui->h;
8.1462 + }
8.1463 +
8.1464 + /** CHeck multiple subwins at same position **/
8.1465 + /** We check the glui_id's: only the glui with the higher
8.1466 + ID number (meaning it was created later) gets bumped over **/
8.1467 + if ( curr_glui != this AND this->glui_id > curr_glui->glui_id ) {
8.1468 + if ( TEST_AND( this->flags,GLUI_SUBWINDOW_LEFT ) AND
8.1469 + TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
8.1470 + new_x += curr_glui->w;
8.1471 + }
8.1472 + else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_TOP ) AND
8.1473 + TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) ) {
8.1474 + new_y += curr_glui->h;
8.1475 + }
8.1476 + else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_BOTTOM ) AND
8.1477 + TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
8.1478 + new_y -= curr_glui->h;
8.1479 + }
8.1480 + else if ( TEST_AND( this->flags,GLUI_SUBWINDOW_RIGHT ) AND
8.1481 + TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
8.1482 + new_x -= curr_glui->w;
8.1483 + }
8.1484 +
8.1485 + }
8.1486 + }
8.1487 +
8.1488 + curr_glui = (GLUI*) curr_glui->next();
8.1489 + }
8.1490 +
8.1491 +
8.1492 +
8.1493 + CLAMP( new_x, 0, new_x );
8.1494 + CLAMP( new_y, 0, new_y );
8.1495 +
8.1496 + glutPositionWindow( new_x, new_y );
8.1497 + /* glutPostRedisplay(); */
8.1498 +
8.1499 + glutSetWindow( old_window );
8.1500 + }
8.1501 +}
8.1502 +
8.1503 +
8.1504 +/********************************* GLUI_Master_Object::reshape() **********/
8.1505 +/* This gets called by the user from a GLUT reshape callback. So we look */
8.1506 +/* for subwindows that belong to the current window */
8.1507 +
8.1508 +void GLUI_Master_Object::reshape( void )
8.1509 +{
8.1510 + GLUI *glui;
8.1511 + int current_window;
8.1512 +
8.1513 + current_window = glutGetWindow();
8.1514 +
8.1515 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1516 + while( glui ) {
8.1517 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.1518 + glui->parent_window == current_window ) {
8.1519 + glutSetWindow( glui->get_glut_window_id());
8.1520 + glui->check_subwindow_position();
8.1521 + }
8.1522 +
8.1523 + glui = (GLUI*) glui->next();
8.1524 + }
8.1525 +
8.1526 + glutSetWindow(current_window);
8.1527 +}
8.1528 +
8.1529 +
8.1530 +/**************************** GLUI_Master_Object::set_glutReshapeFunc() *****/
8.1531 +
8.1532 +void GLUI_Master_Object::set_glutReshapeFunc(void (*f)(int width, int height))
8.1533 +{
8.1534 + glutReshapeFunc( glui_reshape_func );
8.1535 + add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_RESHAPE, (void*) f);
8.1536 +}
8.1537 +
8.1538 +
8.1539 +/**************************** GLUI_Master_Object::set_glutKeyboardFunc() ****/
8.1540 +
8.1541 +void GLUI_Master_Object::set_glutKeyboardFunc(void (*f)(unsigned char key,
8.1542 + int x, int y))
8.1543 +{
8.1544 + glutKeyboardFunc( glui_keyboard_func );
8.1545 + add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_KEYBOARD, (void*) f);
8.1546 +}
8.1547 +
8.1548 +
8.1549 +/*********************** GLUI_Master_Object::set_glutSpecialFunc() **********/
8.1550 +
8.1551 +void GLUI_Master_Object::set_glutSpecialFunc(void (*f)(int key,
8.1552 + int x, int y))
8.1553 +{
8.1554 + glutSpecialFunc( glui_special_func );
8.1555 + add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_SPECIAL, (void*) f);
8.1556 +}
8.1557 +
8.1558 +
8.1559 +/*********************** GLUI_Master_Object::set_glutMouseFunc() **********/
8.1560 +
8.1561 +void GLUI_Master_Object::set_glutMouseFunc(void (*f)(int button, int state,
8.1562 + int x, int y))
8.1563 +{
8.1564 + glutMouseFunc( glui_mouse_func );
8.1565 + add_cb_to_glut_window( glutGetWindow(), GLUI_GLUT_MOUSE, (void*) f);
8.1566 +}
8.1567 +
8.1568 +
8.1569 +/****************************** glui_parent_window_reshape_func() **********/
8.1570 +/* This is the reshape callback for a window that contains subwindows */
8.1571 +
8.1572 +void glui_parent_window_reshape_func( int w, int h )
8.1573 +{
8.1574 + int current_window;
8.1575 + GLUI *glui;
8.1576 + int first = true;
8.1577 +
8.1578 + /* printf( "glui_parent_window_reshape_func: %d\n", glutGetWindow() ); */
8.1579 +
8.1580 + current_window = glutGetWindow();
8.1581 +
8.1582 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1583 + while( glui ) {
8.1584 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.1585 + glui->parent_window == current_window ) {
8.1586 + glutSetWindow( glui->get_glut_window_id());
8.1587 + glui->check_subwindow_position();
8.1588 + glutSetWindow( current_window );
8.1589 +
8.1590 + if ( first ) {
8.1591 + glui->glut_reshape_CB( w, h );
8.1592 +
8.1593 + first = false;
8.1594 + }
8.1595 + }
8.1596 +
8.1597 + glui = (GLUI*) glui->next();
8.1598 + }
8.1599 +}
8.1600 +
8.1601 +
8.1602 +/****************************** glui_parent_window_keyboard_func() **********/
8.1603 +
8.1604 +void glui_parent_window_keyboard_func(unsigned char key, int x, int y)
8.1605 +{
8.1606 + /* printf( "glui_parent_window_keyboard_func: %d\n", glutGetWindow() ); */
8.1607 +
8.1608 + int current_window;
8.1609 + GLUI *glui;
8.1610 +
8.1611 + current_window = glutGetWindow();
8.1612 +
8.1613 + if ( GLUI_Master.active_control_glui AND GLUI_Master.active_control ) {
8.1614 + glutSetWindow( GLUI_Master.active_control_glui->get_glut_window_id() );
8.1615 +
8.1616 + GLUI_Master.active_control_glui->keyboard(key,x,y);
8.1617 +
8.1618 + glutSetWindow( current_window );
8.1619 + }
8.1620 + else {
8.1621 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1622 + while( glui ) {
8.1623 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.1624 + glui->parent_window == current_window ) {
8.1625 + glui->glut_keyboard_CB( key, x, y );
8.1626 + break;
8.1627 + }
8.1628 +
8.1629 + glui = (GLUI*) glui->next();
8.1630 + }
8.1631 + }
8.1632 +}
8.1633 +
8.1634 +
8.1635 +/****************************** glui_parent_window_special_func() **********/
8.1636 +
8.1637 +void glui_parent_window_special_func(int key, int x, int y)
8.1638 +{
8.1639 + /*printf( "glui_parent_window_special_func: %d\n", glutGetWindow() ); */
8.1640 +
8.1641 + int current_window;
8.1642 + GLUI *glui;
8.1643 +
8.1644 + /** If clicking in the main area of a window w/subwindows,
8.1645 + disactivate any current control **/
8.1646 + if ( GLUI_Master.active_control_glui != NULL )
8.1647 + GLUI_Master.active_control_glui->disactivate_current_control();
8.1648 +
8.1649 + /*** Now pass on the mouse event ***/
8.1650 +
8.1651 + current_window = glutGetWindow();
8.1652 +
8.1653 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1654 + while( glui ) {
8.1655 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.1656 + glui->parent_window == current_window ) {
8.1657 + glutSetWindow( glui->get_glut_window_id());
8.1658 + glui->glut_special_CB( key, x, y );
8.1659 + break;
8.1660 + }
8.1661 +
8.1662 + glui = (GLUI*) glui->next();
8.1663 + }
8.1664 +}
8.1665 +
8.1666 +
8.1667 +/****************************** glui_parent_window_mouse_func() **********/
8.1668 +
8.1669 +void glui_parent_window_mouse_func(int button, int state, int x, int y)
8.1670 +{
8.1671 + int current_window;
8.1672 + GLUI *glui;
8.1673 +
8.1674 + /** If clicking in the main area of a window w/subwindows,
8.1675 + disactivate any current control **/
8.1676 + if ( GLUI_Master.active_control_glui != NULL )
8.1677 + GLUI_Master.active_control_glui->disactivate_current_control();
8.1678 +
8.1679 +
8.1680 + /*** Now pass on the mouse event ***/
8.1681 +
8.1682 + current_window = glutGetWindow();
8.1683 +
8.1684 + glui = (GLUI*) GLUI_Master.gluis.first_child();
8.1685 + while( glui ) {
8.1686 + if ( TEST_AND( glui->flags, GLUI_SUBWINDOW) AND
8.1687 + glui->parent_window == current_window ) {
8.1688 + glutSetWindow( glui->get_glut_window_id());
8.1689 + glui->glut_mouse_CB( button, state, x, y );
8.1690 + break;
8.1691 + }
8.1692 +
8.1693 + glui = (GLUI*) glui->next();
8.1694 + }
8.1695 +
8.1696 +}
8.1697 +
8.1698 +
8.1699 +/************************** GLUI_Master_Object::find_glut_window() **********/
8.1700 +
8.1701 +GLUI_Glut_Window *GLUI_Master_Object::find_glut_window( int window_id )
8.1702 +{
8.1703 + GLUI_Glut_Window *window;
8.1704 +
8.1705 + window = (GLUI_Glut_Window*) glut_windows.first_child();
8.1706 + while( window ) {
8.1707 + if ( window->glut_window_id == window_id )
8.1708 + return window;
8.1709 +
8.1710 + window = (GLUI_Glut_Window*) window->next();
8.1711 + }
8.1712 +
8.1713 + /*** Window not found - return NULL ***/
8.1714 + return NULL;
8.1715 +}
8.1716 +
8.1717 +
8.1718 +/******************** GLUI_Master_Object::add_cb_to_glut_window() **********/
8.1719 +
8.1720 +void GLUI_Master_Object::add_cb_to_glut_window(int window_id,
8.1721 + int cb_type,void *cb)
8.1722 +{
8.1723 + GLUI_Glut_Window *window;
8.1724 +
8.1725 + window = find_glut_window( window_id );
8.1726 + if ( NOT window ) {
8.1727 + /*** Allocate new window structure ***/
8.1728 +
8.1729 + window = new GLUI_Glut_Window;
8.1730 + window->glut_window_id = window_id;
8.1731 + window->link_this_to_parent_last( (GLUI_Node*) &this->glut_windows );
8.1732 + }
8.1733 +
8.1734 + switch( cb_type ) {
8.1735 + case GLUI_GLUT_RESHAPE:
8.1736 + window->glut_reshape_CB = (void(*)(int,int)) cb;
8.1737 + break;
8.1738 + case GLUI_GLUT_DISPLAY:
8.1739 + window->glut_display_CB = (void(*)()) cb;
8.1740 + break;
8.1741 + case GLUI_GLUT_KEYBOARD:
8.1742 + window->glut_keyboard_CB = (void(*)(unsigned char,int,int)) cb;
8.1743 + break;
8.1744 + case GLUI_GLUT_SPECIAL:
8.1745 + window->glut_special_CB = (void(*)(int,int,int)) cb;
8.1746 + break;
8.1747 + case GLUI_GLUT_MOUSE:
8.1748 + window->glut_mouse_CB = (void(*)(int,int,int,int)) cb;
8.1749 + break;
8.1750 + case GLUI_GLUT_MOTION:
8.1751 + window->glut_motion_CB = (void(*)(int,int)) cb;
8.1752 + break;
8.1753 + case GLUI_GLUT_PASSIVE_MOTION:
8.1754 + window->glut_passive_motion_CB = (void(*)(int,int)) cb;
8.1755 + break;
8.1756 + case GLUI_GLUT_ENTRY:
8.1757 + window->glut_entry_CB = (void(*)(int)) cb;
8.1758 + break;
8.1759 + case GLUI_GLUT_VISIBILITY:
8.1760 + window->glut_visibility_CB= (void(*)(int)) cb;
8.1761 + break;
8.1762 + }
8.1763 +}
8.1764 +
8.1765 +
8.1766 +/************* GLUI_Master_Object::set_left_button_glut_menu_control() *****/
8.1767 +
8.1768 +void GLUI_Master_Object::set_left_button_glut_menu_control(
8.1769 + GLUI_Control *control )
8.1770 +{
8.1771 + curr_left_button_glut_menu = control;
8.1772 +}
8.1773 +
8.1774 +
8.1775 +/******************************* GLUI_Main::set_ortho_projection() **********/
8.1776 +
8.1777 +void GLUI_Main::set_ortho_projection( void )
8.1778 +{
8.1779 + int win_h, win_w;
8.1780 +
8.1781 + win_w = glutGet( GLUT_WINDOW_WIDTH );
8.1782 + win_h = glutGet( GLUT_WINDOW_HEIGHT );
8.1783 +
8.1784 + glMatrixMode( GL_PROJECTION );
8.1785 + glLoadIdentity();
8.1786 + /* gluOrtho2D( 0.0, (float) win_w, 0.0, (float) win_h ); */
8.1787 + glOrtho( 0.0, (float)win_w, 0.0, (float) win_h, -1000.0, 1000.0 );
8.1788 +
8.1789 + glMatrixMode( GL_MODELVIEW );
8.1790 +
8.1791 + return; /****-----------------------------------------------***/
8.1792 +
8.1793 + glMatrixMode( GL_MODELVIEW );
8.1794 + glLoadIdentity();
8.1795 +
8.1796 + /*** Rotate image so y increases upwards, contrary to OpenGL axes ***/
8.1797 + glTranslatef( (float) win_w/2.0, (float) win_h/2.0, 0.0 );
8.1798 + glRotatef( 180.0, 0.0, 1.0, 0.0 );
8.1799 + glRotatef( 180.0, 0.0, 0.0, 1.0 );
8.1800 + glTranslatef( (float) -win_w/2.0, (float) -win_h/2.0, 0.0 );
8.1801 +}
8.1802 +
8.1803 +
8.1804 +/******************************* GLUI_Main::set_viewport() **********/
8.1805 +
8.1806 +void GLUI_Main::set_viewport( void )
8.1807 +{
8.1808 + glViewport( 0, 0, main_panel->w, main_panel->h );
8.1809 +}
8.1810 +
8.1811 +
8.1812 +/****************************** GLUI_Main::refresh() ****************/
8.1813 +
8.1814 +void GLUI_Main::refresh( void )
8.1815 +{
8.1816 + int orig;
8.1817 + int new_w, new_h;
8.1818 +
8.1819 + /****** GLUI_Glut_Window *glut_window;
8.1820 + int current_window;
8.1821 + current_window = glutGetWindow();
8.1822 + glut_window = GLUI_Master.find_glut_window( current_window );
8.1823 + if ( glut_window ) {
8.1824 + glut_window->glut_reshape_CB(w,h);
8.1825 + ******/
8.1826 +
8.1827 + orig = glutGetWindow();
8.1828 +
8.1829 + pack_controls();
8.1830 +
8.1831 + if ( TEST_AND( this->flags, GLUI_SUBWINDOW ) ) {
8.1832 + /*** GLUI subwindow ***/
8.1833 +
8.1834 + check_subwindow_position();
8.1835 +
8.1836 + if ( glut_window_id > 0 )
8.1837 + glutSetWindow( glut_window_id );
8.1838 + glutPostRedisplay();
8.1839 +
8.1840 + /* printf( "top_level: %d\n", top_level_glut_window_id );*/
8.1841 + glutSetWindow( top_level_glut_window_id );
8.1842 + }
8.1843 + else {
8.1844 + /*** Standalone GLUI window ***/
8.1845 +
8.1846 + if ( glut_window_id > 0 )
8.1847 + glutSetWindow( glut_window_id );
8.1848 +
8.1849 + new_h = glutGet( GLUT_WINDOW_HEIGHT );
8.1850 + new_w = glutGet( GLUT_WINDOW_WIDTH );
8.1851 +
8.1852 + new_h = this->h;
8.1853 + new_w = this->w;
8.1854 +
8.1855 + glutReshapeWindow( new_w, new_h );
8.1856 +
8.1857 + glutPostRedisplay();
8.1858 + }
8.1859 +
8.1860 + glutSetWindow( orig);
8.1861 +}
8.1862 +
8.1863 +
8.1864 +
8.1865 +/***************** GLUI_Master_Object::get_main_gfx_viewport() ***********/
8.1866 +
8.1867 +void GLUI_Master_Object::get_viewport_area( int *x, int *y,
8.1868 + int *w, int *h )
8.1869 +{
8.1870 + GLUI *curr_glui;
8.1871 + int curr_x, curr_y, curr_w, curr_h;
8.1872 + int curr_window;
8.1873 +
8.1874 + curr_window = glutGetWindow();
8.1875 + curr_x = 0;
8.1876 + curr_y = 0;
8.1877 + curr_w = glutGet( GLUT_WINDOW_WIDTH );
8.1878 + curr_h = glutGet( GLUT_WINDOW_HEIGHT );
8.1879 +
8.1880 + curr_glui = (GLUI*) gluis.first_child();
8.1881 + while( curr_glui ) {
8.1882 + if ( TEST_AND( curr_glui->flags, GLUI_SUBWINDOW) AND
8.1883 + curr_glui->parent_window == curr_window ) {
8.1884 +
8.1885 + /* printf( "%s -> %d %d %d\n", curr_glui->window_name.string, curr_glui->flags,
8.1886 + curr_glui->w, curr_glui->h );*/
8.1887 +
8.1888 + if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_LEFT ) ) {
8.1889 + curr_x += curr_glui->w;
8.1890 + curr_w -= curr_glui->w;
8.1891 + }
8.1892 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_BOTTOM ) ) {
8.1893 + curr_y += curr_glui->h;
8.1894 + curr_h -= curr_glui->h;
8.1895 + }
8.1896 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_RIGHT ) ) {
8.1897 + curr_w -= curr_glui->w;
8.1898 + }
8.1899 + else if ( TEST_AND( curr_glui->flags,GLUI_SUBWINDOW_TOP ) ) {
8.1900 + curr_h -= curr_glui->h;
8.1901 + }
8.1902 + }
8.1903 +
8.1904 + curr_glui = (GLUI*) curr_glui->next();
8.1905 + }
8.1906 +
8.1907 + curr_x = MAX( 0, curr_x );
8.1908 + curr_y = MAX( 0, curr_y );
8.1909 + curr_w = MAX( 0, curr_w );
8.1910 + curr_h = MAX( 0, curr_h );
8.1911 +
8.1912 + *x = curr_x;
8.1913 + *y = curr_y;
8.1914 + *w = curr_w;
8.1915 + *h = curr_h;
8.1916 +}
8.1917 +
8.1918 +
8.1919 +/*****************GLUI_Master_Object::auto_set_main_gfx_viewport() **********/
8.1920 +
8.1921 +void GLUI_Master_Object::auto_set_viewport( void )
8.1922 +{
8.1923 + int x, y, w, h;
8.1924 +
8.1925 + get_viewport_area( &x, &y, &w, &h );
8.1926 + glViewport( MAX(x,0), MAX(y,0), MAX(w,0), MAX(h,0) );
8.1927 +}
8.1928 +
8.1929 +
8.1930 +
8.1931 +/***************************************** GLUI::show() **********************/
8.1932 +
8.1933 +void GLUI::show( void )
8.1934 +{
8.1935 + int orig_window;
8.1936 +
8.1937 + orig_window = main_panel->set_to_glut_window();
8.1938 +
8.1939 + glutShowWindow();
8.1940 +
8.1941 + main_panel->restore_window(orig_window);
8.1942 +}
8.1943 +
8.1944 +
8.1945 +
8.1946 +/***************************************** GLUI::hide() **********************/
8.1947 +
8.1948 +void GLUI::hide( void )
8.1949 +{
8.1950 + int orig_window;
8.1951 +
8.1952 + this->disactivate_current_control();
8.1953 +
8.1954 + orig_window = main_panel->set_to_glut_window();
8.1955 +
8.1956 + glutHideWindow();
8.1957 +
8.1958 + main_panel->restore_window(orig_window);
8.1959 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/source/glui/glui.h Wed Nov 04 00:39:03 2009 +0000
9.3 @@ -0,0 +1,1694 @@
9.4 +/****************************************************************************
9.5 +
9.6 + GLUI User Interface Toolkit
9.7 + ---------------------------
9.8 +
9.9 + glui.h - Main header for GLUI User Interface Toolkit
9.10 +
9.11 +
9.12 + --------------------------------------------------
9.13 +
9.14 + Copyright (c) 1998 Paul Rademacher
9.15 +
9.16 + This program is freely distributable without licensing fees and is
9.17 + provided without guarantee or warrantee expressed or implied. This
9.18 + program is -not- in the public domain.
9.19 +
9.20 +*****************************************************************************/
9.21 +
9.22 +
9.23 +#ifndef _GLUI_H_
9.24 +#define _GLUI_H_
9.25 +
9.26 +#include <GL/glut.h>
9.27 +#include <stdlib.h>
9.28 +#include <stdio.h>
9.29 +#include <string.h>
9.30 +
9.31 +#define GLUI_VERSION 2.2f /********** Current version **********/
9.32 +
9.33 +#ifdef WIN32
9.34 +#pragma comment(lib, "glui32.lib") // Link against GLUI library
9.35 +#endif
9.36 +
9.37 +class Arcball;
9.38 +
9.39 +/********** Do some basic defines *******/
9.40 +#ifndef false
9.41 +#define true 1
9.42 +#define false 0
9.43 +#endif
9.44 +
9.45 +#ifndef Byte
9.46 +#define Byte unsigned char
9.47 +#endif
9.48 +
9.49 +#ifndef _RGBC_
9.50 +class RGBc {
9.51 +public:
9.52 + Byte r, g, b;
9.53 +
9.54 + void set(Byte r,Byte g,Byte b) {this->r=r;this->g=g;this->b=b;};
9.55 +
9.56 + RGBc( void ) {};
9.57 + RGBc( Byte r, Byte g, Byte b ) { set( r, g, b ); };
9.58 +};
9.59 +#define _RGBC_
9.60 +#endif
9.61 +
9.62 +/********** List of GLUT callbacks ********/
9.63 +
9.64 +enum GLUI_Glut_CB_Types {
9.65 + GLUI_GLUT_RESHAPE,
9.66 + GLUI_GLUT_KEYBOARD,
9.67 + GLUI_GLUT_DISPLAY,
9.68 + GLUI_GLUT_MOUSE,
9.69 + GLUI_GLUT_MOTION,
9.70 + GLUI_GLUT_SPECIAL,
9.71 + GLUI_GLUT_PASSIVE_MOTION,
9.72 + GLUI_GLUT_ENTRY,
9.73 + GLUI_GLUT_VISIBILITY
9.74 +};
9.75 +
9.76 +/********** List of control types **********/
9.77 +enum GLUI_Control_Types {
9.78 + GLUI_CONTROL_CHECKBOX =1,
9.79 + GLUI_CONTROL_BUTTON,
9.80 + GLUI_CONTROL_RADIOBUTTON,
9.81 + GLUI_CONTROL_RADIOGROUP,
9.82 + GLUI_CONTROL_SLIDER,
9.83 + GLUI_CONTROL_STATICTEXT,
9.84 + GLUI_CONTROL_EDITTEXT,
9.85 + GLUI_CONTROL_BITMAP,
9.86 + GLUI_CONTROL_PANEL,
9.87 + GLUI_CONTROL_SPINNER,
9.88 + GLUI_CONTROL_SEPARATOR,
9.89 + GLUI_CONTROL_COLUMN,
9.90 + GLUI_CONTROL_LISTBOX,
9.91 + GLUI_CONTROL_MOUSE_INTERACTION,
9.92 + GLUI_CONTROL_ROTATION,
9.93 + GLUI_CONTROL_TRANSLATION,
9.94 + GLUI_CONTROL_ROLLOUT
9.95 +};
9.96 +
9.97 +
9.98 +/********* Constants for window placement **********/
9.99 +#define GLUI_XOFF 6
9.100 +#define GLUI_YOFF 6
9.101 +#define GLUI_ITEMSPACING 3
9.102 +#define GLUI_CHECKBOX_SIZE 13
9.103 +#define GLUI_RADIOBUTTON_SIZE 13
9.104 +#define GLUI_BUTTON_SIZE 20
9.105 +#define GLUI_STATICTEXT_SIZE 13
9.106 +#define GLUI_SEPARATOR_HEIGHT 8
9.107 +#define GLUI_DEFAULT_CONTROL_WIDTH 100
9.108 +#define GLUI_DEFAULT_CONTROL_HEIGHT 13
9.109 +#define GLUI_EDITTEXT_BOXINNERMARGINX 3
9.110 +#define GLUI_EDITTEXT_HEIGHT 20
9.111 +#define GLUI_EDITTEXT_WIDTH 130
9.112 +#define GLUI_EDITTEXT_MIN_INT_WIDTH 35
9.113 +#define GLUI_EDITTEXT_MIN_TEXT_WIDTH 50
9.114 +#define GLUI_PANEL_NAME_DROP 8
9.115 +#define GLUI_PANEL_EMBOSS_TOP 4
9.116 +/* #define GLUI_ROTATION_WIDTH 60*/
9.117 +/* #define GLUI_ROTATION_HEIGHT 78 */
9.118 +#define GLUI_ROTATION_WIDTH 50
9.119 +#define GLUI_ROTATION_HEIGHT (GLUI_ROTATION_WIDTH+18)
9.120 +#define GLUI_MOUSE_INTERACTION_WIDTH 50
9.121 +#define GLUI_MOUSE_INTERACTION_HEIGHT (GLUI_MOUSE_INTERACTION_WIDTH)+18
9.122 +
9.123 +
9.124 +/** Different panel control types **/
9.125 +#define GLUI_PANEL_NONE 0
9.126 +#define GLUI_PANEL_EMBOSSED 1
9.127 +#define GLUI_PANEL_RAISED 2
9.128 +
9.129 +
9.130 +/** Max # of els in control's float_array **/
9.131 +#define GLUI_DEF_MAX_ARRAY 30
9.132 +
9.133 +/********* The control's 'active' behavior *********/
9.134 +#define GLUI_CONTROL_ACTIVE_MOUSEDOWN 1
9.135 +#define GLUI_CONTROL_ACTIVE_PERMANENT 2
9.136 +
9.137 +
9.138 +/********* Control alignment types **********/
9.139 +#define GLUI_ALIGN_CENTER 1
9.140 +#define GLUI_ALIGN_RIGHT 2
9.141 +#define GLUI_ALIGN_LEFT 3
9.142 +
9.143 +
9.144 +/********** Limit types - how to limit spinner values *********/
9.145 +#define GLUI_LIMIT_NONE 0
9.146 +#define GLUI_LIMIT_CLAMP 1
9.147 +#define GLUI_LIMIT_WRAP 2
9.148 +
9.149 +
9.150 +/********** Translation control types ********************/
9.151 +
9.152 +#define GLUI_TRANSLATION_XY 0
9.153 +#define GLUI_TRANSLATION_Z 1
9.154 +#define GLUI_TRANSLATION_X 2
9.155 +#define GLUI_TRANSLATION_Y 3
9.156 +
9.157 +#define GLUI_TRANSLATION_LOCK_NONE 0
9.158 +#define GLUI_TRANSLATION_LOCK_X 1
9.159 +#define GLUI_TRANSLATION_LOCK_Y 2
9.160 +
9.161 +/********** How was a control activated? *****************/
9.162 +#define GLUI_ACTIVATE_MOUSE 1
9.163 +#define GLUI_ACTIVATE_TAB 2
9.164 +
9.165 +
9.166 +/********** What type of live variable does a control have? **********/
9.167 +#define GLUI_LIVE_NONE 0
9.168 +#define GLUI_LIVE_INT 1
9.169 +#define GLUI_LIVE_FLOAT 2
9.170 +#define GLUI_LIVE_TEXT 3
9.171 +#define GLUI_LIVE_DOUBLE 4
9.172 +#define GLUI_LIVE_FLOAT_ARRAY 5
9.173 +
9.174 +
9.175 +/********** Translation codes **********/
9.176 +
9.177 +enum TranslationCodes {
9.178 + GLUI_TRANSLATION_MOUSE_NONE=0,
9.179 + GLUI_TRANSLATION_MOUSE_UP,
9.180 + GLUI_TRANSLATION_MOUSE_DOWN,
9.181 + GLUI_TRANSLATION_MOUSE_LEFT,
9.182 + GLUI_TRANSLATION_MOUSE_RIGHT,
9.183 + GLUI_TRANSLATION_MOUSE_UP_LEFT,
9.184 + GLUI_TRANSLATION_MOUSE_UP_RIGHT,
9.185 + GLUI_TRANSLATION_MOUSE_DOWN_LEFT,
9.186 + GLUI_TRANSLATION_MOUSE_DOWN_RIGHT
9.187 +};
9.188 +
9.189 +/************ A string type for us to use **********/
9.190 +/* typedef char GLUI_String[300]; */
9.191 +class GLUI_String
9.192 +{
9.193 +public:
9.194 + char string[300];
9.195 +
9.196 + char &operator[]( int i ) {
9.197 + return string[i];
9.198 + }
9.199 +
9.200 + operator char*() { return (char*) &string[0]; };
9.201 + /* operator void*() { return (void*) &string[0]; }; */
9.202 +
9.203 + GLUI_String( void ) {
9.204 + string[0] = '\0';
9.205 + }
9.206 +
9.207 + GLUI_String( char *text ) {
9.208 + strcpy( string, text );
9.209 + }
9.210 +};
9.211 +
9.212 +
9.213 +/********* Pre-declare the various classes *********/
9.214 +class GLUI;
9.215 +class GLUI_Control;
9.216 +class GLUI_Listbox;
9.217 +class GLUI_Rotation;
9.218 +class GLUI_Translation;
9.219 +class GLUI_Mouse_Interaction;
9.220 +class GLUI_Checkbox;
9.221 +class GLUI_Slider;
9.222 +class GLUI_Button;
9.223 +class GLUI_StaticText;
9.224 +class GLUI_Bitmap;
9.225 +class GLUI_EditText;
9.226 +class GLUI_Node;
9.227 +class GLUI_Main;
9.228 +class GLUI_Panel;
9.229 +class GLUI_Spinner;
9.230 +class GLUI_RadioButton;
9.231 +class GLUI_RadioGroup;
9.232 +class GLUI_Separator;
9.233 +class GLUI_Column;
9.234 +class GLUI_Master;
9.235 +class GLUI_Glut_Window;
9.236 +class GLUI_Rollout;
9.237 +
9.238 +
9.239 +
9.240 +/*** Flags for GLUI class constructor ***/
9.241 +#define GLUI_SUBWINDOW ((long)(1<< 1))
9.242 +#define GLUI_SUBWINDOW_TOP ((long)(1<< 2))
9.243 +#define GLUI_SUBWINDOW_BOTTOM ((long)(1<< 3))
9.244 +#define GLUI_SUBWINDOW_LEFT ((long)(1<< 4))
9.245 +#define GLUI_SUBWINDOW_RIGHT ((long)(1<< 5))
9.246 +
9.247 +/*** Codes for different type of edittext boxes and spinners ***/
9.248 +#define GLUI_EDITTEXT_TEXT 1
9.249 +#define GLUI_EDITTEXT_INT 2
9.250 +#define GLUI_EDITTEXT_FLOAT 3
9.251 +#define GLUI_SPINNER_INT GLUI_EDITTEXT_INT
9.252 +#define GLUI_SPINNER_FLOAT GLUI_EDITTEXT_FLOAT
9.253 +
9.254 +
9.255 +
9.256 +/*** Definition of callbacks ***/
9.257 +typedef void (*GLUI_Update_CB) (int id);
9.258 +typedef void (*Int1_CB) (int);
9.259 +typedef void (*Int2_CB) (int, int);
9.260 +typedef void (*Int3_CB) (int, int, int);
9.261 +typedef void (*Int4_CB) (int, int, int, int);
9.262 +
9.263 +
9.264 +
9.265 +/************************************************************/
9.266 +/* */
9.267 +/* Base class, for hierarchical relationships */
9.268 +/* */
9.269 +/************************************************************/
9.270 +
9.271 +class GLUI_Node {
9.272 +protected:
9.273 + GLUI_Node *parent_node;
9.274 + GLUI_Node *child_head;
9.275 + GLUI_Node *child_tail;
9.276 + GLUI_Node *next_sibling;
9.277 + GLUI_Node *prev_sibling;
9.278 +
9.279 +public:
9.280 + GLUI_Node *first_sibling( void );
9.281 + GLUI_Node *last_sibling( void );
9.282 + GLUI_Node *prev( void );
9.283 + GLUI_Node *next( void );
9.284 + GLUI_Node *first_child( void ) { return child_head; };
9.285 + GLUI_Node *last_child( void ) { return child_tail; };
9.286 + GLUI_Node *parent(void) { return parent_node; };
9.287 +
9.288 + void link_this_to_parent_last( GLUI_Node *parent );
9.289 + void link_this_to_parent_first( GLUI_Node *parent );
9.290 + void link_this_to_sibling_next( GLUI_Node *sibling );
9.291 + void link_this_to_sibling_prev( GLUI_Node *sibling );
9.292 + void unlink( void );
9.293 +
9.294 + void dump( FILE *out, char *name ) {
9.295 + fprintf( out, "GLUI_node: %s\n", name );
9.296 + fprintf( out, " parent: %p child_head: %p child_tail: %p\n",
9.297 + parent_node, child_head, child_tail );
9.298 + fprintf( out, " next: %p prev: %p\n", next_sibling, prev_sibling );
9.299 + }
9.300 +
9.301 + GLUI_Node( void ) {
9.302 + parent_node= child_head = child_tail = next_sibling = prev_sibling = NULL;
9.303 + };
9.304 +
9.305 + friend class GLUI_Rollout;
9.306 + friend class GLUI_Main;
9.307 +};
9.308 +
9.309 +
9.310 +
9.311 +/************************************************************/
9.312 +/* */
9.313 +/* Standard Bitmap stuff */
9.314 +/* */
9.315 +/************************************************************/
9.316 +
9.317 +enum GLUI_StdBitmaps_Codes {
9.318 + GLUI_STDBITMAP_CHECKBOX_OFF=0,
9.319 + GLUI_STDBITMAP_CHECKBOX_ON,
9.320 + GLUI_STDBITMAP_RADIOBUTTON_OFF,
9.321 + GLUI_STDBITMAP_RADIOBUTTON_ON,
9.322 + GLUI_STDBITMAP_UP_ARROW,
9.323 + GLUI_STDBITMAP_DOWN_ARROW,
9.324 + GLUI_STDBITMAP_LEFT_ARROW,
9.325 + GLUI_STDBITMAP_RIGHT_ARROW,
9.326 + GLUI_STDBITMAP_SPINNER_UP_OFF,
9.327 + GLUI_STDBITMAP_SPINNER_UP_ON,
9.328 + GLUI_STDBITMAP_SPINNER_DOWN_OFF,
9.329 + GLUI_STDBITMAP_SPINNER_DOWN_ON,
9.330 +
9.331 + GLUI_STDBITMAP_CHECKBOX_OFF_DIS, /*** Disactivated control bitmaps ***/
9.332 + GLUI_STDBITMAP_CHECKBOX_ON_DIS,
9.333 + GLUI_STDBITMAP_RADIOBUTTON_OFF_DIS,
9.334 + GLUI_STDBITMAP_RADIOBUTTON_ON_DIS,
9.335 + GLUI_STDBITMAP_SPINNER_UP_DIS,
9.336 + GLUI_STDBITMAP_SPINNER_DOWN_DIS,
9.337 + GLUI_STDBITMAP_LISTBOX_UP,
9.338 + GLUI_STDBITMAP_LISTBOX_DOWN,
9.339 + GLUI_STDBITMAP_LISTBOX_UP_DIS,
9.340 + /***
9.341 + GLUI_STDBITMAP_SLIDER_TAB,
9.342 + ***/
9.343 + GLUI_STDBITMAP_NUM_ITEMS
9.344 +};
9.345 +
9.346 +
9.347 +/************ Image Bitmap arrays **********/
9.348 +extern int glui_img_checkbox_0[];
9.349 +extern int glui_img_checkbox_1[];
9.350 +extern int glui_img_radiobutton_0[];
9.351 +extern int glui_img_radiobutton_1[];
9.352 +extern int glui_img_uparrow[];
9.353 +extern int glui_img_downarrow[];
9.354 +extern int glui_img_leftarrow[];
9.355 +extern int glui_img_rightarrow[];
9.356 +extern int glui_img_spinup_0[];
9.357 +extern int glui_img_spinup_1[];
9.358 +extern int glui_img_spindown_0[];
9.359 +extern int glui_img_spindown_1[];
9.360 +extern int glui_img_checkbox_0_dis[];
9.361 +extern int glui_img_checkbox_1_dis[];
9.362 +extern int glui_img_radiobutton_0_dis[];
9.363 +extern int glui_img_radiobutton_1_dis[];
9.364 +extern int glui_img_spinup_dis[];
9.365 +extern int glui_img_spindown_dis[];
9.366 +extern int glui_img_listbox_up[];
9.367 +extern int glui_img_listbox_down[];
9.368 +extern int glui_img_listbox_up_dis[];
9.369 +
9.370 +extern int *bitmap_arrays[];
9.371 +
9.372 +
9.373 +
9.374 +/************************************************************/
9.375 +/* */
9.376 +/* Class GLUI_Bitmap */
9.377 +/* */
9.378 +/************************************************************/
9.379 +class GLUI_Bitmap
9.380 +{
9.381 +public:
9.382 + unsigned char *pixels;
9.383 + int w, h;
9.384 +
9.385 + void load_from_array( int *array );
9.386 +
9.387 + GLUI_Bitmap( void ) {
9.388 + pixels = NULL;
9.389 + w = 0;
9.390 + h = 0;
9.391 + }
9.392 +};
9.393 +
9.394 +
9.395 +
9.396 +
9.397 +/************************************************************/
9.398 +/* */
9.399 +/* Class GLUI_StdBitmap */
9.400 +/* */
9.401 +/************************************************************/
9.402 +class GLUI_StdBitmaps
9.403 +{
9.404 +public:
9.405 + GLUI_Bitmap bitmaps[ GLUI_STDBITMAP_NUM_ITEMS ];
9.406 +
9.407 + void draw( int bitmap_num, int x, int y );
9.408 +
9.409 + GLUI_StdBitmaps( void ) {
9.410 + int i;
9.411 +
9.412 + for( i=0; i<GLUI_STDBITMAP_NUM_ITEMS; i++ ) {
9.413 + bitmaps[i].load_from_array( bitmap_arrays[i] );
9.414 + }
9.415 + }
9.416 +};
9.417 +
9.418 +
9.419 +
9.420 +
9.421 +/************************************************************/
9.422 +/* */
9.423 +/* Master GLUI Class */
9.424 +/* */
9.425 +/************************************************************/
9.426 +class GLUI_Master_Object {
9.427 +private:
9.428 + GLUI_Node glut_windows;
9.429 + void (*glut_idle_CB)(void);
9.430 +
9.431 + void add_cb_to_glut_window(int window,int cb_type,void *cb);
9.432 +
9.433 +public:
9.434 + GLUI_Node gluis;
9.435 + GLUI_Control *active_control, *curr_left_button_glut_menu;
9.436 + GLUI *active_control_glui;
9.437 + int glui_id_counter;
9.438 +
9.439 + GLUI_Glut_Window *find_glut_window( int window_id );
9.440 +
9.441 + void set_glutIdleFunc(void (*f)(void));
9.442 +
9.443 + /**************
9.444 + void (*glut_keyboard_CB)(unsigned char, int, int);
9.445 + void (*glut_reshape_CB)(int, int);
9.446 + void (*glut_special_CB)(int, int, int);
9.447 + void (*glut_mouse_CB)(int,int,int,int);
9.448 +
9.449 + void (*glut_passive_motion_CB)(int,int);
9.450 + void (*glut_visibility_CB)(int);
9.451 + void (*glut_motion_CB)(int,int);
9.452 + void (*glut_display_CB)(void);
9.453 + void (*glut_entry_CB)(int);
9.454 + **********/
9.455 +
9.456 + void set_left_button_glut_menu_control( GLUI_Control *control );
9.457 +
9.458 +
9.459 + /********** GLUT callthroughs **********/
9.460 + /* These are the glut callbacks that we do not handle */
9.461 +
9.462 + void set_glutReshapeFunc(void (*f)(int width, int height));
9.463 + void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
9.464 + void set_glutSpecialFunc(void (*f)(int key, int x, int y));
9.465 + void set_glutMouseFunc(void (*f)(int, int, int, int ));
9.466 +
9.467 + void set_glutDisplayFunc(void (*f)(void)) {glutDisplayFunc(f);};
9.468 + void set_glutTimerFunc(unsigned int millis, void (*f)(int value), int value)
9.469 + { ::glutTimerFunc(millis,f,value);};
9.470 + void set_glutOverlayDisplayFunc(void(*f)(void)){glutOverlayDisplayFunc(f);};
9.471 + void set_glutSpaceballMotionFunc(Int3_CB f) {glutSpaceballMotionFunc(f);};
9.472 + void set_glutSpaceballRotateFunc(Int3_CB f) {glutSpaceballRotateFunc(f);};
9.473 + void set_glutSpaceballButtonFunc(Int2_CB f) {glutSpaceballButtonFunc(f);};
9.474 + void set_glutTabletMotionFunc(Int2_CB f) {glutTabletMotionFunc(f);};
9.475 + void set_glutTabletButtonFunc(Int4_CB f) {glutTabletButtonFunc(f);};
9.476 + /* void set_glutWindowStatusFunc(Int1_CB f) {glutWindowStatusFunc(f);}; */
9.477 + void set_glutMenuStatusFunc(Int3_CB f) {glutMenuStatusFunc(f);};
9.478 + void set_glutMenuStateFunc(Int1_CB f) {glutMenuStateFunc(f);};
9.479 + void set_glutButtonBoxFunc(Int2_CB f) {glutButtonBoxFunc(f);};
9.480 + void set_glutDialsFunc(Int2_CB f) {glutDialsFunc(f);};
9.481 +
9.482 +
9.483 + GLUI *create_glui( char *name, long flags=0, int x=-1, int y=-1 );
9.484 + GLUI *create_glui_subwindow( int parent_window, long flags=0 );
9.485 + GLUI *find_glui_by_window_id( int window_id );
9.486 + void get_viewport_area( int *x, int *y, int *w, int *h );
9.487 + void auto_set_viewport( void );
9.488 + void close_all( void );
9.489 + void sync_live_all( void );
9.490 +
9.491 + void reshape( void );
9.492 +
9.493 + float get_version( void ) { return GLUI_VERSION; };
9.494 +
9.495 + friend void glui_idle_func(void);
9.496 +
9.497 + GLUI_Master_Object( void ) {
9.498 + glut_idle_CB = NULL;
9.499 + glui_id_counter = 1;
9.500 + }
9.501 +};
9.502 +
9.503 +extern GLUI_Master_Object GLUI_Master;
9.504 +
9.505 +
9.506 +
9.507 +/************************************************************/
9.508 +/* */
9.509 +/* Class for managing a GLUT window */
9.510 +/* */
9.511 +/************************************************************/
9.512 +
9.513 +class GLUI_Glut_Window : public GLUI_Node {
9.514 +public:
9.515 + int glut_window_id;
9.516 +
9.517 + /*********** Pointers to GLUT callthrough functions *****/
9.518 + void (*glut_keyboard_CB)(unsigned char, int, int);
9.519 + void (*glut_special_CB)(int, int, int);
9.520 + void (*glut_reshape_CB)(int, int);
9.521 + void (*glut_passive_motion_CB)(int,int);
9.522 + void (*glut_mouse_CB)(int,int,int,int);
9.523 + void (*glut_visibility_CB)(int);
9.524 + void (*glut_motion_CB)(int,int);
9.525 + void (*glut_display_CB)(void);
9.526 + void (*glut_entry_CB)(int);
9.527 +
9.528 + GLUI_Glut_Window( void ) {
9.529 + glut_display_CB = NULL;
9.530 + glut_reshape_CB = NULL;
9.531 + glut_keyboard_CB = NULL;
9.532 + glut_special_CB = NULL;
9.533 + glut_mouse_CB = NULL;
9.534 + glut_motion_CB = NULL;
9.535 + glut_passive_motion_CB = NULL;
9.536 + glut_entry_CB = NULL;
9.537 + glut_visibility_CB = NULL;
9.538 + glut_window_id = 0;
9.539 + };
9.540 +};
9.541 +
9.542 +
9.543 +
9.544 +/************************************************************/
9.545 +/* */
9.546 +/* Main GLUI class (not user-level) */
9.547 +/* */
9.548 +/************************************************************/
9.549 +
9.550 +class GLUI_Main : public GLUI_Node {
9.551 +protected:
9.552 + /*** Variables ***/
9.553 + int main_gfx_window_id;
9.554 + int mouse_button_down;
9.555 + int glut_window_id;
9.556 + int top_level_glut_window_id;
9.557 + GLUI_Control *active_control;
9.558 + GLUI_Control *mouse_over_control;
9.559 + GLUI_Panel *main_panel;
9.560 + int curr_cursor;
9.561 + int w, h;
9.562 + long flags;
9.563 + int closing;
9.564 + int parent_window;
9.565 + int glui_id;
9.566 +
9.567 + /********** Friend classes *************/
9.568 +
9.569 + friend class GLUI_Control;
9.570 + friend class GLUI_Rotation;
9.571 + friend class GLUI_Translation;
9.572 + friend class GLUI;
9.573 + friend class GLUI_Master_Object;
9.574 +
9.575 +
9.576 + /********** Misc functions *************/
9.577 +
9.578 + GLUI_Control *find_control( int x, int y );
9.579 + GLUI_Control *find_next_control( GLUI_Control *control );
9.580 + GLUI_Control *find_next_control_rec( GLUI_Control *control );
9.581 + GLUI_Control *find_next_control_( GLUI_Control *control );
9.582 + GLUI_Control *find_prev_control( GLUI_Control *control );
9.583 + void create_standalone_window( char *name, int x=-1, int y=-1 );
9.584 + void create_subwindow( int parent,int window_alignment );
9.585 + void setup_default_glut_callbacks( void );
9.586 +
9.587 + void mouse(int button, int state, int x, int y);
9.588 + void keyboard(unsigned char key, int x, int y);
9.589 + void special(int key, int x, int y);
9.590 + void passive_motion(int x, int y);
9.591 + void reshape( int w, int h );
9.592 + void visibility(int state);
9.593 + void motion(int x, int y);
9.594 + void entry(int state);
9.595 + void display( void );
9.596 + void idle(void);
9.597 +
9.598 + void (*glut_mouse_CB)(int, int, int, int);
9.599 + void (*glut_keyboard_CB)(unsigned char, int, int);
9.600 + void (*glut_special_CB)(int, int, int);
9.601 + void (*glut_reshape_CB)(int, int);
9.602 +
9.603 +
9.604 + /*********** Friend functions and classes **********/
9.605 +
9.606 + friend void glui_mouse_func(int button, int state, int x, int y);
9.607 + friend void glui_keyboard_func(unsigned char key, int x, int y);
9.608 + friend void glui_special_func(int key, int x, int y);
9.609 + friend void glui_passive_motion_func(int x, int y);
9.610 + friend void glui_reshape_func( int w, int h );
9.611 + friend void glui_visibility_func(int state);
9.612 + friend void glui_motion_func(int x, int y);
9.613 + friend void glui_entry_func(int state);
9.614 + friend void glui_display_func( void );
9.615 + friend void glui_idle_func(void);
9.616 +
9.617 + friend void glui_parent_window_reshape_func( int w, int h );
9.618 + friend void glui_parent_window_keyboard_func( unsigned char, int, int );
9.619 + friend void glui_parent_window_special_func( int, int, int );
9.620 + friend void glui_parent_window_mouse_func( int, int, int, int );
9.621 +
9.622 +
9.623 + /*********** Controls ************/
9.624 + GLUI_Control *controls;
9.625 + int num_controls;
9.626 +
9.627 + int add_control( GLUI_Node *parent, GLUI_Control *control );
9.628 +
9.629 +
9.630 + /********** Constructors and Destructors ***********/
9.631 +
9.632 + GLUI_Main( void );
9.633 +
9.634 +public:
9.635 + GLUI_StdBitmaps std_bitmaps;
9.636 + GLUI_String window_name;
9.637 + RGBc bkgd_color;
9.638 + float bkgd_color_f[3];
9.639 +
9.640 + void *font;
9.641 + int curr_modifiers;
9.642 +
9.643 + void adjust_glut_xy( int &x, int &y ) { y = h-y; };
9.644 + void activate_control( GLUI_Control *control, int how );
9.645 + void align_controls( GLUI_Control *control );
9.646 + void restore_draw_buffer( int buffer_state );
9.647 + void disactivate_current_control( void );
9.648 + void draw_raised_box( int x, int y, int w, int h );
9.649 + void draw_lowered_box( int x, int y, int w, int h );
9.650 + int set_front_draw_buffer( void );
9.651 + void post_update_main_gfx( void );
9.652 + void pack_controls( void );
9.653 + void close_internal( void );
9.654 + void check_subwindow_position( void );
9.655 + void set_ortho_projection( void );
9.656 + void set_viewport( void );
9.657 + void refresh( void );
9.658 +};
9.659 +
9.660 +
9.661 +
9.662 +
9.663 +
9.664 +
9.665 +/************************************************************/
9.666 +/* */
9.667 +/* GLUI_Control: base class for all controls */
9.668 +/* */
9.669 +/************************************************************/
9.670 +
9.671 +class GLUI_Control : public GLUI_Node {
9.672 +public:
9.673 +
9.674 + int w, h; /* dimensions of control */
9.675 + int x_abs, y_abs;
9.676 + int x_off, y_off_top, y_off_bot; /* INNER margins, by which
9.677 + child controls are indented */
9.678 + int contain_x, contain_y;
9.679 + int contain_w, contain_h;
9.680 + /* if this is a container control (e.g.,
9.681 + radiogroup or panel) this indicated dimensions
9.682 + of inner area in which controls reside */
9.683 + int active, active_type, can_activate;
9.684 + int spacebar_mouse_click;
9.685 + long user_id, type;
9.686 + int is_container; /* Is this a container class (e.g., panel) */
9.687 + int alignment;
9.688 + GLUI_Update_CB callback;
9.689 + void *ptr_val; /* A pointer value */
9.690 + float float_val; /* A float value */
9.691 + int enabled; /* Is this control grayed out? */
9.692 + int int_val; /* An integer value */
9.693 + float float_array_val[GLUI_DEF_MAX_ARRAY];
9.694 + int state;
9.695 + GLUI_String name; /* The name of this control */
9.696 + GLUI_String text;
9.697 + GLUI *glui;
9.698 + void *font;
9.699 + int live_type, live_inited;
9.700 + int last_live_int; /* last value that live var known to have */
9.701 + float last_live_float;
9.702 + GLUI_String last_live_text;
9.703 + float last_live_float_array[GLUI_DEF_MAX_ARRAY];
9.704 + int float_array_size;
9.705 +
9.706 + int collapsible, is_open;
9.707 + GLUI_Node collapsed_node;
9.708 + int hidden; /* Collapsed controls (and children) are hidden */
9.709 +
9.710 + /*** Get/Set values ***/
9.711 +
9.712 + virtual void set_name( char *string );
9.713 + virtual void set_int_val( int new_int ) { int_val = new_int; output_live(true); };
9.714 + virtual void set_float_val( float new_float ) { float_val = new_float; output_live(true); };
9.715 + virtual void set_ptr_val( void *new_ptr ) { ptr_val = new_ptr; output_live(true); };
9.716 + virtual void set_float_array_val( float *array_ptr );
9.717 +
9.718 + virtual float get_float_val( void ) { return float_val; };
9.719 + virtual int get_int_val( void ) { return int_val; };
9.720 + virtual void get_float_array_val( float *array_ptr );
9.721 +
9.722 + virtual int mouse_down_handler( int local_x, int local_y )
9.723 + { return false; };
9.724 + virtual int mouse_up_handler( int local_x, int local_y, int inside )
9.725 + { return false; };
9.726 + virtual int mouse_held_down_handler( int local_x, int local_y, int inside)
9.727 + { return false; };
9.728 + virtual int key_handler( unsigned char key, int modifiers )
9.729 + { return false; };
9.730 + virtual int special_handler( int key,int modifiers )
9.731 + { return false; };
9.732 +
9.733 + virtual void update_size( void ) { };
9.734 + virtual void idle( void ) { };
9.735 + virtual int mouse_over( int state, int x, int y ) { return false; };
9.736 +
9.737 + virtual void enable( void );
9.738 + virtual void disable( void );
9.739 + virtual void activate( int how ) { active = true; };
9.740 + virtual void disactivate( void ) { active = false; };
9.741 +
9.742 + void hide_internal( int recurse );
9.743 + void unhide_internal( int recurse );
9.744 +
9.745 + int can_draw( void ) { return (glui != NULL && hidden == false); };
9.746 +
9.747 + virtual void align( void );
9.748 + void pack( int x, int y ); /* Recalculate positions and offsets */
9.749 + void pack_old( int x, int y );
9.750 + void draw_recursive( int x, int y );
9.751 + int set_to_glut_window( void );
9.752 + void restore_window( int orig );
9.753 + void translate_and_draw_front( void );
9.754 + void translate_to_origin( void )
9.755 + {glTranslatef((float)x_abs+.5,(float)y_abs+.5,0.0);};
9.756 + virtual void draw( int x, int y )=0;
9.757 + void set_font( void *new_font );
9.758 + void *get_font( void );
9.759 + int string_width( char *text );
9.760 + int char_width( char c );
9.761 +
9.762 + void draw_name( int x, int y );
9.763 + void draw_box_inwards_outline( int x_min, int x_max,
9.764 + int y_min, int y_max );
9.765 + void draw_box( int x_min, int x_max, int y_min, int y_max,
9.766 + float r, float g, float b );
9.767 + void draw_bkgd_box( int x_min, int x_max, int y_min, int y_max );
9.768 + void draw_emboss_box( int x_min, int x_max,int y_min,int y_max);
9.769 + void draw_string( char *text );
9.770 + void draw_char( char c );
9.771 + void draw_active_box( int x_min, int x_max, int y_min, int y_max );
9.772 + void set_to_bkgd_color( void );
9.773 +
9.774 + void set_w( int new_w );
9.775 + void set_h( int new_w );
9.776 + void set_alignment( int new_align );
9.777 + void sync_live( int recurse, int draw ); /* Reads live variable */
9.778 + void init_live( void );
9.779 + void output_live( int update_main_gfx ); /** Writes live variable **/
9.780 + virtual void set_text( char *t ) {};
9.781 + void execute_callback( void );
9.782 + void get_this_column_dims( int *col_x, int *col_y,
9.783 + int *col_w, int *col_h,
9.784 + int *col_x_off, int *col_y_off );
9.785 + virtual int needs_idle( void );
9.786 +
9.787 + GLUI_Control(void) {
9.788 + x_off = GLUI_XOFF;
9.789 + y_off_top = GLUI_YOFF;
9.790 + y_off_bot = GLUI_YOFF;
9.791 + x_abs = GLUI_XOFF;
9.792 + y_abs = GLUI_YOFF;
9.793 + state = 0;
9.794 + active = false;
9.795 + enabled = true;
9.796 + int_val = 0;
9.797 + last_live_int = 0;
9.798 + float_array_size = 0;
9.799 + sprintf( (char*)name, "Control: %p", this );
9.800 + float_val = 0.0;
9.801 + last_live_float = 0.0;
9.802 + ptr_val = NULL;
9.803 + glui = NULL;
9.804 + w = GLUI_DEFAULT_CONTROL_WIDTH;
9.805 + h = GLUI_DEFAULT_CONTROL_HEIGHT;
9.806 + font = NULL;
9.807 + active_type = GLUI_CONTROL_ACTIVE_MOUSEDOWN;
9.808 + alignment = GLUI_ALIGN_LEFT;
9.809 + is_container = false;
9.810 + can_activate = true; /* By default, you can activate a control */
9.811 + spacebar_mouse_click = true; /* Does spacebar simulate a mouse click? */
9.812 + live_type = GLUI_LIVE_NONE;
9.813 + strcpy( (char*)text, "" );
9.814 + strcpy( (char*)last_live_text, "" );
9.815 + live_inited = false;
9.816 + collapsible = false;
9.817 + is_open = true;
9.818 + hidden = false;
9.819 +
9.820 + int i;
9.821 + for( i=0; i<GLUI_DEF_MAX_ARRAY; i++ )
9.822 + float_array_val[i] = last_live_float_array[i] = 0.0;
9.823 + };
9.824 +
9.825 + virtual ~GLUI_Control();
9.826 +};
9.827 +
9.828 +
9.829 +
9.830 +
9.831 +/************************************************************/
9.832 +/* */
9.833 +/* Button class (container) */
9.834 +/* */
9.835 +/************************************************************/
9.836 +
9.837 +class GLUI_Button : public GLUI_Control
9.838 +{
9.839 +public:
9.840 + int currently_inside;
9.841 +
9.842 + int mouse_down_handler( int local_x, int local_y );
9.843 + int mouse_up_handler( int local_x, int local_y, int same );
9.844 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.845 + int key_handler( unsigned char key,int modifiers );
9.846 +
9.847 + void draw( int x, int y );
9.848 + void draw_pressed( void );
9.849 + void draw_unpressed( void );
9.850 + void draw_text( int sunken );
9.851 +
9.852 + void update_size( void );
9.853 +
9.854 + GLUI_Button( void ) {
9.855 + sprintf( name, "Button: %p", this );
9.856 + type = GLUI_CONTROL_BUTTON;
9.857 + h = GLUI_BUTTON_SIZE;
9.858 + w = 100;
9.859 + alignment = GLUI_ALIGN_CENTER;
9.860 + can_activate = true;
9.861 + };
9.862 +
9.863 + virtual ~GLUI_Button() {};
9.864 +};
9.865 +
9.866 +
9.867 +
9.868 +/************************************************************/
9.869 +/* */
9.870 +/* Checkbox class (container) */
9.871 +/* */
9.872 +/************************************************************/
9.873 +
9.874 +class GLUI_Checkbox : public GLUI_Control
9.875 +{
9.876 +public:
9.877 + int orig_value, currently_inside;
9.878 + int text_x_offset;
9.879 +
9.880 + int mouse_down_handler( int local_x, int local_y );
9.881 + int mouse_up_handler( int local_x, int local_y, int inside );
9.882 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.883 + int key_handler( unsigned char key,int modifiers );
9.884 +
9.885 + void update_size( void );
9.886 +
9.887 + void draw( int x, int y );
9.888 +
9.889 + void draw_active_area( void );
9.890 + void draw_checked( void );
9.891 + void draw_unchecked( void );
9.892 + void draw_X( void );
9.893 + void draw_empty_box( void );
9.894 + void set_int_val( int new_val );
9.895 +
9.896 + GLUI_Checkbox( void ) {
9.897 + sprintf( name, "Checkbox: %p", this );
9.898 + type = GLUI_CONTROL_CHECKBOX;
9.899 + w = 100;
9.900 + h = GLUI_CHECKBOX_SIZE;
9.901 + orig_value = -1;
9.902 + text_x_offset = 18;
9.903 + can_activate = true;
9.904 + live_type = GLUI_LIVE_INT; /* This control has an 'int' live var */
9.905 + };
9.906 +
9.907 + virtual ~GLUI_Checkbox() {};
9.908 +};
9.909 +
9.910 +
9.911 +/************************************************************/
9.912 +/* */
9.913 +/* Column class */
9.914 +/* */
9.915 +/************************************************************/
9.916 +
9.917 +class GLUI_Column : public GLUI_Control
9.918 +{
9.919 +public:
9.920 + void draw( int x, int y );
9.921 +
9.922 + GLUI_Column( void ) {
9.923 + type = GLUI_CONTROL_COLUMN;
9.924 + w = 0;
9.925 + h = 0;
9.926 + int_val = 0;
9.927 + can_activate = false;
9.928 + };
9.929 +
9.930 + virtual ~GLUI_Column() {};
9.931 +};
9.932 +
9.933 +
9.934 +
9.935 +/************************************************************/
9.936 +/* */
9.937 +/* Panel class (container) */
9.938 +/* */
9.939 +/************************************************************/
9.940 +
9.941 +class GLUI_Panel : public GLUI_Control
9.942 +{
9.943 +public:
9.944 + void draw( int x, int y );
9.945 + void set_name( char *text );
9.946 + void set_type( int new_type );
9.947 +
9.948 + void update_size( void );
9.949 +
9.950 + GLUI_Panel( void ) {
9.951 + type = GLUI_CONTROL_PANEL;
9.952 + w = 300;
9.953 + h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
9.954 + int_val = GLUI_PANEL_EMBOSSED;
9.955 + alignment = GLUI_ALIGN_CENTER;
9.956 + is_container = true;
9.957 + can_activate = false;
9.958 + strcpy( name, "" );
9.959 + };
9.960 +
9.961 + virtual ~GLUI_Panel() {};
9.962 +};
9.963 +
9.964 +
9.965 +/************************************************************/
9.966 +/* */
9.967 +/* Panel class (container) */
9.968 +/* */
9.969 +/************************************************************/
9.970 +
9.971 +class GLUI_Rollout : public GLUI_Panel
9.972 +{
9.973 + /* private: */
9.974 + /* GLUI_Panel panel; */
9.975 +public:
9.976 + int currently_inside, initially_inside;
9.977 + GLUI_Button button;
9.978 +
9.979 + void draw( int x, int y );
9.980 + void draw_pressed( void );
9.981 + void draw_unpressed( void );
9.982 + int mouse_down_handler( int local_x, int local_y );
9.983 + int mouse_up_handler( int local_x, int local_y, int inside );
9.984 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.985 +
9.986 + void open( void );
9.987 + void close( void );
9.988 +
9.989 + /* void set_name( char *text ) { panel.set_name( text ); }; */
9.990 + void update_size( void );
9.991 +
9.992 + GLUI_Rollout( void ) {
9.993 + currently_inside = false;
9.994 + initially_inside = false;
9.995 + can_activate = true;
9.996 + is_container = true;
9.997 + type = GLUI_CONTROL_ROLLOUT;
9.998 + h = GLUI_DEFAULT_CONTROL_HEIGHT + 7;
9.999 + w = GLUI_DEFAULT_CONTROL_WIDTH;
9.1000 + y_off_top = 21;
9.1001 + collapsible = true;
9.1002 + strcpy( name, "" );
9.1003 + };
9.1004 +
9.1005 + virtual ~GLUI_Rollout() {};
9.1006 +};
9.1007 +
9.1008 +
9.1009 +/************************************************************/
9.1010 +/* */
9.1011 +/* User-Level GLUI class */
9.1012 +/* */
9.1013 +/************************************************************/
9.1014 +
9.1015 +class GLUI : public GLUI_Main {
9.1016 +private:
9.1017 +public:
9.1018 + void add_column( int draw_bar = true );
9.1019 + void add_column_to_panel( GLUI_Panel *panel, int draw_bar = true );
9.1020 +
9.1021 + void add_separator( void );
9.1022 + void add_separator_to_panel( GLUI_Panel *panel );
9.1023 +
9.1024 + GLUI_RadioGroup
9.1025 + *add_radiogroup( int *live_var=NULL,
9.1026 + int user_id=-1,GLUI_Update_CB callback=NULL);
9.1027 +
9.1028 + GLUI_RadioGroup
9.1029 + *add_radiogroup_to_panel( GLUI_Panel *panel,
9.1030 + int *live_var=NULL,
9.1031 + int user_id=-1, GLUI_Update_CB callback=NULL );
9.1032 + GLUI_RadioButton
9.1033 + *add_radiobutton_to_group( GLUI_RadioGroup *group,
9.1034 + char *name );
9.1035 +
9.1036 + GLUI_Listbox *add_listbox( char *name, int *live_var=NULL,
9.1037 + int id=-1, GLUI_Update_CB callback=NULL );
9.1038 + GLUI_Listbox *add_listbox_to_panel( GLUI_Panel *panel,
9.1039 + char *name, int *live_var=NULL,
9.1040 + int id=-1, GLUI_Update_CB callback=NULL);
9.1041 +
9.1042 + GLUI_Rotation *add_rotation( char *name, float *live_var=NULL,
9.1043 + int id=-1, GLUI_Update_CB callback=NULL );
9.1044 + GLUI_Rotation *add_rotation_to_panel( GLUI_Panel *panel,
9.1045 + char *name, float *live_var=NULL,
9.1046 + int id=-1, GLUI_Update_CB callback=NULL);
9.1047 +
9.1048 + GLUI_Translation *add_translation( char *name,
9.1049 + int trans_type, float *live_var=NULL,
9.1050 + int id=-1, GLUI_Update_CB callback=NULL );
9.1051 + GLUI_Translation *add_translation_to_panel(
9.1052 + GLUI_Panel *panel, char *name,
9.1053 + int trans_type, float *live_var=NULL,
9.1054 + int id=-1, GLUI_Update_CB callback=NULL);
9.1055 +
9.1056 + GLUI_Checkbox *add_checkbox( char *name,
9.1057 + int *live_var=NULL,
9.1058 + int id=-1, GLUI_Update_CB callback=NULL);
9.1059 + GLUI_Checkbox *add_checkbox_to_panel( GLUI_Panel *panel, char *name,
9.1060 + int *live_var=NULL, int id=-1,
9.1061 + GLUI_Update_CB callback=NULL);
9.1062 +
9.1063 + GLUI_Button *add_button( char *name, int id=-1,
9.1064 + GLUI_Update_CB callback=NULL);
9.1065 + GLUI_Button *add_button_to_panel( GLUI_Panel *panel, char *name,
9.1066 + int id=-1, GLUI_Update_CB callback=NULL );
9.1067 +
9.1068 + GLUI_StaticText *add_statictext( char *name );
9.1069 + GLUI_StaticText *add_statictext_to_panel( GLUI_Panel *panel, char *name );
9.1070 +
9.1071 + GLUI_EditText *add_edittext( char *name,
9.1072 + int data_type=GLUI_EDITTEXT_TEXT,
9.1073 + void *live_var=NULL,
9.1074 + int id=-1, GLUI_Update_CB callback=NULL );
9.1075 + GLUI_EditText *add_edittext_to_panel( GLUI_Panel *panel,
9.1076 + char *name,
9.1077 + int data_type=GLUI_EDITTEXT_TEXT,
9.1078 + void *live_var=NULL, int id=-1,
9.1079 + GLUI_Update_CB callback=NULL );
9.1080 +
9.1081 + GLUI_Spinner *add_spinner( char *name,
9.1082 + int data_type=GLUI_SPINNER_INT,
9.1083 + void *live_var=NULL,
9.1084 + int id=-1, GLUI_Update_CB callback=NULL );
9.1085 + GLUI_Spinner *add_spinner_to_panel( GLUI_Panel *panel,
9.1086 + char *name,
9.1087 + int data_type=GLUI_SPINNER_INT,
9.1088 + void *live_var=NULL,
9.1089 + int id=-1,
9.1090 + GLUI_Update_CB callback=NULL );
9.1091 +
9.1092 + GLUI_Panel *add_panel( char *name, int type=GLUI_PANEL_EMBOSSED );
9.1093 + GLUI_Panel *add_panel_to_panel( GLUI_Panel *panel, char *name,
9.1094 + int type=GLUI_PANEL_EMBOSSED );
9.1095 +
9.1096 + GLUI_Rollout *add_rollout( char *name, int open=true );
9.1097 + GLUI_Rollout *add_rollout_to_panel( GLUI_Panel *panel, char *name, int open=true );
9.1098 +
9.1099 + void set_main_gfx_window( int window_id );
9.1100 + int get_glut_window_id( void ) { return glut_window_id; };
9.1101 +
9.1102 + void enable( void ) { main_panel->enable(); };
9.1103 + void disable( void );
9.1104 +
9.1105 + void sync_live( void );
9.1106 +
9.1107 + void close( void );
9.1108 +
9.1109 + void show( void );
9.1110 + void hide( void );
9.1111 +
9.1112 + /***** GLUT callback setup functions *****/
9.1113 + /*
9.1114 + void set_glutDisplayFunc(void (*f)(void));
9.1115 + void set_glutReshapeFunc(void (*f)(int width, int height));
9.1116 + void set_glutKeyboardFunc(void (*f)(unsigned char key, int x, int y));
9.1117 + void set_glutSpecialFunc(void (*f)(int key, int x, int y));
9.1118 + void set_glutMouseFunc(void (*f)(int button, int state, int x, int y));
9.1119 + void set_glutMotionFunc(void (*f)(int x, int y));
9.1120 + void set_glutPassiveMotionFunc(void (*f)(int x, int y));
9.1121 + void set_glutEntryFunc(void (*f)(int state));
9.1122 + void set_glutVisibilityFunc(void (*f)(int state));
9.1123 + void set_glutInit( int *argcp, char **argv );
9.1124 + void set_glutInitWindowSize(int width, int height);
9.1125 + void set_glutInitWindowPosition(int x, int y);
9.1126 + void set_glutInitDisplayMode(unsigned int mode);
9.1127 + int set_glutCreateWindow(char *name);
9.1128 + */
9.1129 +
9.1130 + /***** Constructors and desctructors *****/
9.1131 +
9.1132 + int init( char *name, long flags, int x, int y, int parent_window );
9.1133 +};
9.1134 +
9.1135 +
9.1136 +
9.1137 +
9.1138 +/************************************************************/
9.1139 +/* */
9.1140 +/* EditText class */
9.1141 +/* */
9.1142 +/************************************************************/
9.1143 +
9.1144 +class GLUI_EditText : public GLUI_Control
9.1145 +{
9.1146 +public:
9.1147 + int has_limits;
9.1148 + int data_type;
9.1149 + GLUI_String orig_text;
9.1150 + int insertion_pt;
9.1151 + int title_x_offset;
9.1152 + int text_x_offset;
9.1153 + int substring_start; /*substring that gets displayed in box*/
9.1154 + int substring_end;
9.1155 + int sel_start, sel_end; /* current selection */
9.1156 + int num_periods;
9.1157 + int last_insertion_pt;
9.1158 + float float_low, float_high;
9.1159 + int int_low, int_high;
9.1160 + GLUI_Spinner *spinner;
9.1161 + int debug;
9.1162 + int draw_text_only;
9.1163 +
9.1164 +
9.1165 + int mouse_down_handler( int local_x, int local_y );
9.1166 + int mouse_up_handler( int local_x, int local_y, int same );
9.1167 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.1168 + int key_handler( unsigned char key,int modifiers );
9.1169 + int special_handler( int key,int modifiers );
9.1170 +
9.1171 + void activate( int how );
9.1172 + void disactivate( void );
9.1173 +
9.1174 + void draw( int x, int y );
9.1175 +
9.1176 + int mouse_over( int state, int x, int y );
9.1177 +
9.1178 + int find_word_break( int start, int direction );
9.1179 + int substring_width( int start, int end );
9.1180 + void clear_substring( int start, int end );
9.1181 + int find_insertion_pt( int x, int y );
9.1182 + int update_substring_bounds( void );
9.1183 + void update_and_draw_text( void );
9.1184 + void draw_text( int x, int y );
9.1185 + void draw_insertion_pt( void );
9.1186 + void set_numeric_text( void );
9.1187 + void update_x_offsets( void );
9.1188 + void update_size( void );
9.1189 +
9.1190 + void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
9.1191 + void set_int_limits( int low, int high, int limit_type=GLUI_LIMIT_CLAMP );
9.1192 + void set_float_val( float new_val );
9.1193 + void set_int_val( int new_val );
9.1194 + void set_text( char *text );
9.1195 + char *get_text( void ) { return text; };
9.1196 +
9.1197 + void dump( FILE *out, char *text );
9.1198 +
9.1199 + GLUI_EditText( void ) {
9.1200 + type = GLUI_CONTROL_EDITTEXT;
9.1201 + h = GLUI_EDITTEXT_HEIGHT;
9.1202 + w = GLUI_EDITTEXT_WIDTH;
9.1203 + title_x_offset = 0;
9.1204 + text_x_offset = 55;
9.1205 + insertion_pt = -1;
9.1206 + last_insertion_pt = -1;
9.1207 + name[0] = '\0';
9.1208 + substring_start = 0;
9.1209 + data_type = GLUI_EDITTEXT_TEXT;
9.1210 + substring_end = 2;
9.1211 + num_periods = 0;
9.1212 + has_limits = GLUI_LIMIT_NONE;
9.1213 + sel_start = 0;
9.1214 + sel_end = 0;
9.1215 + active_type = GLUI_CONTROL_ACTIVE_PERMANENT;
9.1216 + can_activate = true;
9.1217 + spacebar_mouse_click = false;
9.1218 + spinner = NULL;
9.1219 + debug = false;
9.1220 + draw_text_only = false;
9.1221 + };
9.1222 +};
9.1223 +
9.1224 +
9.1225 +
9.1226 +
9.1227 +/************************************************************/
9.1228 +/* */
9.1229 +/* RadioGroup class (container) */
9.1230 +/* */
9.1231 +/************************************************************/
9.1232 +
9.1233 +class GLUI_RadioGroup : public GLUI_Control
9.1234 +{
9.1235 +public:
9.1236 + int num_buttons;
9.1237 +
9.1238 + void draw( int x, int y );
9.1239 + void set_name( char *text );
9.1240 + void set_int_val( int int_val );
9.1241 + void set_selected( int int_val );
9.1242 +
9.1243 + void draw_group( int translate );
9.1244 +
9.1245 + GLUI_RadioGroup( void ) {
9.1246 + type = GLUI_CONTROL_RADIOGROUP;
9.1247 + x_off = 0;
9.1248 + y_off_top = 0;
9.1249 + y_off_bot = 0;
9.1250 + is_container = true;
9.1251 + w = 300;
9.1252 + h = 300;
9.1253 + num_buttons = 0;
9.1254 + name[0] = '\0';
9.1255 + can_activate = false;
9.1256 + live_type = GLUI_LIVE_INT;
9.1257 + };
9.1258 +};
9.1259 +
9.1260 +
9.1261 +
9.1262 +/************************************************************/
9.1263 +/* */
9.1264 +/* RadioButton class (container) */
9.1265 +/* */
9.1266 +/************************************************************/
9.1267 +
9.1268 +class GLUI_RadioButton : public GLUI_Control
9.1269 +{
9.1270 +public:
9.1271 + int orig_value, currently_inside;
9.1272 + int text_x_offset;
9.1273 +
9.1274 + int mouse_down_handler( int local_x, int local_y );
9.1275 + int mouse_up_handler( int local_x, int local_y, int inside );
9.1276 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.1277 +
9.1278 + void draw( int x, int y );
9.1279 + void update_size( void );
9.1280 +
9.1281 + void draw_active_area( void );
9.1282 + void draw_checked( void );
9.1283 + void draw_unchecked( void );
9.1284 + void draw_O( void );
9.1285 +
9.1286 + GLUI_RadioGroup *group;
9.1287 +
9.1288 + GLUI_RadioButton( void ) {
9.1289 + sprintf( name, "RadioButton: %p", this );
9.1290 + type = GLUI_CONTROL_RADIOBUTTON;
9.1291 + h = GLUI_RADIOBUTTON_SIZE;
9.1292 + group = NULL;
9.1293 + orig_value = -1;
9.1294 + text_x_offset = 18;
9.1295 + can_activate = true;
9.1296 + };
9.1297 +};
9.1298 +
9.1299 +
9.1300 +/************************************************************/
9.1301 +/* */
9.1302 +/* Separator class (container) */
9.1303 +/* */
9.1304 +/************************************************************/
9.1305 +
9.1306 +class GLUI_Separator : public GLUI_Control
9.1307 +{
9.1308 +public:
9.1309 + void draw( int x, int y );
9.1310 +
9.1311 + GLUI_Separator( void ) {
9.1312 + type = GLUI_CONTROL_SEPARATOR;
9.1313 + w = 100;
9.1314 + h = GLUI_SEPARATOR_HEIGHT;
9.1315 + can_activate = false;
9.1316 + };
9.1317 +};
9.1318 +
9.1319 +
9.1320 +#define GLUI_SPINNER_ARROW_WIDTH 12
9.1321 +#define GLUI_SPINNER_ARROW_HEIGHT 8
9.1322 +#define GLUI_SPINNER_ARROW_Y 2
9.1323 +
9.1324 +#define GLUI_SPINNER_STATE_NONE 0
9.1325 +#define GLUI_SPINNER_STATE_UP 1
9.1326 +#define GLUI_SPINNER_STATE_DOWN 2
9.1327 +#define GLUI_SPINNER_STATE_BOTH 3
9.1328 +
9.1329 +#define GLUI_SPINNER_DEFAULT_GROWTH_EXP 1.05f
9.1330 +
9.1331 +
9.1332 +/************************************************************/
9.1333 +/* */
9.1334 +/* Spinner class (container) */
9.1335 +/* */
9.1336 +/************************************************************/
9.1337 +
9.1338 +class GLUI_Spinner : public GLUI_Control
9.1339 +{
9.1340 +public:
9.1341 + int currently_inside;
9.1342 + int state;
9.1343 + float growth, growth_exp;
9.1344 + int last_x, last_y;
9.1345 + int data_type;
9.1346 + int callback_count;
9.1347 + int last_int_val;
9.1348 + float last_float_val;
9.1349 + int first_callback;
9.1350 + float user_speed;
9.1351 +
9.1352 + GLUI_EditText *edittext;
9.1353 +
9.1354 + int mouse_down_handler( int local_x, int local_y );
9.1355 + int mouse_up_handler( int local_x, int local_y, int same );
9.1356 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.1357 + int key_handler( unsigned char key,int modifiers );
9.1358 + int special_handler( int key,int modifiers );
9.1359 +
9.1360 + void draw( int x, int y );
9.1361 + void draw_pressed( void );
9.1362 + void draw_unpressed( void );
9.1363 + void draw_text( int sunken );
9.1364 +
9.1365 + void update_size( void );
9.1366 +
9.1367 + void set_float_limits( float low,float high,int limit_type=GLUI_LIMIT_CLAMP);
9.1368 + void set_int_limits( int low, int high,int limit_type=GLUI_LIMIT_CLAMP);
9.1369 + int find_arrow( int local_x, int local_y );
9.1370 + void do_drag( int x, int y );
9.1371 + void do_callbacks( void );
9.1372 + void draw_arrows( void );
9.1373 + void do_click( void );
9.1374 + void idle( void );
9.1375 + int needs_idle( void );
9.1376 +
9.1377 + char *get_text( void );
9.1378 +
9.1379 + void set_float_val( float new_val );
9.1380 + void set_int_val( int new_val );
9.1381 + float get_float_val( void );
9.1382 + int get_int_val( void );
9.1383 + void increase_growth( void );
9.1384 + void reset_growth( void );
9.1385 +
9.1386 + void set_speed( float speed ) { user_speed = speed; };
9.1387 +
9.1388 + GLUI_Spinner( void ) {
9.1389 + sprintf( name, "Spinner: %p", this );
9.1390 + type = GLUI_CONTROL_SPINNER;
9.1391 + h = GLUI_EDITTEXT_HEIGHT;
9.1392 + w = GLUI_EDITTEXT_WIDTH;
9.1393 + x_off = 0;
9.1394 + y_off_top = 0;
9.1395 + y_off_bot = 0;
9.1396 + can_activate = true;
9.1397 + state = GLUI_SPINNER_STATE_NONE;
9.1398 + edittext = NULL;
9.1399 + growth_exp = GLUI_SPINNER_DEFAULT_GROWTH_EXP;
9.1400 + callback_count = 0;
9.1401 + first_callback = true;
9.1402 + user_speed = 1.0;
9.1403 + };
9.1404 +};
9.1405 +
9.1406 +/************************************************************/
9.1407 +
9.1408 +/* */
9.1409 +/* StaticText class */
9.1410 +/* */
9.1411 +/************************************************************/
9.1412 +
9.1413 +class GLUI_StaticText : public GLUI_Control
9.1414 +{
9.1415 +public:
9.1416 + void set_text( char *text );
9.1417 + void draw( int x, int y );
9.1418 + void draw_text( void );
9.1419 + void update_size( void );
9.1420 + void erase_text( void );
9.1421 +
9.1422 + GLUI_StaticText( void ) {
9.1423 + type = GLUI_CONTROL_STATICTEXT;
9.1424 + h = GLUI_STATICTEXT_SIZE;
9.1425 + name[0] = '\0';
9.1426 + can_activate = false;
9.1427 + };
9.1428 +};
9.1429 +
9.1430 +
9.1431 +
9.1432 +/************************************************************/
9.1433 +/* */
9.1434 +/* Listbox class */
9.1435 +/* */
9.1436 +/************************************************************/
9.1437 +
9.1438 +class GLUI_Listbox_Item : public GLUI_Node
9.1439 +{
9.1440 +public:
9.1441 + GLUI_String text;
9.1442 + int id;
9.1443 +};
9.1444 +
9.1445 +class GLUI_Listbox : public GLUI_Control
9.1446 +{
9.1447 +public:
9.1448 + GLUI_String curr_text;
9.1449 + GLUI_Listbox_Item items_list;
9.1450 + int depressed;
9.1451 +
9.1452 + int orig_value, currently_inside;
9.1453 + int text_x_offset, title_x_offset;
9.1454 + int glut_menu_id;
9.1455 +
9.1456 + int mouse_down_handler( int local_x, int local_y );
9.1457 + int mouse_up_handler( int local_x, int local_y, int inside );
9.1458 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.1459 + int key_handler( unsigned char key,int modifiers );
9.1460 + int special_handler( int key,int modifiers );
9.1461 +
9.1462 + void update_size( void );
9.1463 + void draw( int x, int y );
9.1464 + int mouse_over( int state, int x, int y );
9.1465 +
9.1466 + void draw_active_area( void );
9.1467 + void set_int_val( int new_val );
9.1468 + void dump( FILE *output );
9.1469 +
9.1470 + int add_item( int id, char *text );
9.1471 + int delete_item( char *text );
9.1472 + int delete_item( int id );
9.1473 + int sort_items( void );
9.1474 +
9.1475 + int do_selection( int item );
9.1476 +
9.1477 + void increase_width( void );
9.1478 +
9.1479 + GLUI_Listbox_Item *get_item_ptr( char *text );
9.1480 + GLUI_Listbox_Item *get_item_ptr( int id );
9.1481 +
9.1482 +
9.1483 + GLUI_Listbox( void ) {
9.1484 + sprintf( name, "Listbox: %p", this );
9.1485 + type = GLUI_CONTROL_LISTBOX;
9.1486 + w = GLUI_EDITTEXT_WIDTH;
9.1487 + h = GLUI_EDITTEXT_HEIGHT;
9.1488 + orig_value = -1;
9.1489 + title_x_offset = 0;
9.1490 + text_x_offset = 55;
9.1491 + can_activate = true;
9.1492 + curr_text[0] = '\0';
9.1493 + live_type = GLUI_LIVE_INT; /* This has an integer live var */
9.1494 + depressed = false;
9.1495 + glut_menu_id = -1;
9.1496 + };
9.1497 +
9.1498 + ~GLUI_Listbox();
9.1499 +};
9.1500 +
9.1501 +
9.1502 +/************************************************************/
9.1503 +/* */
9.1504 +/* Mouse_Interaction class */
9.1505 +/* */
9.1506 +/************************************************************/
9.1507 +
9.1508 +class GLUI_Mouse_Interaction : public GLUI_Control
9.1509 +{
9.1510 +public:
9.1511 + /*int get_main_area_size( void ) { return MIN( h-18, */
9.1512 + int draw_active_area_only;
9.1513 +
9.1514 + int mouse_down_handler( int local_x, int local_y );
9.1515 + int mouse_up_handler( int local_x, int local_y, int inside );
9.1516 + int mouse_held_down_handler( int local_x, int local_y, int inside );
9.1517 + int special_handler( int key, int modifiers );
9.1518 + void update_size( void );
9.1519 + void draw( int x, int y );
9.1520 + void draw_active_area( void );
9.1521 +
9.1522 + /*** The following methods (starting with "iaction_") need to
9.1523 + be overloaded ***/
9.1524 + virtual int iaction_mouse_down_handler( int local_x, int local_y ) = 0;
9.1525 + virtual int iaction_mouse_up_handler( int local_x, int local_y, int inside )=0;
9.1526 + virtual int iaction_mouse_held_down_handler( int local_x, int local_y, int inside )=0;
9.1527 + virtual int iaction_special_handler( int key, int modifiers )=0;
9.1528 + virtual void iaction_draw_active_area_persp( void )=0;
9.1529 + virtual void iaction_draw_active_area_ortho( void )=0;
9.1530 + virtual void iaction_dump( FILE *output )=0;
9.1531 + virtual void iaction_init( void ) = 0;
9.1532 +
9.1533 + GLUI_Mouse_Interaction( void ) {
9.1534 + sprintf( name, "Mouse_Interaction: %p", this );
9.1535 + type = GLUI_CONTROL_MOUSE_INTERACTION;
9.1536 + w = GLUI_MOUSE_INTERACTION_WIDTH;
9.1537 + h = GLUI_MOUSE_INTERACTION_HEIGHT;
9.1538 + can_activate = true;
9.1539 + live_type = GLUI_LIVE_NONE;
9.1540 + alignment = GLUI_ALIGN_CENTER;
9.1541 + draw_active_area_only = false;
9.1542 + };
9.1543 +};
9.1544 +
9.1545 +
9.1546 +/************************************************************/
9.1547 +/* */
9.1548 +/* Rotation class */
9.1549 +/* */
9.1550 +/************************************************************/
9.1551 +
9.1552 +class GLUI_Rotation : public GLUI_Mouse_Interaction
9.1553 +{
9.1554 +public:
9.1555 + Arcball *ball;
9.1556 + GLUquadricObj *quadObj;
9.1557 + int can_spin, spinning;
9.1558 + float damping;
9.1559 +
9.1560 + int iaction_mouse_down_handler( int local_x, int local_y );
9.1561 + int iaction_mouse_up_handler( int local_x, int local_y, int inside );
9.1562 + int iaction_mouse_held_down_handler( int local_x, int local_y, int inside );
9.1563 + int iaction_special_handler( int key, int modifiers );
9.1564 + void iaction_init( void ) { init_ball(); };
9.1565 + void iaction_draw_active_area_persp( void );
9.1566 + void iaction_draw_active_area_ortho( void );
9.1567 + void iaction_dump( FILE *output );
9.1568 +
9.1569 + /* void update_size( void ); */
9.1570 + /* void draw( int x, int y ); */
9.1571 + /* int mouse_over( int state, int x, int y ); */
9.1572 +
9.1573 + void setup_texture( void );
9.1574 + void setup_lights( void );
9.1575 + void draw_ball( float radius );
9.1576 +
9.1577 + void init_ball( void );
9.1578 +
9.1579 + void reset( void );
9.1580 +
9.1581 + int needs_idle( void );
9.1582 + void idle( void );
9.1583 +
9.1584 + void copy_float_array_to_ball( void );
9.1585 + void copy_ball_to_float_array( void );
9.1586 +
9.1587 + void set_spin( float damp_factor );
9.1588 +
9.1589 + GLUI_Rotation(void);
9.1590 +};
9.1591 +
9.1592 +
9.1593 +
9.1594 +/************************************************************/
9.1595 +/* */
9.1596 +/* Translation class */
9.1597 +/* */
9.1598 +/************************************************************/
9.1599 +
9.1600 +class GLUI_Translation : public GLUI_Mouse_Interaction
9.1601 +{
9.1602 +public:
9.1603 + int trans_type; /* Is this an XY or a Z controller? */
9.1604 + int down_x, down_y;
9.1605 + float scale_factor;
9.1606 + GLUquadricObj *quadObj;
9.1607 + int trans_mouse_code;
9.1608 + float orig_x, orig_y, orig_z;
9.1609 + int locked;
9.1610 +
9.1611 + int iaction_mouse_down_handler( int local_x, int local_y );
9.1612 + int iaction_mouse_up_handler( int local_x, int local_y, int inside );
9.1613 + int iaction_mouse_held_down_handler( int local_x, int local_y, int inside );
9.1614 + int iaction_special_handler( int key, int modifiers );
9.1615 + void iaction_init( void ) { };
9.1616 + void iaction_draw_active_area_persp( void );
9.1617 + void iaction_draw_active_area_ortho( void );
9.1618 + void iaction_dump( FILE *output );
9.1619 +
9.1620 + void set_speed( float s ) { scale_factor = s; };
9.1621 +
9.1622 + void setup_texture( void );
9.1623 + void setup_lights( void );
9.1624 + void draw_2d_arrow( int radius, int filled, int orientation );
9.1625 + void draw_2d_x_arrows( int radius );
9.1626 + void draw_2d_y_arrows( int radius );
9.1627 + void draw_2d_z_arrows( int radius );
9.1628 + void draw_2d_xy_arrows( int radius );
9.1629 +
9.1630 + int get_mouse_code( int x, int y );
9.1631 +
9.1632 + /* Float array is either a single float (for single-axis controls),
9.1633 + or two floats for X and Y (if an XY controller) */
9.1634 +
9.1635 + float get_z( void ) { return float_array_val[0]; }
9.1636 + float get_x( void ) { return float_array_val[0]; }
9.1637 + float get_y( void ) {
9.1638 + if ( trans_type == GLUI_TRANSLATION_XY ) return float_array_val[1];
9.1639 + else return float_array_val[0];
9.1640 + }
9.1641 +
9.1642 + void set_z( float val );
9.1643 + void set_x( float val );
9.1644 + void set_y( float val );
9.1645 + void set_one_val( float val, int index );
9.1646 +
9.1647 + GLUI_Translation( void ) {
9.1648 + locked = GLUI_TRANSLATION_LOCK_NONE;
9.1649 + sprintf( name, "Translation: %p", this );
9.1650 + type = GLUI_CONTROL_TRANSLATION;
9.1651 + w = GLUI_MOUSE_INTERACTION_WIDTH;
9.1652 + h = GLUI_MOUSE_INTERACTION_HEIGHT;
9.1653 + can_activate = true;
9.1654 + live_type = GLUI_LIVE_FLOAT_ARRAY;
9.1655 + float_array_size = 0;
9.1656 + alignment = GLUI_ALIGN_CENTER;
9.1657 + trans_type = GLUI_TRANSLATION_XY;
9.1658 + scale_factor = 1.0;
9.1659 + quadObj = NULL;
9.1660 + trans_mouse_code = GLUI_TRANSLATION_MOUSE_NONE;
9.1661 + };
9.1662 +};
9.1663 +
9.1664 +
9.1665 +
9.1666 +
9.1667 +/********** Misc functions *********************/
9.1668 +int _glutBitmapWidthString( void *font, char *s );
9.1669 +void _glutBitmapString( void *font, char *s );
9.1670 +
9.1671 +
9.1672 +
9.1673 +/********** Our own callbacks for glut *********/
9.1674 +/* These are the callbacks that we pass to glut. They take
9.1675 + some action if necessary, then (possibly) call the user-level
9.1676 + glut callbacks.
9.1677 + */
9.1678 +
9.1679 +void glui_display_func( void );
9.1680 +void glui_reshape_func( int w, int h );
9.1681 +void glui_keyboard_func(unsigned char key, int x, int y);
9.1682 +void glui_special_func(int key, int x, int y);
9.1683 +void glui_mouse_func(int button, int state, int x, int y);
9.1684 +void glui_motion_func(int x, int y);
9.1685 +void glui_passive_motion_func(int x, int y);
9.1686 +void glui_entry_func(int state);
9.1687 +void glui_visibility_func(int state);
9.1688 +void glui_idle_func(void);
9.1689 +
9.1690 +void glui_parent_window_reshape_func( int w, int h );
9.1691 +void glui_parent_window_keyboard_func(unsigned char key, int x, int y);
9.1692 +void glui_parent_window_mouse_func(int, int, int, int );
9.1693 +void glui_parent_window_special_func(int key, int x, int y);
9.1694 +
9.1695 +
9.1696 +
9.1697 +#endif
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/source/glui/glui.txt Wed Nov 04 00:39:03 2009 +0000
10.3 @@ -0,0 +1,8 @@
10.4 +
10.5 +- the control_float/control_int_value stuff seems like a disaster waiting to
10.6 + happen. They are independent values everywhere except in the edit text
10.7 + control, what's up with that?!
10.8 +
10.9 +- x,y in GLUI_Control::draw() isn't used anymore?
10.10 +
10.11 +- adding a radio group