forked from bartvdbraak/blender
Code cleanup:
* Remove BSP_GhostTest, not used and working for ages, approved by Sergey.
This commit is contained in:
parent
f50bae3259
commit
2390c95cf1
@ -1,126 +0,0 @@
|
||||
# Microsoft Developer Studio Project File - Name="BSP_GhostTest" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=BSP_GhostTest - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BSP_GhostTest.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "BSP_GhostTest.mak" CFG="BSP_GhostTest - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "BSP_GhostTest - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "BSP_GhostTest - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "BSP_GhostTest - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /G6 /MT /W3 /GX /O2 /Ob2 /I "../../extern/" /I "../../../../lib/windows/string/include" /I "../../../../lib/windows/ghost/include" /I "../../../../lib/windows/moto/include" /I "../../../../lib/windows/memutil/include" /I "../../../../lib/windows/container/include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x413 /d "NDEBUG"
|
||||
# ADD RSC /l 0x413 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# 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 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
|
||||
# ADD LINK32 glu32.lib opengl32.lib kernel32.lib user32.lib gdi32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\..\lib\windows\glut-3.7\lib\\"
|
||||
|
||||
!ELSEIF "$(CFG)" == "BSP_GhostTest - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../../extern/" /I "../../../../lib/windows/string/include" /I "../../../../lib/windows/ghost/include" /I "../../../../lib/windows/moto/include" /I "../../../../lib/windows/memutil/include" /I "../../../../lib/windows/container/include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x413 /d "_DEBUG"
|
||||
# ADD RSC /l 0x413 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# 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 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
|
||||
# ADD LINK32 glu32.lib opengl32.lib user32.lib gdi32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\..\lib\windows\glut-3.7\lib\\"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "BSP_GhostTest - Win32 Release"
|
||||
# Name "BSP_GhostTest - Win32 Debug"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_GhostTest3D.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_GhostTest3D.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_MeshDrawer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_MeshDrawer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_PlyLoader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_PlyLoader.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\BSP_TMesh.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ply.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\plyfile.c
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
@ -1,125 +0,0 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "BSP_GhostTest"=.\BSP_GhostTest.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name bsplib
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name ghost
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name string
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name MoTo
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "MoTo"=..\..\..\moto\make\msvc_6_0\MoTo.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bsplib"=..\..\make\msvc6_0\bsplib.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name container
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name memutil
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name MoTo
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "container"=..\..\..\container\make\msvc_6_0\container.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name memutil
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "ghost"=..\..\..\ghost\make\msvc\ghost.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "memutil"=..\..\..\memutil\make\msvc_60\memutil.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "string"=..\..\..\string\make\msvc_6_0\string.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
@ -1,649 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
* Copyright (C) 2001 NaN Technologies B.V.
|
||||
*/
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
# ifdef WIN32
|
||||
# include <windows.h>
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
# else // WIN32
|
||||
# include <AGL/gl.h>
|
||||
# endif // WIN32
|
||||
#else // defined(WIN32) || defined(__APPLE__)
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
#endif // defined(WIN32) || defined(__APPLE__)
|
||||
|
||||
|
||||
#include "BSP_GhostTest3D.h"
|
||||
#include "BSP_MeshDrawer.h"
|
||||
|
||||
#include "GHOST_ISystem.h"
|
||||
#include "GHOST_IWindow.h"
|
||||
|
||||
#include "MT_Quaternion.h"
|
||||
#include "MT_Transform.h"
|
||||
#include "CSG_BooleanOps.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
EmptyInterpFunc(
|
||||
void *d1,
|
||||
void * d2,
|
||||
void *dnew,
|
||||
float epsilon
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
BSP_GhostTestApp3D::
|
||||
BSP_GhostTestApp3D(
|
||||
) :
|
||||
m_window(NULL),
|
||||
m_system(NULL),
|
||||
m_finish_me_off(false),
|
||||
m_current_object(0)
|
||||
{
|
||||
//nothing to do;
|
||||
}
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
SetMesh(
|
||||
MEM_SmartPtr<BSP_TMesh> mesh
|
||||
){
|
||||
m_meshes.push_back(mesh);
|
||||
|
||||
BSP_RotationSetting rotation_setting;
|
||||
BSP_TranslationSetting translation_setting;
|
||||
|
||||
rotation_setting.m_angle_x = MT_Scalar(0);
|
||||
rotation_setting.m_angle_y = MT_Scalar(0);
|
||||
rotation_setting.m_moving = false;
|
||||
rotation_setting.x_old = 0;
|
||||
rotation_setting.y_old = 0;
|
||||
|
||||
translation_setting.m_t_x = MT_Scalar(0);
|
||||
translation_setting.m_t_y = MT_Scalar(0);
|
||||
translation_setting.m_t_z = MT_Scalar(0);
|
||||
translation_setting.m_moving = false;
|
||||
translation_setting.x_old = 0;
|
||||
translation_setting.y_old = 0;
|
||||
|
||||
m_rotation_settings.push_back(rotation_setting);
|
||||
m_translation_settings.push_back(translation_setting);
|
||||
m_render_modes.push_back(e_wireframe_shaded);
|
||||
m_scale_settings.push_back(MT_Scalar(1));
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
Swap(
|
||||
int i
|
||||
){
|
||||
|
||||
if (!m_rotation_settings[i].m_moving && !m_translation_settings[i].m_moving) {
|
||||
swap(m_meshes[i],m_meshes.back());
|
||||
swap(m_rotation_settings[i],m_rotation_settings.back());
|
||||
swap(m_translation_settings[i],m_translation_settings.back());
|
||||
swap(m_scale_settings[i],m_scale_settings.back());
|
||||
swap(m_render_modes[i],m_render_modes.back());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MT_Transform
|
||||
BSP_GhostTestApp3D::
|
||||
GetTransform(
|
||||
int i
|
||||
){
|
||||
|
||||
MT_Quaternion q_ax(MT_Vector3(0,1,0),m_rotation_settings[i].m_angle_x);
|
||||
MT_Quaternion q_ay(MT_Vector3(1,0,0),m_rotation_settings[i].m_angle_y);
|
||||
|
||||
MT_Point3 tr(
|
||||
m_translation_settings[i].m_t_x,
|
||||
m_translation_settings[i].m_t_y,
|
||||
m_translation_settings[i].m_t_z
|
||||
);
|
||||
|
||||
|
||||
MT_Matrix3x3 rotx(q_ax);
|
||||
MT_Matrix3x3 roty(q_ay);
|
||||
|
||||
MT_Matrix3x3 rot = rotx * roty;
|
||||
|
||||
MT_Transform trans(tr,rot);
|
||||
|
||||
MT_Transform scalet;
|
||||
scalet.setIdentity();
|
||||
scalet.scale(m_scale_settings[i],m_scale_settings[i],m_scale_settings[i]);
|
||||
|
||||
return trans * scalet;
|
||||
}
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
Operate(
|
||||
int type
|
||||
){
|
||||
|
||||
CSG_VertexIteratorDescriptor * vA = VertexIt_Construct(m_meshes[0],GetTransform(0));
|
||||
CSG_FaceIteratorDescriptor * fA = FaceIt_Construct(m_meshes[0]);
|
||||
|
||||
CSG_VertexIteratorDescriptor * vB = VertexIt_Construct(m_meshes[1],GetTransform(1));
|
||||
CSG_FaceIteratorDescriptor * fB = FaceIt_Construct(m_meshes[1]);
|
||||
|
||||
// describe properties.
|
||||
|
||||
CSG_MeshPropertyDescriptor props;
|
||||
props.user_face_vertex_data_size = 0;
|
||||
props.user_data_size = 0;
|
||||
|
||||
CSG_BooleanOperation * op = CSG_NewBooleanFunction();
|
||||
props = CSG_DescibeOperands(op,props,props);
|
||||
|
||||
CSG_PerformBooleanOperation(
|
||||
op,CSG_OperationType(type),
|
||||
*fA,*vA,*fB,*vB,EmptyInterpFunc
|
||||
);
|
||||
|
||||
CSG_FaceIteratorDescriptor out_f;
|
||||
CSG_OutputFaceDescriptor(op,&out_f);
|
||||
|
||||
CSG_VertexIteratorDescriptor out_v;
|
||||
CSG_OutputVertexDescriptor(op,&out_v);
|
||||
|
||||
MEM_SmartPtr<BSP_TMesh> new_mesh (BuildMesh(props,out_f,out_v));
|
||||
|
||||
// free stuff
|
||||
|
||||
CSG_FreeVertexDescriptor(&out_v);
|
||||
CSG_FreeFaceDescriptor(&out_f);
|
||||
CSG_FreeBooleanOperation(op);
|
||||
|
||||
op = NULL;
|
||||
SetMesh(new_mesh);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
UpdateFrame(
|
||||
) {
|
||||
if (m_window) {
|
||||
|
||||
GHOST_Rect v_rect;
|
||||
m_window->getClientBounds(v_rect);
|
||||
|
||||
glViewport(0,0,v_rect.getWidth(),v_rect.getHeight());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MT_Vector3
|
||||
BSP_GhostTestApp3D::
|
||||
UnProject(
|
||||
const MT_Vector3 & vec
|
||||
) {
|
||||
|
||||
GLint viewport[4];
|
||||
GLdouble mvmatrix[16],projmatrix[16];
|
||||
|
||||
glGetIntegerv(GL_VIEWPORT,viewport);
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX,mvmatrix);
|
||||
glGetDoublev(GL_PROJECTION_MATRIX,projmatrix);
|
||||
|
||||
GLdouble realy = viewport[3] - vec.y() - 1;
|
||||
GLdouble outx,outy,outz;
|
||||
|
||||
gluUnProject(vec.x(),realy,vec.z(),mvmatrix,projmatrix,viewport,&outx,&outy,&outz);
|
||||
|
||||
return MT_Vector3(outx,outy,outz);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BSP_GhostTestApp3D::
|
||||
InitApp(
|
||||
){
|
||||
|
||||
// create a system and window with opengl
|
||||
// rendering context.
|
||||
|
||||
GHOST_TSuccess success = GHOST_ISystem::createSystem();
|
||||
if (success == GHOST_kFailure) return false;
|
||||
|
||||
m_system = GHOST_ISystem::getSystem();
|
||||
if (m_system == NULL) return false;
|
||||
|
||||
m_system->addEventConsumer(this);
|
||||
|
||||
m_window = m_system->createWindow(
|
||||
"GHOST crud3D!",
|
||||
100,100,512,512,GHOST_kWindowStateNormal,
|
||||
GHOST_kDrawingContextTypeOpenGL,false
|
||||
);
|
||||
|
||||
if (
|
||||
m_window == NULL
|
||||
) {
|
||||
m_system = NULL;
|
||||
GHOST_ISystem::disposeSystem();
|
||||
return false;
|
||||
}
|
||||
|
||||
// make an opengl frustum for this wind
|
||||
|
||||
MT_Vector3 min,max;
|
||||
|
||||
min = m_meshes[0]->m_min;
|
||||
max = m_meshes[0]->m_max;
|
||||
InitOpenGl(min,max);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
Run(
|
||||
){
|
||||
if (m_system == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (!m_finish_me_off) {
|
||||
m_system->processEvents(true);
|
||||
m_system->dispatchEvents();
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
BSP_GhostTestApp3D::
|
||||
processEvent(
|
||||
GHOST_IEvent* event
|
||||
){
|
||||
|
||||
bool handled = false;
|
||||
|
||||
switch(event->getType()) {
|
||||
case GHOST_kEventWindowSize:
|
||||
case GHOST_kEventWindowActivate:
|
||||
UpdateFrame();
|
||||
case GHOST_kEventWindowUpdate:
|
||||
DrawPolies();
|
||||
handled = true;
|
||||
break;
|
||||
case GHOST_kEventButtonDown:
|
||||
{
|
||||
int x,y;
|
||||
m_system->getCursorPosition(x,y);
|
||||
|
||||
|
||||
int wx,wy;
|
||||
m_window->screenToClient(x,y,wx,wy);
|
||||
|
||||
GHOST_TButtonMask button =
|
||||
static_cast<GHOST_TEventButtonData *>(event->getData())->button;
|
||||
|
||||
if (button == GHOST_kButtonMaskLeft) {
|
||||
m_rotation_settings[m_current_object].m_moving = true;
|
||||
m_rotation_settings[m_current_object].x_old = x;
|
||||
m_rotation_settings[m_current_object].y_old = y;
|
||||
} else
|
||||
if (button == GHOST_kButtonMaskRight) {
|
||||
m_translation_settings[m_current_object].m_moving = true;
|
||||
m_translation_settings[m_current_object].x_old = x;
|
||||
m_translation_settings[m_current_object].y_old = y;
|
||||
} else
|
||||
|
||||
m_window->invalidate();
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case GHOST_kEventButtonUp:
|
||||
{
|
||||
|
||||
GHOST_TButtonMask button =
|
||||
static_cast<GHOST_TEventButtonData *>(event->getData())->button;
|
||||
|
||||
if (button == GHOST_kButtonMaskLeft) {
|
||||
m_rotation_settings[m_current_object].m_moving = false;
|
||||
m_rotation_settings[m_current_object].x_old = 0;
|
||||
m_rotation_settings[m_current_object].y_old = 0;
|
||||
|
||||
} else
|
||||
if (button == GHOST_kButtonMaskRight) {
|
||||
m_translation_settings[m_current_object].m_moving = false;
|
||||
m_translation_settings[m_current_object].x_old;
|
||||
m_translation_settings[m_current_object].y_old;
|
||||
|
||||
}
|
||||
m_window->invalidate();
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
case GHOST_kEventCursorMove:
|
||||
{
|
||||
int x,y;
|
||||
m_system->getCursorPosition(x,y);
|
||||
int wx,wy;
|
||||
m_window->screenToClient(x,y,wx,wy);
|
||||
|
||||
if (m_rotation_settings[m_current_object].m_moving) {
|
||||
m_rotation_settings[m_current_object].m_angle_x = MT_Scalar(wx)/20;
|
||||
m_rotation_settings[m_current_object].x_old = wx;
|
||||
m_rotation_settings[m_current_object].m_angle_y = MT_Scalar(wy)/20;
|
||||
m_rotation_settings[m_current_object].y_old = wy;
|
||||
|
||||
m_window->invalidate();
|
||||
}
|
||||
if (m_translation_settings[m_current_object].m_moving) {
|
||||
|
||||
// project current objects bounding box center into screen space.
|
||||
// unproject mouse point into object space using z-value from
|
||||
// projected bounding box center.
|
||||
|
||||
GHOST_Rect bounds;
|
||||
m_window->getClientBounds(bounds);
|
||||
|
||||
int w_h = bounds.getHeight();
|
||||
|
||||
y = w_h - wy;
|
||||
x = wx;
|
||||
|
||||
double mvmatrix[16];
|
||||
double projmatrix[16];
|
||||
GLint viewport[4];
|
||||
|
||||
double px, py, pz,sz;
|
||||
|
||||
/* Get the matrices needed for gluUnProject */
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
|
||||
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
|
||||
|
||||
// work out the position of the end effector in screen space
|
||||
|
||||
GLdouble ex,ey,ez;
|
||||
|
||||
ex = m_translation_settings[m_current_object].m_t_x;
|
||||
ey = m_translation_settings[m_current_object].m_t_y;
|
||||
ez = m_translation_settings[m_current_object].m_t_z;
|
||||
|
||||
gluProject(ex, ey, ez, mvmatrix, projmatrix, viewport, &px, &py, &sz);
|
||||
gluUnProject((GLdouble) x, (GLdouble) y, sz, mvmatrix, projmatrix, viewport, &px, &py, &pz);
|
||||
|
||||
m_translation_settings[m_current_object].m_t_x = px;
|
||||
m_translation_settings[m_current_object].m_t_y = py;
|
||||
m_translation_settings[m_current_object].m_t_z = pz;
|
||||
m_window->invalidate();
|
||||
|
||||
}
|
||||
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case GHOST_kEventKeyDown :
|
||||
{
|
||||
GHOST_TEventKeyData *kd =
|
||||
static_cast<GHOST_TEventKeyData *>(event->getData());
|
||||
|
||||
|
||||
switch(kd->key) {
|
||||
case GHOST_kKeyI:
|
||||
{
|
||||
// now intersect meshes.
|
||||
Operate(e_csg_intersection);
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
}
|
||||
case GHOST_kKeyU:
|
||||
{
|
||||
Operate(e_csg_union);
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
}
|
||||
case GHOST_kKeyD:
|
||||
{
|
||||
Operate(e_csg_difference);
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
}
|
||||
|
||||
case GHOST_kKeyA:
|
||||
{
|
||||
|
||||
m_scale_settings[m_current_object] *= 1.1;
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
}
|
||||
case GHOST_kKeyZ:
|
||||
{
|
||||
m_scale_settings[m_current_object] *= 0.8;
|
||||
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
}
|
||||
|
||||
case GHOST_kKeyR:
|
||||
m_render_modes[m_current_object]++;
|
||||
if (m_render_modes[m_current_object] > e_last_render_mode) {
|
||||
m_render_modes[m_current_object] = e_first_render_mode;
|
||||
}
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
|
||||
case GHOST_kKeyB:
|
||||
handled = true;
|
||||
m_window->invalidate();
|
||||
break;
|
||||
|
||||
case GHOST_kKeyQ:
|
||||
m_finish_me_off = true;
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case GHOST_kKeyS:
|
||||
Swap(m_current_object);
|
||||
m_window->invalidate();
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
case GHOST_kKeySpace:
|
||||
|
||||
// increment the current object only if the object is not being
|
||||
// manipulated.
|
||||
if (! (m_rotation_settings[m_current_object].m_moving || m_translation_settings[m_current_object].m_moving)) {
|
||||
m_current_object ++;
|
||||
if (m_current_object >= m_meshes.size()) {
|
||||
m_current_object = 0;
|
||||
|
||||
}
|
||||
}
|
||||
m_window->invalidate();
|
||||
handled = true;
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
return handled;
|
||||
};
|
||||
|
||||
BSP_GhostTestApp3D::
|
||||
~BSP_GhostTestApp3D(
|
||||
){
|
||||
|
||||
if (m_window) {
|
||||
m_system->disposeWindow(m_window);
|
||||
m_window = NULL;
|
||||
GHOST_ISystem::disposeSystem();
|
||||
m_system = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
DrawPolies(
|
||||
){
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
for (int i = 0; i < m_meshes.size(); ++i) {
|
||||
MT_Transform trans = GetTransform(i);
|
||||
|
||||
float opengl_mat[16];
|
||||
trans.getValue(opengl_mat);
|
||||
|
||||
glPushMatrix();
|
||||
glMultMatrixf(opengl_mat);
|
||||
MT_Vector3 color(1.0,1.0,1.0);
|
||||
if (i == m_current_object) {
|
||||
color = MT_Vector3(1.0,0,0);
|
||||
}
|
||||
BSP_MeshDrawer::DrawMesh(m_meshes[i].Ref(),m_render_modes[i]);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
m_window->swapBuffers();
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
BSP_GhostTestApp3D::
|
||||
InitOpenGl(
|
||||
const MT_Vector3 &min,
|
||||
const MT_Vector3 &max
|
||||
){
|
||||
|
||||
GLfloat light_diffuse0[] = {1.0, 0.0, 0.0, 0.5}; /* Red diffuse light. */
|
||||
GLfloat light_position0[] = {1.0, 1.0, 1.0, 0.0}; /* Infinite light location. */
|
||||
|
||||
GLfloat light_diffuse1[] = {1.0, 1.0, 1.0, 0.5}; /* Red diffuse light. */
|
||||
GLfloat light_position1[] = {1.0, 0, 0, 0.0}; /* Infinite light location. */
|
||||
|
||||
/* Enable a single OpenGL light. */
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
|
||||
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
|
||||
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_LIGHT1);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
// make sure there is no back face culling.
|
||||
// glDisable(GL_CULL_FACE);
|
||||
|
||||
// use two sided lighting model
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
|
||||
|
||||
/* Use depth buffering for hidden surface elimination. */
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* Setup the view of the cube. */
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
// center of the box + 3* depth of box
|
||||
|
||||
MT_Vector3 center = (min + max) * 0.5;
|
||||
MT_Vector3 diag = max - min;
|
||||
|
||||
float depth = diag.length();
|
||||
float distance = 5;
|
||||
|
||||
gluPerspective(
|
||||
/* field of view in degree */ 40.0,
|
||||
/* aspect ratio */ 1.0,
|
||||
/* Z near */ 1.0,
|
||||
/* Z far */ distance * depth * 2
|
||||
);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
gluLookAt(
|
||||
center.x(), center.y(), center.z() + distance*depth, //eye
|
||||
center.x(), center.y(), center.z(), //center
|
||||
0.0, 1.0, 0.
|
||||
); /* up is in positive Y direction */
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,159 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef __BSP_GHOSTTEST3D_H__
|
||||
#define __BSP_GHOSTTEST3D_H__
|
||||
|
||||
#include "GHOST_IEventConsumer.h"
|
||||
#include "MT_Vector3.h"
|
||||
#include "BSP_TMesh.h"
|
||||
#include "BSP_MeshDrawer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class GHOST_IWindow;
|
||||
class GHOST_ISystem;
|
||||
|
||||
|
||||
class BSP_GhostTestApp3D :
|
||||
public GHOST_IEventConsumer
|
||||
{
|
||||
public :
|
||||
// Construct an instance of the application;
|
||||
|
||||
BSP_GhostTestApp3D(
|
||||
);
|
||||
|
||||
// initialize the applicaton
|
||||
|
||||
bool
|
||||
InitApp(
|
||||
);
|
||||
|
||||
// Run the application untill internal return.
|
||||
void
|
||||
Run(
|
||||
);
|
||||
|
||||
~BSP_GhostTestApp3D(
|
||||
);
|
||||
|
||||
void
|
||||
SetMesh(
|
||||
MEM_SmartPtr<BSP_TMesh> mesh
|
||||
);
|
||||
|
||||
private :
|
||||
|
||||
struct BSP_RotationSetting {
|
||||
MT_Scalar m_angle_x;
|
||||
MT_Scalar m_angle_y;
|
||||
int x_old;
|
||||
int y_old;
|
||||
bool m_moving;
|
||||
};
|
||||
|
||||
struct BSP_TranslationSetting {
|
||||
MT_Scalar m_t_x;
|
||||
MT_Scalar m_t_y;
|
||||
MT_Scalar m_t_z;
|
||||
int x_old;
|
||||
int y_old;
|
||||
bool m_moving;
|
||||
};
|
||||
|
||||
// Return the transform of object i
|
||||
|
||||
MT_Transform
|
||||
GetTransform(
|
||||
int active_object
|
||||
);
|
||||
|
||||
// Perform an operation between the first two objects in the
|
||||
// list
|
||||
|
||||
void
|
||||
Operate(
|
||||
int type
|
||||
);
|
||||
|
||||
// Swap mesh i and settings with the last mesh in list.
|
||||
|
||||
void
|
||||
Swap(
|
||||
int i
|
||||
);
|
||||
|
||||
void
|
||||
DrawPolies(
|
||||
);
|
||||
|
||||
void
|
||||
UpdateFrame(
|
||||
);
|
||||
|
||||
MT_Vector3
|
||||
UnProject(
|
||||
const MT_Vector3 & vec
|
||||
);
|
||||
|
||||
// Create a frustum and projection matrix to
|
||||
// look at the bounding box
|
||||
|
||||
void
|
||||
InitOpenGl(
|
||||
const MT_Vector3 &min,
|
||||
const MT_Vector3 &max
|
||||
);
|
||||
|
||||
|
||||
// inherited from GHOST_IEventConsumer
|
||||
bool
|
||||
processEvent(
|
||||
GHOST_IEvent* event
|
||||
);
|
||||
|
||||
GHOST_IWindow *m_window;
|
||||
GHOST_ISystem *m_system;
|
||||
|
||||
bool m_finish_me_off;
|
||||
|
||||
// List of current meshes.
|
||||
std::vector< MEM_SmartPtr<BSP_TMesh> > m_meshes;
|
||||
|
||||
std::vector< BSP_RotationSetting> m_rotation_settings;
|
||||
std::vector< BSP_TranslationSetting> m_translation_settings;
|
||||
std::vector< MT_Scalar> m_scale_settings;
|
||||
std::vector< int> m_render_modes;
|
||||
|
||||
int m_current_object;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,156 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "BSP_MeshDrawer.h"
|
||||
|
||||
#include "BSP_TMesh.h"
|
||||
|
||||
#if defined(WIN32) || defined(__APPLE__)
|
||||
# ifdef WIN32
|
||||
# include <windows.h>
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
# else // WIN32
|
||||
# include <AGL/gl.h>
|
||||
# endif // WIN32
|
||||
#else // defined(WIN32) || defined(__APPLE__)
|
||||
# include <GL/gl.h>
|
||||
# include <GL/glu.h>
|
||||
#endif // defined(WIN32) || defined(__APPLE__)
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
BSP_MeshDrawer::
|
||||
DrawMesh(
|
||||
BSP_TMesh &mesh,
|
||||
int render_mode
|
||||
){
|
||||
|
||||
|
||||
if (render_mode == e_none) return;
|
||||
|
||||
// decompose polygons into triangles.
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
|
||||
if (render_mode == e_wireframe || render_mode == e_wireframe_shaded) {
|
||||
|
||||
glColor3f(0.0, 0.0, 0.0);
|
||||
|
||||
if (render_mode == e_wireframe) {
|
||||
glDisable(GL_LIGHTING);
|
||||
} else {
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
|
||||
glEnable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonOffset(1.0,1.0);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
DrawPolies(mesh);
|
||||
glEnd();
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_POLYGON_OFFSET_FILL);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
DrawPolies(mesh);
|
||||
glEnd();
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
} else {
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
DrawPolies(mesh);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BSP_MeshDrawer::
|
||||
DrawPolies(
|
||||
BSP_TMesh &mesh
|
||||
){
|
||||
|
||||
const vector<BSP_TVertex> & verts = mesh.VertexSet();
|
||||
const vector<BSP_TFace> &faces = mesh.FaceSet();
|
||||
|
||||
// just draw the edges for now.
|
||||
|
||||
vector<BSP_TVertex>::const_iterator vertex_it = verts.begin();
|
||||
|
||||
|
||||
vector<BSP_TFace>::const_iterator faces_it = faces.begin();
|
||||
vector<BSP_TFace>::const_iterator faces_end = faces.end();
|
||||
|
||||
for (;faces_it != faces_end; ++faces_it ){
|
||||
|
||||
glNormal3f(
|
||||
faces_it->m_normal.x(),
|
||||
faces_it->m_normal.y(),
|
||||
faces_it->m_normal.z()
|
||||
);
|
||||
|
||||
glVertex3f(
|
||||
verts[faces_it->m_verts[0]].m_pos.x(),
|
||||
verts[faces_it->m_verts[0]].m_pos.y(),
|
||||
verts[faces_it->m_verts[0]].m_pos.z()
|
||||
);
|
||||
glVertex3f(
|
||||
verts[faces_it->m_verts[1]].m_pos.x(),
|
||||
verts[faces_it->m_verts[1]].m_pos.y(),
|
||||
verts[faces_it->m_verts[1]].m_pos.z()
|
||||
);
|
||||
glVertex3f(
|
||||
verts[faces_it->m_verts[2]].m_pos.x(),
|
||||
verts[faces_it->m_verts[2]].m_pos.y(),
|
||||
verts[faces_it->m_verts[2]].m_pos.z()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,71 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef __BSP_MESHDRAWER_H__
|
||||
#define __BSP_MESHDRAWER_H__
|
||||
|
||||
class BSP_TMesh;
|
||||
class MT_Vector3;
|
||||
|
||||
enum BSP_TRenderMode {
|
||||
e_shaded,
|
||||
e_none,
|
||||
e_wireframe,
|
||||
e_wireframe_shaded,
|
||||
e_first_render_mode = e_shaded,
|
||||
e_last_render_mode = e_wireframe_shaded
|
||||
};
|
||||
|
||||
class BSP_MeshDrawer
|
||||
{
|
||||
public :
|
||||
static
|
||||
void
|
||||
DrawMesh(
|
||||
BSP_TMesh &mesh,
|
||||
int render_mode
|
||||
);
|
||||
|
||||
private :
|
||||
|
||||
static
|
||||
void
|
||||
DrawPolies(
|
||||
BSP_TMesh &mesh
|
||||
);
|
||||
|
||||
|
||||
BSP_MeshDrawer(
|
||||
);
|
||||
|
||||
~BSP_MeshDrawer(
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,192 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "BSP_PlyLoader.h"
|
||||
|
||||
#include "MT_Vector3.h"
|
||||
#include "ply.h"
|
||||
|
||||
struct LoadVertex {
|
||||
float x,y,z; /* the usual 3-space position of a vertex */
|
||||
};
|
||||
|
||||
struct LoadFace {
|
||||
unsigned char intensity; /* this user attaches intensity to faces */
|
||||
unsigned char nverts; /* number of vertex indices in list */
|
||||
int *verts; /* vertex index list */
|
||||
};
|
||||
|
||||
|
||||
MEM_SmartPtr<BSP_TMesh>
|
||||
BSP_PlyLoader::
|
||||
NewMeshFromFile(
|
||||
char * file_name,
|
||||
MT_Vector3 &min,
|
||||
MT_Vector3 &max
|
||||
|
||||
) {
|
||||
|
||||
min = MT_Vector3(MT_INFINITY,MT_INFINITY,MT_INFINITY);
|
||||
max = MT_Vector3(-MT_INFINITY,-MT_INFINITY,-MT_INFINITY);
|
||||
|
||||
PlyProperty vert_props[] = { /* list of property information for a vertex */
|
||||
{"x", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,x), 0, 0, 0, 0},
|
||||
{"y", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,y), 0, 0, 0, 0},
|
||||
{"z", PLY_FLOAT, PLY_FLOAT, offsetof(LoadVertex,z), 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
PlyProperty face_props[] = { /* list of property information for a vertex */
|
||||
{"vertex_indices", PLY_INT, PLY_INT, offsetof(LoadFace,verts),
|
||||
1, PLY_UCHAR, PLY_UCHAR, offsetof(LoadFace,nverts)},
|
||||
};
|
||||
|
||||
MEM_SmartPtr<BSP_TMesh> mesh = new BSP_TMesh;
|
||||
|
||||
if (mesh == NULL) return NULL;
|
||||
|
||||
int i,j;
|
||||
PlyFile *ply;
|
||||
int nelems;
|
||||
char **elist;
|
||||
int file_type;
|
||||
float version;
|
||||
int nprops;
|
||||
int num_elems;
|
||||
PlyProperty **plist;
|
||||
|
||||
char *elem_name;
|
||||
|
||||
LoadVertex load_vertex;
|
||||
LoadFace load_face;
|
||||
|
||||
/* open a PLY file for reading */
|
||||
ply = ply_open_for_reading(
|
||||
file_name,
|
||||
&nelems,
|
||||
&elist,
|
||||
&file_type,
|
||||
&version
|
||||
);
|
||||
|
||||
if (ply == NULL) return NULL;
|
||||
|
||||
/* go through each kind of element that we learned is in the file */
|
||||
/* and read them */
|
||||
|
||||
for (i = 0; i < nelems; i++) {
|
||||
|
||||
/* get the description of the first element */
|
||||
|
||||
elem_name = elist[i];
|
||||
plist = ply_get_element_description (ply, elem_name, &num_elems, &nprops);
|
||||
|
||||
/* print the name of the element, for debugging */
|
||||
|
||||
/* if we're on vertex elements, read them in */
|
||||
|
||||
if (equal_strings ("vertex", elem_name)) {
|
||||
|
||||
/* set up for getting vertex elements */
|
||||
|
||||
ply_get_property (ply, elem_name, &vert_props[0]);
|
||||
ply_get_property (ply, elem_name, &vert_props[1]);
|
||||
ply_get_property (ply, elem_name, &vert_props[2]);
|
||||
|
||||
// make some memory for the vertices
|
||||
mesh->VertexSet().reserve(num_elems);
|
||||
|
||||
/* grab all the vertex elements */
|
||||
for (j = 0; j < num_elems; j++) {
|
||||
|
||||
/* grab and element from the file */
|
||||
ply_get_element (ply, (void *)&load_vertex);
|
||||
// pass the vertex into the mesh builder.
|
||||
|
||||
if (load_vertex.x < min.x()) {
|
||||
min.x() = load_vertex.x;
|
||||
} else
|
||||
if (load_vertex.x > max.x()) {
|
||||
max.x()= load_vertex.x;
|
||||
}
|
||||
|
||||
if (load_vertex.y < min.y()) {
|
||||
min.y() = load_vertex.y;
|
||||
} else
|
||||
if (load_vertex.y > max.y()) {
|
||||
max.y()= load_vertex.y;
|
||||
}
|
||||
|
||||
if (load_vertex.z < min.z()) {
|
||||
min.z() = load_vertex.z;
|
||||
} else
|
||||
if (load_vertex.z > max.z()) {
|
||||
max.z()= load_vertex.z;
|
||||
}
|
||||
|
||||
BSP_TVertex my_vert;
|
||||
my_vert.m_pos = MT_Vector3(load_vertex.x,load_vertex.y,load_vertex.z);
|
||||
mesh->VertexSet().push_back(my_vert);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* if we're on face elements, read them in */
|
||||
if (equal_strings ("face", elem_name)) {
|
||||
|
||||
/* set up for getting face elements */
|
||||
|
||||
ply_get_property (ply, elem_name, &face_props[0]);
|
||||
|
||||
/* grab all the face elements */
|
||||
for (j = 0; j < num_elems; j++) {
|
||||
|
||||
ply_get_element (ply, (void *)&load_face);
|
||||
|
||||
int v;
|
||||
for (v = 2; v< load_face.nverts; v++) {
|
||||
|
||||
BSP_TFace f;
|
||||
|
||||
f.m_verts[0] = load_face.verts[0];
|
||||
f.m_verts[1] = load_face.verts[v-1];
|
||||
f.m_verts[2] = load_face.verts[v];
|
||||
|
||||
mesh->BuildNormal(f);
|
||||
mesh->FaceSet().push_back(f);
|
||||
}
|
||||
// free up the memory this pile of shit used to allocate the polygon's vertices
|
||||
free (load_face.verts);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/* close the PLY file */
|
||||
ply_close (ply);
|
||||
|
||||
return mesh;
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef __BSP_PLYLOADER_H__
|
||||
#define __BSP_PLYLOADER_H__
|
||||
|
||||
#include "MEM_SmartPtr.h"
|
||||
#include "BSP_TMesh.h"
|
||||
|
||||
class BSP_PlyLoader {
|
||||
public :
|
||||
|
||||
static
|
||||
MEM_SmartPtr<BSP_TMesh>
|
||||
NewMeshFromFile(
|
||||
char * file_name,
|
||||
MT_Vector3 &min,
|
||||
MT_Vector3 &max
|
||||
);
|
||||
|
||||
|
||||
private :
|
||||
|
||||
// unimplemented - not for instantiation.
|
||||
|
||||
BSP_PlyLoader(
|
||||
);
|
||||
|
||||
~BSP_PlyLoader(
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,397 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef __BSP_TMESH_H__
|
||||
#define __BSP_TMESH_H__
|
||||
|
||||
#include "MT_Point3.h"
|
||||
#include "MT_Vector3.h"
|
||||
#include "MT_Transform.h"
|
||||
|
||||
#include "MEM_SmartPtr.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "CSG_BooleanOps.h"
|
||||
|
||||
/**
|
||||
* A very basic test mesh.
|
||||
*/
|
||||
|
||||
struct BSP_TVertex {
|
||||
MT_Point3 m_pos;
|
||||
};
|
||||
|
||||
struct BSP_TFace {
|
||||
int m_verts[3];
|
||||
MT_Vector3 m_normal;
|
||||
};
|
||||
|
||||
|
||||
class BSP_TMesh {
|
||||
public :
|
||||
|
||||
std::vector<BSP_TVertex> m_verts;
|
||||
std::vector<BSP_TFace> m_faces;
|
||||
|
||||
MT_Vector3 m_min,m_max;
|
||||
|
||||
std::vector<BSP_TVertex> &
|
||||
VertexSet(
|
||||
){
|
||||
return m_verts;
|
||||
}
|
||||
|
||||
std::vector<BSP_TFace> &
|
||||
FaceSet(
|
||||
) {
|
||||
return m_faces;
|
||||
}
|
||||
|
||||
void
|
||||
AddFace(
|
||||
int *verts,
|
||||
int num_verts
|
||||
){
|
||||
int i;
|
||||
for (i= 2; i <num_verts; i++) {
|
||||
BSP_TFace f;
|
||||
f.m_verts[0] = verts[0];
|
||||
f.m_verts[1] = verts[i-1];
|
||||
f.m_verts[2] = verts[i];
|
||||
|
||||
m_faces.push_back(f);
|
||||
|
||||
BuildNormal(m_faces.back());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BuildNormal(
|
||||
BSP_TFace & f
|
||||
) const {
|
||||
MT_Vector3 l1 =
|
||||
m_verts[f.m_verts[1]].m_pos -
|
||||
m_verts[f.m_verts[0]].m_pos;
|
||||
MT_Vector3 l2 =
|
||||
m_verts[f.m_verts[2]].m_pos -
|
||||
m_verts[f.m_verts[1]].m_pos;
|
||||
|
||||
MT_Vector3 normal = l1.cross(l2);
|
||||
|
||||
f.m_normal = normal.safe_normalized();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* some iterator functions to describe the mesh to the BSP module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class defines 2 C style iterators over a CSG mesh, one for
|
||||
* vertices and 1 for faces. They conform to the iterator interface
|
||||
* defined in CSG_BooleanOps.h
|
||||
*/
|
||||
|
||||
struct VertexIt {
|
||||
BSP_TMesh * mesh;
|
||||
BSP_TVertex * pos;
|
||||
MT_Transform trans;
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
VertexIt_Destruct(
|
||||
CSG_VertexIteratorDescriptor * iterator
|
||||
) {
|
||||
delete ((VertexIt *)(iterator->it));
|
||||
iterator->it = NULL;
|
||||
delete(iterator);
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
int
|
||||
VertexIt_Done(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
VertexIt * vertex_it = (VertexIt *)it;
|
||||
|
||||
if (vertex_it->pos < vertex_it->mesh->VertexSet().end()) return 0;
|
||||
return 1;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
VertexIt_Fill(
|
||||
CSG_IteratorPtr it,
|
||||
CSG_IVertex *vert
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
VertexIt * vertex_it = (VertexIt *)it;
|
||||
|
||||
MT_Point3 p = vertex_it->pos->m_pos;
|
||||
p = vertex_it->trans * p;
|
||||
|
||||
p.getValue(vert->position);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
VertexIt_Step(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
VertexIt * vertex_it = (VertexIt *)it;
|
||||
|
||||
++(vertex_it->pos);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
VertexIt_Reset(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
VertexIt * vertex_it = (VertexIt *)it;
|
||||
|
||||
vertex_it->pos = vertex_it->mesh->VertexSet().begin();
|
||||
};
|
||||
|
||||
static
|
||||
CSG_VertexIteratorDescriptor *
|
||||
VertexIt_Construct(
|
||||
BSP_TMesh *mesh,
|
||||
MT_Transform trans
|
||||
){
|
||||
// user should have insured mesh is not equal to NULL.
|
||||
|
||||
CSG_VertexIteratorDescriptor * output = new CSG_VertexIteratorDescriptor;
|
||||
if (output == NULL) return NULL;
|
||||
output->Done = VertexIt_Done;
|
||||
output->Fill = VertexIt_Fill;
|
||||
output->Step = VertexIt_Step;
|
||||
output->Reset = VertexIt_Reset;
|
||||
output->num_elements = mesh->VertexSet().size();
|
||||
|
||||
VertexIt * v_it = new VertexIt;
|
||||
v_it->mesh = mesh;
|
||||
v_it->pos = mesh->VertexSet().begin();
|
||||
v_it->trans = trans;
|
||||
output->it = v_it;
|
||||
return output;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Face iterator.
|
||||
*/
|
||||
|
||||
struct FaceIt {
|
||||
BSP_TMesh * mesh;
|
||||
BSP_TFace *pos;
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
FaceIt_Destruct(
|
||||
CSG_FaceIteratorDescriptor * iterator
|
||||
) {
|
||||
delete ((FaceIt *)(iterator->it));
|
||||
iterator->it = NULL;
|
||||
delete(iterator);
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
int
|
||||
FaceIt_Done(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
FaceIt * face_it = (FaceIt *)it;
|
||||
|
||||
if (face_it->pos < face_it->mesh->FaceSet().end()) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
FaceIt_Fill(
|
||||
CSG_IteratorPtr it,
|
||||
CSG_IFace *face
|
||||
){
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
FaceIt * face_it = (FaceIt *)it;
|
||||
// essentially iterating through a triangle fan here.
|
||||
|
||||
face->vertex_index[0] = int(face_it->pos->m_verts[0]);
|
||||
face->vertex_index[1] = int(face_it->pos->m_verts[1]);
|
||||
face->vertex_index[2] = int(face_it->pos->m_verts[2]);
|
||||
|
||||
face->vertex_number = 3;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
FaceIt_Step(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
FaceIt * face_it = (FaceIt *)it;
|
||||
|
||||
face_it->pos ++;
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
FaceIt_Reset(
|
||||
CSG_IteratorPtr it
|
||||
) {
|
||||
// assume CSG_IteratorPtr is of the correct type.
|
||||
FaceIt * face_it = (FaceIt *)it;
|
||||
|
||||
face_it->pos = face_it->mesh->FaceSet().begin();
|
||||
};
|
||||
|
||||
static
|
||||
CSG_FaceIteratorDescriptor *
|
||||
FaceIt_Construct(
|
||||
BSP_TMesh * mesh
|
||||
) {
|
||||
CSG_FaceIteratorDescriptor * output = new CSG_FaceIteratorDescriptor;
|
||||
if (output == NULL) return NULL;
|
||||
|
||||
output->Done = FaceIt_Done;
|
||||
output->Fill = FaceIt_Fill;
|
||||
output->Step = FaceIt_Step;
|
||||
output->Reset = FaceIt_Reset;
|
||||
|
||||
output->num_elements = mesh->FaceSet().size();
|
||||
|
||||
FaceIt * f_it = new FaceIt;
|
||||
f_it->mesh = mesh;
|
||||
f_it->pos = mesh->FaceSet().begin();
|
||||
|
||||
output->it = f_it;
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
/**
|
||||
* Some Build functions.
|
||||
*/
|
||||
|
||||
static
|
||||
MEM_SmartPtr<BSP_TMesh>
|
||||
BuildMesh(
|
||||
CSG_MeshPropertyDescriptor &props,
|
||||
CSG_FaceIteratorDescriptor &face_it,
|
||||
CSG_VertexIteratorDescriptor &vertex_it
|
||||
) {
|
||||
MEM_SmartPtr<BSP_TMesh> mesh = new BSP_TMesh();
|
||||
|
||||
CSG_IVertex vert;
|
||||
|
||||
while (!vertex_it.Done(vertex_it.it)) {
|
||||
|
||||
vertex_it.Fill(vertex_it.it,&vert);
|
||||
|
||||
BSP_TVertex v;
|
||||
v.m_pos = MT_Point3(vert.position);
|
||||
mesh->VertexSet().push_back(v);
|
||||
|
||||
vertex_it.Step(vertex_it.it);
|
||||
}
|
||||
|
||||
|
||||
CSG_IFace face;
|
||||
|
||||
while (!face_it.Done(face_it.it)) {
|
||||
face_it.Fill(face_it.it,&face);
|
||||
|
||||
BSP_TFace f;
|
||||
|
||||
f.m_verts[0] = face.vertex_index[0],
|
||||
f.m_verts[1] = face.vertex_index[1],
|
||||
f.m_verts[2] = face.vertex_index[2],
|
||||
|
||||
mesh->BuildNormal(f);
|
||||
|
||||
mesh->FaceSet().push_back(f);
|
||||
|
||||
face_it.Step(face_it.it);
|
||||
}
|
||||
|
||||
return mesh;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -1,143 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "BSP_GhostTest3D.h"
|
||||
|
||||
#include "BSP_TMesh.h"
|
||||
#include "MEM_SmartPtr.h"
|
||||
#include "BSP_PlyLoader.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
#if 1
|
||||
MEM_SmartPtr<BSP_TMesh>
|
||||
NewTestMesh(
|
||||
int x,
|
||||
int y,
|
||||
MT_Scalar fx,
|
||||
MT_Scalar fy,
|
||||
MT_Scalar ampx,
|
||||
MT_Scalar ampy,
|
||||
MT_Scalar sx,
|
||||
MT_Scalar sy
|
||||
) {
|
||||
|
||||
MEM_SmartPtr<BSP_TMesh> output = new BSP_TMesh;
|
||||
|
||||
std::vector<BSP_TVertex> &verts = output->VertexSet();
|
||||
|
||||
int i,j;
|
||||
|
||||
MT_Scalar x_scale = fx*MT_PI/x;
|
||||
MT_Scalar y_scale = fy*MT_PI/y;
|
||||
|
||||
MT_Scalar fsx = sx/x;
|
||||
MT_Scalar fsy = sy/y;
|
||||
|
||||
for (j = 0; j < y; j++) {
|
||||
for (i = 0; i < x; i++) {
|
||||
float z = ampx*sin(x_scale * i) + ampy*sin(y_scale * j);
|
||||
|
||||
MT_Vector3 val(i*fsx - sx/2,j*fsy - sy/2,z);
|
||||
|
||||
BSP_TVertex chuff;
|
||||
chuff.m_pos = val;
|
||||
verts.push_back(chuff);
|
||||
}
|
||||
}
|
||||
|
||||
int poly[4];
|
||||
|
||||
for (j = 0; j < (y-1); j++) {
|
||||
for (i = 0; i < (x-1); i++) {
|
||||
|
||||
poly[0] = j*x + i;
|
||||
poly[1] = poly[0] + 1;
|
||||
poly[2] = poly[1] + y;
|
||||
poly[3] = poly[2] -1;
|
||||
|
||||
output->AddFace(poly,4);
|
||||
}
|
||||
}
|
||||
|
||||
output->m_min = MT_Vector3(-sx/2,-sy/2,-ampx -ampy);
|
||||
output->m_max = MT_Vector3(sx/2,sy/2,ampx + ampy);
|
||||
|
||||
return output;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
MT_Vector3 min,max;
|
||||
MT_Vector3 min2,max2;
|
||||
|
||||
#if 1
|
||||
MEM_SmartPtr<BSP_TMesh> mesh1 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min,max);
|
||||
MEM_SmartPtr<BSP_TMesh> mesh2 = BSP_PlyLoader::NewMeshFromFile("bsp_cube.ply",min2,max2);
|
||||
|
||||
mesh1->m_min = min;
|
||||
mesh1->m_max = max;
|
||||
mesh2->m_min = min2;
|
||||
mesh1->m_max = max2;
|
||||
|
||||
#else
|
||||
MEM_SmartPtr<BSP_TMesh> mesh1 = NewTestMesh(10,10,2,2,4,4,20,20);
|
||||
MEM_SmartPtr<BSP_TMesh> mesh2 = NewTestMesh(10,10,2,2,4,4,20,20);
|
||||
#endif
|
||||
|
||||
if (!mesh1) {
|
||||
cout << "could not load mesh!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// MEM_SmartPtr<BSP_TMesh> mesh2 = new BSP_TMesh(mesh1.Ref());
|
||||
|
||||
BSP_GhostTestApp3D app;
|
||||
|
||||
cout << "Mesh polygons :" << mesh1->FaceSet().size() << "\n";
|
||||
cout << "Mesh vertices :" << mesh1->VertexSet().size() << "\n";
|
||||
|
||||
app.SetMesh(mesh1);
|
||||
app.SetMesh(mesh2);
|
||||
|
||||
|
||||
app.InitApp();
|
||||
|
||||
app.Run();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -1,196 +0,0 @@
|
||||
/**
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): none yet.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Header for PLY polygon files.
|
||||
|
||||
- Greg Turk, March 1994
|
||||
|
||||
A PLY file contains a single polygonal _object_.
|
||||
|
||||
An object is composed of lists of _elements_. Typical elements are
|
||||
vertices, faces, edges and materials.
|
||||
|
||||
Each type of element for a given object has one or more _properties_
|
||||
associated with the element type. For instance, a vertex element may
|
||||
have as properties three floating-point values x,y,z and three unsigned
|
||||
chars for red, green and blue.
|
||||
|
||||
---------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1994 The Board of Trustees of The Leland Stanford
|
||||
Junior University. All rights reserved.
|
||||
|
||||
Permission to use, copy, modify and distribute this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided
|
||||
that the above copyright notice and this permission notice appear in
|
||||
all copies of this software and that you do not sell the software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __PLY_H__
|
||||
#define __PLY_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define PLY_ASCII 1 /* ascii PLY file */
|
||||
#define PLY_BINARY_BE 2 /* binary PLY file, big endian */
|
||||
#define PLY_BINARY_LE 3 /* binary PLY file, little endian */
|
||||
|
||||
#define PLY_OKAY 0 /* ply routine worked okay */
|
||||
#define PLY_ERROR -1 /* error in ply routine */
|
||||
|
||||
/* scalar data types supported by PLY format */
|
||||
|
||||
#define PLY_START_TYPE 0
|
||||
#define PLY_CHAR 1
|
||||
#define PLY_SHORT 2
|
||||
#define PLY_INT 3
|
||||
#define PLY_UCHAR 4
|
||||
#define PLY_USHORT 5
|
||||
#define PLY_UINT 6
|
||||
#define PLY_FLOAT 7
|
||||
#define PLY_DOUBLE 8
|
||||
#define PLY_END_TYPE 9
|
||||
|
||||
#define PLY_SCALAR 0
|
||||
#define PLY_LIST 1
|
||||
|
||||
|
||||
typedef struct PlyProperty { /* description of a property */
|
||||
|
||||
char *name; /* property name */
|
||||
int external_type; /* file's data type */
|
||||
int internal_type; /* program's data type */
|
||||
int offset; /* offset bytes of prop in a struct */
|
||||
|
||||
int is_list; /* 1 = list, 0 = scalar */
|
||||
int count_external; /* file's count type */
|
||||
int count_internal; /* program's count type */
|
||||
int count_offset; /* offset byte for list count */
|
||||
|
||||
} PlyProperty;
|
||||
|
||||
typedef struct PlyElement { /* description of an element */
|
||||
char *name; /* element name */
|
||||
int num; /* number of elements in this object */
|
||||
int size; /* size of element (bytes) or -1 if variable */
|
||||
int nprops; /* number of properties for this element */
|
||||
PlyProperty **props; /* list of properties in the file */
|
||||
char *store_prop; /* flags: property wanted by user? */
|
||||
int other_offset; /* offset to un-asked-for props, or -1 if none*/
|
||||
int other_size; /* size of other_props structure */
|
||||
} PlyElement;
|
||||
|
||||
typedef struct PlyOtherProp { /* describes other properties in an element */
|
||||
char *name; /* element name */
|
||||
int size; /* size of other_props */
|
||||
int nprops; /* number of properties in other_props */
|
||||
PlyProperty **props; /* list of properties in other_props */
|
||||
} PlyOtherProp;
|
||||
|
||||
typedef struct OtherData { /* for storing other_props for an other element */
|
||||
void *other_props;
|
||||
} OtherData;
|
||||
|
||||
typedef struct OtherElem { /* data for one "other" element */
|
||||
char *elem_name; /* names of other elements */
|
||||
int elem_count; /* count of instances of each element */
|
||||
OtherData **other_data; /* actual property data for the elements */
|
||||
PlyOtherProp *other_props; /* description of the property data */
|
||||
} OtherElem;
|
||||
|
||||
typedef struct PlyOtherElems { /* "other" elements, not interpreted by user */
|
||||
int num_elems; /* number of other elements */
|
||||
OtherElem *other_list; /* list of data for other elements */
|
||||
} PlyOtherElems;
|
||||
|
||||
typedef struct PlyFile { /* description of PLY file */
|
||||
FILE *fp; /* file pointer */
|
||||
int file_type; /* ascii or binary */
|
||||
float version; /* version number of file */
|
||||
int nelems; /* number of elements of object */
|
||||
PlyElement **elems; /* list of elements */
|
||||
int num_comments; /* number of comments */
|
||||
char **comments; /* list of comments */
|
||||
int num_obj_info; /* number of items of object information */
|
||||
char **obj_info; /* list of object info items */
|
||||
PlyElement *which_elem; /* which element we're currently writing */
|
||||
PlyOtherElems *other_elems; /* "other" elements from a PLY file */
|
||||
} PlyFile;
|
||||
|
||||
/* memory allocation */
|
||||
static char *my_alloc();
|
||||
#define myalloc(mem_size) my_alloc((mem_size), __LINE__, __FILE__)
|
||||
|
||||
|
||||
/*** delcaration of routines ***/
|
||||
|
||||
extern PlyFile *ply_write(FILE *, int, char **, int);
|
||||
extern PlyFile *ply_open_for_writing(char *, int, char **, int, float *);
|
||||
extern void ply_describe_element(PlyFile *, char *, int, int, PlyProperty *);
|
||||
extern void ply_describe_property(PlyFile *, char *, PlyProperty *);
|
||||
extern void ply_element_count(PlyFile *, char *, int);
|
||||
extern void ply_header_complete(PlyFile *);
|
||||
extern void ply_put_element_setup(PlyFile *, char *);
|
||||
extern void ply_put_element(PlyFile *, void *);
|
||||
extern void ply_put_comment(PlyFile *, char *);
|
||||
extern void ply_put_obj_info(PlyFile *, char *);
|
||||
extern PlyFile *ply_read(FILE *, int *, char ***);
|
||||
extern PlyFile *ply_open_for_reading( char *, int *, char ***, int *, float *);
|
||||
extern PlyProperty **ply_get_element_description(PlyFile *, char *, int*, int*);
|
||||
extern void ply_get_element_setup( PlyFile *, char *, int, PlyProperty *);
|
||||
extern void ply_get_property(PlyFile *, char *, PlyProperty *);
|
||||
extern PlyOtherProp *ply_get_other_properties(PlyFile *, char *, int);
|
||||
extern void ply_get_element(PlyFile *, void *);
|
||||
extern char **ply_get_comments(PlyFile *, int *);
|
||||
extern char **ply_get_obj_info(PlyFile *, int *);
|
||||
extern void ply_close(PlyFile *);
|
||||
extern void ply_get_info(PlyFile *, float *, int *);
|
||||
extern PlyOtherElems *ply_get_other_element (PlyFile *, char *, int);
|
||||
extern void ply_describe_other_elements ( PlyFile *, PlyOtherElems *);
|
||||
extern void ply_put_other_elements (PlyFile *);
|
||||
extern void ply_free_other_elements (PlyOtherElems *);
|
||||
|
||||
extern int equal_strings(char *, char *);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* !__PLY_H__ */
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user