Initial Import

master
egon.rath 2010-04-21 14:48:36 +00:00
commit 290c2f494c
21 changed files with 1143 additions and 0 deletions

40
B3View.pro Normal file
View File

@ -0,0 +1,40 @@
CONFIG -= qt
DESTDIR = build
OBJECTS_DIR = tmp
SOURCES += main.cpp \
Engine.cpp \
EventHandler.cpp \
UserInterface.cpp \
Debug.cpp \
View.cpp \
Utils.cpp
HEADERS += Engine.h \
EventHandler.h \
UserInterface.h \
Debug.h \
View.h \
Utils.h
CONFIG += warn_off
# Irrlicht
# it's tailored to use svn on linux, and the stable build on windows
unix {
IRRLICHTBASE = /home/er/tmp/irrlicht/trunk
}
win32 {
IRRLICHTBASE = d:/libs/irrlicht-1.7.1
}
INCLUDEPATH += $$IRRLICHTBASE/include
unix {
LIBS += -L$$IRRLICHTBASE/source/Irrlicht \
-lIrrlicht \
-lX11 \
-lGL \
-lXxf86vm
}
win32 {
LIBS += -L$$IRRLICHTBASE/lib/Win32-gcc \
-lIrrlicht
}

8
Debug.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "Debug.h"
ostream & debug()
{
std::flush( cout );
return cout;
}

15
Debug.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <iostream>
#include <cassert>
using std::cout;
using std::endl;
using std::ostream;
using std::wcout;
using std::wcerr;
ostream & debug();
#endif // DEBUG_H

169
Engine.cpp Normal file
View File

@ -0,0 +1,169 @@
#include "Engine.h"
/* //////////////////////////////////////////////////////////////////////////
PRIVATE METHODS
/////////////////////////////////////////////////////////////////////// */
void Engine::setupScene()
{
// Setup Light
ILightSceneNode *light = m_Scene->addLightSceneNode();
light->setID( SIID_LIGHT );
light->setLightType( ELT_DIRECTIONAL );
light->getLightData().AmbientColor = SColorf( 0.2f, 0.2f, 0.2f );
light->getLightData().DiffuseColor = SColorf( 0.8f, 0.8f, 0.8f );
m_Scene->setAmbientLight( SColorf( 0.2f, 0.2f, 0.2f ));
// Setup Camera
ICameraSceneNode *camera = m_Scene->addCameraSceneNode( 0, vector3df( 0, 0, -10 ), vector3df() );
camera->setAspectRatio(( f32 ) m_Driver->getScreenSize().Width / m_Driver->getScreenSize().Height );
}
IGUIEnvironment * Engine::getGUIEnvironment() const
{
return m_Device->getGUIEnvironment();
}
void Engine::drawAxisLines()
{
SMaterial *lineX = new SMaterial();
lineX->Lighting = false;
lineX->EmissiveColor = SColor( 255, 255, 0, 0 );
lineX->Thickness = 1.0f;
SMaterial *lineY = new SMaterial( *lineX );
lineY->EmissiveColor = SColor( 255, 0, 255, 0 );
SMaterial *lineZ = new SMaterial( *lineX );
lineZ->EmissiveColor = SColor( 255, 0, 0, 255 );
m_Driver->setTransform( ETS_WORLD, matrix4() );
m_Driver->setMaterial( *lineX );
m_Driver->draw3DLine( vector3df(), vector3df( 5, 0, 0 ), SColor( 255, 255, 0, 0 ));
position2d<s32> textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( vector3df( 5.2, 0, 0 ));
dimension2d<u32> textSize = m_AxisFont->getDimension( L"X+" );
m_AxisFont->draw( L"X+", rect<s32>( textPos, textSize ), SColor( 255, 255, 0, 0 ), true, true );
m_Driver->setMaterial( *lineY );
m_Driver->draw3DLine( vector3df(), vector3df( 0, 5, 0 ), SColor( 255, 0, 255, 0 ));
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( vector3df( 0, 5.2, 0 ));
textSize = m_AxisFont->getDimension( L"Y+" );
m_AxisFont->draw( L"Y+", rect<s32>( textPos, textSize ), SColor( 255, 0, 255, 0 ), true, true );
m_Driver->setMaterial( *lineZ );
m_Driver->draw3DLine( vector3df(), vector3df( 0, 0, 5 ), SColor( 255, 0, 0, 255 ));
textPos = m_Scene->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition( vector3df( 0, 0, 5.2 ));
textSize = m_AxisFont->getDimension( L"Z+" );
m_AxisFont->draw( L"Z+", rect<s32>( textPos, textSize ), SColor( 255, 0, 0, 255 ), true, true );
delete lineX;
delete lineY;
delete lineZ;
}
void Engine::drawBackground()
{
dimension2d<u32> screenSize = m_Driver->getScreenSize();
m_Driver->draw2DRectangle( rect<s32>( 0, 0, screenSize.Width, screenSize.Height ),
SColor( 255, 128, 128, 255 ),
SColor( 255, 128, 128, 255 ),
SColor( 255, 224, 224, 255 ),
SColor( 255, 224, 224, 255 ));
}
void Engine::loadMesh( const wstring &fileName )
{
if( m_LoadedMesh != 0 )
m_LoadedMesh->remove();
m_LoadedMesh = m_Scene->addAnimatedMeshSceneNode( m_Scene->getMesh( fileName.c_str() ));
}
void Engine::checkResize()
{
if(( m_WindowSize->Width != m_Driver->getScreenSize().Width ) || ( m_WindowSize->Height != m_Driver->getScreenSize().Height ))
{
m_WindowSize->Width = m_Driver->getScreenSize().Width;
m_WindowSize->Height = m_Driver->getScreenSize().Height;
f32 aspectRatio = (f32) m_WindowSize->Width / m_WindowSize->Height;
debug() << "Setting aspect to: " << aspectRatio << endl;
m_Scene->getActiveCamera()->setAspectRatio( aspectRatio );
}
}
/* //////////////////////////////////////////////////////////////////////////
PUBLIC METHODS
/////////////////////////////////////////////////////////////////////// */
Engine::Engine()
{
m_Device = createDevice( EDT_OPENGL, dimension2d<u32>( 1024, 768 ), 32, false, false, false, 0 );
m_Device->setResizable( true );
m_EventHandler = new EventHandler( m_Device );
m_Device->setEventReceiver( m_EventHandler );
m_Driver = m_Device->getVideoDriver();
m_Scene = m_Device->getSceneManager();
m_Device->setWindowCaption( L"Blitz3D Viewer" );
setupScene();
// Setup User Interface
m_UserInterface = new UserInterface( this );
m_EventHandler->addEventReceiver( ERT_USERINTERFACE, m_UserInterface );
// Setup 3D View
m_View = new View( this );
m_EventHandler->addEventReceiver( ERT_3DVIEW, m_View );
// Load font for displaying Axis names
m_AxisFont = m_Device->getGUIEnvironment()->getFont( "arial.xml" );
// Set Engine enabled
m_RunEngine = true;
// Load test model
m_LoadedMesh = 0;
loadMesh( L"test.b3d" );
// Store actual window size
m_WindowSize = new dimension2d<u32>();
m_WindowSize->Width = m_Driver->getScreenSize().Width;
m_WindowSize->Height = m_Driver->getScreenSize().Height;
}
Engine::~Engine()
{
m_Device->drop();
delete m_WindowSize;
}
void Engine::run()
{
u32 timePerFrame = ( u32 ) ( 1000.0f / 60 );
ITimer *timer = m_Device->getTimer();
// Run the Device with 60 frames/sec
while( m_Device->run() && m_RunEngine )
{
u32 startTime = timer->getRealTime();
checkResize();
m_Driver->beginScene();
drawBackground(); // Draw Background
drawAxisLines(); // Draw XYZ Axis
m_Scene->drawAll(); // Draw Scenegraph
m_UserInterface->getGUIEnvironment()->drawAll();
m_Driver->endScene();
u32 sleepTime = timePerFrame - ( timer->getRealTime() - startTime );
if( sleepTime > 0 && sleepTime < timePerFrame )
m_Device->sleep( sleepTime, false );
}
}

66
Engine.h Normal file
View File

@ -0,0 +1,66 @@
#ifndef ENGINE_H
#define ENGINE_H
// Forward declaration of class UserInterface
class UserInterface;
class View;
#include <string>
#include <iostream>
#include <irrlicht.h>
#include "EventHandler.h"
#include "UserInterface.h"
#include "View.h"
using std::cout;
using std::endl;
using std::wstring;
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace irr::gui;
enum SceneItemID
{
SIID_LIGHT = 1,
SIID_CAMERA = 2,
SIID_MODEL = 3
};
class Engine
{
friend class UserInterface;
friend class View;
private:
IrrlichtDevice *m_Device;
IVideoDriver *m_Driver;
ISceneManager *m_Scene;
IAnimatedMeshSceneNode *m_LoadedMesh;
IGUIFont *m_AxisFont;
dimension2d<u32> *m_WindowSize;
bool m_RunEngine;
EventHandler *m_EventHandler;
UserInterface *m_UserInterface;
View *m_View;
void setupScene();
void drawAxisLines();
void drawBackground();
void checkResize();
IGUIEnvironment *getGUIEnvironment() const;
void loadMesh( const wstring &fileName );
public:
Engine();
~Engine();
void run();
};
#endif // ENGINE_H

36
EventHandler.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "EventHandler.h"
// Public
EventHandler::EventHandler( IrrlichtDevice *device )
{
m_Device = device;
m_EventReceivers = new map<EventReceiverType, IEventReceiver *>();
}
EventHandler::~EventHandler()
{
delete m_EventReceivers;
}
bool EventHandler::addEventReceiver( EventReceiverType type, IEventReceiver *receiver )
{
m_EventReceivers->insert( make_pair( type, receiver ));
}
// IEventReceiver
bool EventHandler::OnEvent( const SEvent &event )
{
if( event.EventType == EET_GUI_EVENT )
{
// Pass to User Interface Handler
map<EventReceiverType,IEventReceiver *>::iterator iter = m_EventReceivers->find( ERT_USERINTERFACE );
iter->second->OnEvent( event );
}
else if( event.EventType == EET_MOUSE_INPUT_EVENT )
{
map<EventReceiverType,IEventReceiver *>::iterator iter = m_EventReceivers->find( ERT_3DVIEW );
iter->second->OnEvent( event );
}
return false;
}

43
EventHandler.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef EVENTHANDLER_H
#define EVENTHANDLER_H
#include <iostream>
#include <map>
#include <utility>
#include <irrlicht.h>
#include "Debug.h"
using std::cout;
using std::endl;
using std::map;
using std::make_pair;
using namespace irr;
using namespace irr::video;
using namespace irr::gui;
enum EventReceiverType
{
ERT_USERINTERFACE = 1,
ERT_3DVIEW = 2
};
class EventHandler : public IEventReceiver
{
private:
IrrlichtDevice *m_Device;
map<EventReceiverType, IEventReceiver*> *m_EventReceivers;
public:
EventHandler( IrrlichtDevice *device );
~EventHandler();
bool addEventReceiver( EventReceiverType type, IEventReceiver *receiver );
// IEventReceiver
virtual bool OnEvent( const SEvent &event );
};
#endif // EVENTHANDLER_H

125
Makefile Normal file
View File

@ -0,0 +1,125 @@
#############################################################################
# Makefile for building: B3View
# Generated by qmake (2.01a) (Qt 4.6.0) on: Mi 21. Apr 16:30:29 2010
# Project: B3View.pro
# Template: app
# Command: c:\qt\2009.05\qt\bin\qmake.exe -spec c:\Qt\2009.05\qt\mkspecs\win32-g++ -win32 -o Makefile B3View.pro
#############################################################################
first: debug
install: debug-install
uninstall: debug-uninstall
MAKEFILE = Makefile
QMAKE = c:\qt\2009.05\qt\bin\qmake.exe
DEL_FILE = del
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
COPY = copy /y
COPY_FILE = $(COPY)
COPY_DIR = xcopy /s /q /y /i
INSTALL_FILE = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
DEL_FILE = del
SYMLINK =
DEL_DIR = rmdir
MOVE = move
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
SUBTARGETS = \
debug \
release
debug: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug
debug-make_default: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug
debug-make_first: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug first
debug-all: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug all
debug-clean: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug clean
debug-distclean: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug distclean
debug-install: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug install
debug-uninstall: $(MAKEFILE).Debug FORCE
$(MAKE) -f $(MAKEFILE).Debug uninstall
release: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release
release-make_default: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release
release-make_first: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release first
release-all: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release all
release-clean: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release clean
release-distclean: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release distclean
release-install: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release install
release-uninstall: $(MAKEFILE).Release FORCE
$(MAKE) -f $(MAKEFILE).Release uninstall
Makefile: B3View.pro c:/Qt/2009.05/qt/mkspecs/win32-g++/qmake.conf c:/Qt/2009.05/qt/mkspecs/qconfig.pri \
c:/Qt/2009.05/qt/mkspecs/features/qt_functions.prf \
c:/Qt/2009.05/qt/mkspecs/features/qt_config.prf \
c:/Qt/2009.05/qt/mkspecs/features/exclusive_builds.prf \
c:/Qt/2009.05/qt/mkspecs/features/default_pre.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/default_pre.prf \
c:/Qt/2009.05/qt/mkspecs/features/debug.prf \
c:/Qt/2009.05/qt/mkspecs/features/debug_and_release.prf \
c:/Qt/2009.05/qt/mkspecs/features/default_post.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/default_post.prf \
c:/Qt/2009.05/qt/mkspecs/features/warn_off.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/rtti.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/exceptions.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/stl.prf \
c:/Qt/2009.05/qt/mkspecs/features/shared.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/windows.prf \
c:/Qt/2009.05/qt/mkspecs/features/win32/thread_off.prf \
c:/Qt/2009.05/qt/mkspecs/features/resources.prf \
c:/Qt/2009.05/qt/mkspecs/features/uic.prf \
c:/Qt/2009.05/qt/mkspecs/features/yacc.prf \
c:/Qt/2009.05/qt/mkspecs/features/lex.prf \
c:/Qt/2009.05/qt/mkspecs/features/include_source_dir.prf
$(QMAKE) -spec c:\Qt\2009.05\qt\mkspecs\win32-g++ -win32 -o Makefile B3View.pro
c:\Qt\2009.05\qt\mkspecs\qconfig.pri:
c:\Qt\2009.05\qt\mkspecs\features\qt_functions.prf:
c:\Qt\2009.05\qt\mkspecs\features\qt_config.prf:
c:\Qt\2009.05\qt\mkspecs\features\exclusive_builds.prf:
c:\Qt\2009.05\qt\mkspecs\features\default_pre.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\default_pre.prf:
c:\Qt\2009.05\qt\mkspecs\features\debug.prf:
c:\Qt\2009.05\qt\mkspecs\features\debug_and_release.prf:
c:\Qt\2009.05\qt\mkspecs\features\default_post.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\default_post.prf:
c:\Qt\2009.05\qt\mkspecs\features\warn_off.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\rtti.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\exceptions.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\stl.prf:
c:\Qt\2009.05\qt\mkspecs\features\shared.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\windows.prf:
c:\Qt\2009.05\qt\mkspecs\features\win32\thread_off.prf:
c:\Qt\2009.05\qt\mkspecs\features\resources.prf:
c:\Qt\2009.05\qt\mkspecs\features\uic.prf:
c:\Qt\2009.05\qt\mkspecs\features\yacc.prf:
c:\Qt\2009.05\qt\mkspecs\features\lex.prf:
c:\Qt\2009.05\qt\mkspecs\features\include_source_dir.prf:
qmake: qmake_all FORCE
@$(QMAKE) -spec c:\Qt\2009.05\qt\mkspecs\win32-g++ -win32 -o Makefile B3View.pro
qmake_all: FORCE
make_default: debug-make_default release-make_default FORCE
make_first: debug-make_first release-make_first FORCE
all: debug-all release-all FORCE
clean: debug-clean release-clean FORCE
distclean: debug-distclean release-distclean FORCE
-$(DEL_FILE) Makefile
FORCE:
$(MAKEFILE).Debug: Makefile
$(MAKEFILE).Release: Makefile

170
Makefile.Debug Normal file
View File

@ -0,0 +1,170 @@
#############################################################################
# Makefile for building: B3View
# Generated by qmake (2.01a) (Qt 4.6.0) on: Mi 21. Apr 16:30:29 2010
# Project: B3View.pro
# Template: app
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NEEDS_QMAIN
CFLAGS = -g -w $(DEFINES)
CXXFLAGS = -g -w -frtti -fexceptions -mthreads $(DEFINES)
INCPATH = -I"..\..\..\..\libs\irrlicht-1.7.1\include" -I"c:\Qt\2009.05\qt\mkspecs\win32-g++"
LINK = g++
LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows
LIBS = -Ld:/libs/irrlicht-1.7.1/lib/Win32-gcc -lIrrlicht
QMAKE = c:\qt\2009.05\qt\bin\qmake.exe
IDC = c:\Qt\2009.05\qt\bin\idc.exe
IDL = midl
ZIP = zip -r -9
DEF_FILE =
RES_FILE =
COPY = copy /y
COPY_FILE = $(COPY)
COPY_DIR = xcopy /s /q /y /i
DEL_FILE = del
DEL_DIR = rmdir
MOVE = move
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
INSTALL_FILE = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
####### Output directory
OBJECTS_DIR = tmp
####### Files
SOURCES = main.cpp \
Engine.cpp \
EventHandler.cpp \
UserInterface.cpp \
Debug.cpp \
View.cpp \
Utils.cpp
OBJECTS = tmp/main.o \
tmp/Engine.o \
tmp/EventHandler.o \
tmp/UserInterface.o \
tmp/Debug.o \
tmp/View.o \
tmp/Utils.o
DIST =
QMAKE_TARGET = B3View
DESTDIR = build\ #avoid trailing-slash linebreak
TARGET = B3View.exe
DESTDIR_TARGET = build\B3View.exe
####### Implicit rules
.SUFFIXES: .cpp .cc .cxx .c
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
####### Build rules
first: all
all: Makefile.Debug $(DESTDIR_TARGET)
$(DESTDIR_TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS) $(LIBS)
qmake: FORCE
@$(QMAKE) -spec c:\Qt\2009.05\qt\mkspecs\win32-g++ -win32 -o Makefile.Debug B3View.pro
dist:
$(ZIP) B3View.zip $(SOURCES) $(DIST) B3View.pro c:\Qt\2009.05\qt\mkspecs\qconfig.pri c:\Qt\2009.05\qt\mkspecs\features\qt_functions.prf c:\Qt\2009.05\qt\mkspecs\features\qt_config.prf c:\Qt\2009.05\qt\mkspecs\features\exclusive_builds.prf c:\Qt\2009.05\qt\mkspecs\features\default_pre.prf c:\Qt\2009.05\qt\mkspecs\features\win32\default_pre.prf c:\Qt\2009.05\qt\mkspecs\features\debug.prf c:\Qt\2009.05\qt\mkspecs\features\debug_and_release.prf c:\Qt\2009.05\qt\mkspecs\features\default_post.prf c:\Qt\2009.05\qt\mkspecs\features\win32\default_post.prf c:\Qt\2009.05\qt\mkspecs\features\build_pass.prf c:\Qt\2009.05\qt\mkspecs\features\warn_off.prf c:\Qt\2009.05\qt\mkspecs\features\win32\rtti.prf c:\Qt\2009.05\qt\mkspecs\features\win32\exceptions.prf c:\Qt\2009.05\qt\mkspecs\features\win32\stl.prf c:\Qt\2009.05\qt\mkspecs\features\shared.prf c:\Qt\2009.05\qt\mkspecs\features\win32\windows.prf c:\Qt\2009.05\qt\mkspecs\features\win32\thread_off.prf c:\Qt\2009.05\qt\mkspecs\features\resources.prf c:\Qt\2009.05\qt\mkspecs\features\uic.prf c:\Qt\2009.05\qt\mkspecs\features\yacc.prf c:\Qt\2009.05\qt\mkspecs\features\lex.prf c:\Qt\2009.05\qt\mkspecs\features\include_source_dir.prf RESOURCES FORMS IMAGES YACCSOURCES YACCSOURCES LEXSOURCES
clean: compiler_clean
-$(DEL_FILE) tmp\main.o tmp\Engine.o tmp\EventHandler.o tmp\UserInterface.o tmp\Debug.o tmp\View.o tmp\Utils.o
distclean: clean
-$(DEL_FILE) $(DESTDIR_TARGET)
-$(DEL_FILE) Makefile.Debug
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
####### Compile
tmp/main.o: main.cpp Engine.h \
EventHandler.h \
Debug.h \
UserInterface.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\main.o main.cpp
tmp/Engine.o: Engine.cpp Engine.h \
EventHandler.h \
Debug.h \
UserInterface.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Engine.o Engine.cpp
tmp/EventHandler.o: EventHandler.cpp EventHandler.h \
Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\EventHandler.o EventHandler.cpp
tmp/UserInterface.o: UserInterface.cpp UserInterface.h \
Debug.h \
Engine.h \
EventHandler.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\UserInterface.o UserInterface.cpp
tmp/Debug.o: Debug.cpp Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Debug.o Debug.cpp
tmp/View.o: View.cpp View.h \
Debug.h \
Engine.h \
EventHandler.h \
UserInterface.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\View.o View.cpp
tmp/Utils.o: Utils.cpp Utils.h \
Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Utils.o Utils.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:

170
Makefile.Release Normal file
View File

@ -0,0 +1,170 @@
#############################################################################
# Makefile for building: B3View
# Generated by qmake (2.01a) (Qt 4.6.0) on: Mi 21. Apr 16:30:29 2010
# Project: B3View.pro
# Template: app
#############################################################################
####### Compiler, tools and options
CC = gcc
CXX = g++
DEFINES = -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_NEEDS_QMAIN
CFLAGS = -O2 -w $(DEFINES)
CXXFLAGS = -O2 -w -frtti -fexceptions -mthreads $(DEFINES)
INCPATH = -I"..\..\..\..\libs\irrlicht-1.7.1\include" -I"c:\Qt\2009.05\qt\mkspecs\win32-g++"
LINK = g++
LFLAGS = -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows
LIBS = -Ld:/libs/irrlicht-1.7.1/lib/Win32-gcc -lIrrlicht
QMAKE = c:\qt\2009.05\qt\bin\qmake.exe
IDC = c:\Qt\2009.05\qt\bin\idc.exe
IDL = midl
ZIP = zip -r -9
DEF_FILE =
RES_FILE =
COPY = copy /y
COPY_FILE = $(COPY)
COPY_DIR = xcopy /s /q /y /i
DEL_FILE = del
DEL_DIR = rmdir
MOVE = move
CHK_DIR_EXISTS= if not exist
MKDIR = mkdir
INSTALL_FILE = $(COPY_FILE)
INSTALL_PROGRAM = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
####### Output directory
OBJECTS_DIR = tmp
####### Files
SOURCES = main.cpp \
Engine.cpp \
EventHandler.cpp \
UserInterface.cpp \
Debug.cpp \
View.cpp \
Utils.cpp
OBJECTS = tmp/main.o \
tmp/Engine.o \
tmp/EventHandler.o \
tmp/UserInterface.o \
tmp/Debug.o \
tmp/View.o \
tmp/Utils.o
DIST =
QMAKE_TARGET = B3View
DESTDIR = build\ #avoid trailing-slash linebreak
TARGET = B3View.exe
DESTDIR_TARGET = build\B3View.exe
####### Implicit rules
.SUFFIXES: .cpp .cc .cxx .c
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
####### Build rules
first: all
all: Makefile.Release $(DESTDIR_TARGET)
$(DESTDIR_TARGET): $(OBJECTS)
$(LINK) $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS) $(LIBS)
qmake: FORCE
@$(QMAKE) -spec c:\Qt\2009.05\qt\mkspecs\win32-g++ -win32 -o Makefile.Release B3View.pro
dist:
$(ZIP) B3View.zip $(SOURCES) $(DIST) B3View.pro c:\Qt\2009.05\qt\mkspecs\qconfig.pri c:\Qt\2009.05\qt\mkspecs\features\qt_functions.prf c:\Qt\2009.05\qt\mkspecs\features\qt_config.prf c:\Qt\2009.05\qt\mkspecs\features\exclusive_builds.prf c:\Qt\2009.05\qt\mkspecs\features\default_pre.prf c:\Qt\2009.05\qt\mkspecs\features\win32\default_pre.prf c:\Qt\2009.05\qt\mkspecs\features\release.prf c:\Qt\2009.05\qt\mkspecs\features\debug_and_release.prf c:\Qt\2009.05\qt\mkspecs\features\default_post.prf c:\Qt\2009.05\qt\mkspecs\features\win32\default_post.prf c:\Qt\2009.05\qt\mkspecs\features\build_pass.prf c:\Qt\2009.05\qt\mkspecs\features\warn_off.prf c:\Qt\2009.05\qt\mkspecs\features\win32\rtti.prf c:\Qt\2009.05\qt\mkspecs\features\win32\exceptions.prf c:\Qt\2009.05\qt\mkspecs\features\win32\stl.prf c:\Qt\2009.05\qt\mkspecs\features\shared.prf c:\Qt\2009.05\qt\mkspecs\features\win32\windows.prf c:\Qt\2009.05\qt\mkspecs\features\win32\thread_off.prf c:\Qt\2009.05\qt\mkspecs\features\resources.prf c:\Qt\2009.05\qt\mkspecs\features\uic.prf c:\Qt\2009.05\qt\mkspecs\features\yacc.prf c:\Qt\2009.05\qt\mkspecs\features\lex.prf c:\Qt\2009.05\qt\mkspecs\features\include_source_dir.prf RESOURCES FORMS IMAGES YACCSOURCES YACCSOURCES LEXSOURCES
clean: compiler_clean
-$(DEL_FILE) tmp\main.o tmp\Engine.o tmp\EventHandler.o tmp\UserInterface.o tmp\Debug.o tmp\View.o tmp\Utils.o
distclean: clean
-$(DEL_FILE) $(DESTDIR_TARGET)
-$(DEL_FILE) Makefile.Release
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean:
####### Compile
tmp/main.o: main.cpp Engine.h \
EventHandler.h \
Debug.h \
UserInterface.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\main.o main.cpp
tmp/Engine.o: Engine.cpp Engine.h \
EventHandler.h \
Debug.h \
UserInterface.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Engine.o Engine.cpp
tmp/EventHandler.o: EventHandler.cpp EventHandler.h \
Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\EventHandler.o EventHandler.cpp
tmp/UserInterface.o: UserInterface.cpp UserInterface.h \
Debug.h \
Engine.h \
EventHandler.h \
View.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\UserInterface.o UserInterface.cpp
tmp/Debug.o: Debug.cpp Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Debug.o Debug.cpp
tmp/View.o: View.cpp View.h \
Debug.h \
Engine.h \
EventHandler.h \
UserInterface.h \
Utils.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\View.o View.cpp
tmp/Utils.o: Utils.cpp Utils.h \
Debug.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o tmp\Utils.o Utils.cpp
####### Install
install: FORCE
uninstall: FORCE
FORCE:

88
UserInterface.cpp Normal file
View File

@ -0,0 +1,88 @@
#include "UserInterface.h"
// PRIVATE
void UserInterface::setupUserInterface()
{
IGUIContextMenu *menu = m_Gui->addMenu();
menu->addItem( L"File", UIE_FILEMENU, true, true );
IGUIContextMenu *fileMenu = menu->getSubMenu( 0 );
fileMenu->addItem( L"Load", UIC_FILE_LOAD );
fileMenu->addItem( L"Quit", UIC_FILE_QUIT );
// Set Font for UI Elements
m_GuiFont = m_Gui->getFont( "arial.xml" );
m_Gui->getSkin()->setFont( m_GuiFont );
}
void UserInterface::displayLoadFileDialog()
{
m_Gui->addFileOpenDialog( L"Select file to load", true, 0, UIE_LOADFILEDIALOG );
}
// PUBLIC
UserInterface::UserInterface( Engine *engine )
{
m_Engine = engine;
m_Gui = engine->getGUIEnvironment();
setupUserInterface();
}
UserInterface::~UserInterface()
{
delete m_GuiFont;
}
IGUIEnvironment * UserInterface::getGUIEnvironment() const
{
return m_Gui;
}
void UserInterface::handleMenuItemPressed( IGUIContextMenu *menu )
{
s32 id = menu->getItemCommandId( menu->getSelectedItem() );
switch( id )
{
case UIC_FILE_LOAD:
displayLoadFileDialog();
break;
case UIC_FILE_QUIT:
m_Engine->m_RunEngine = false;
break;
}
}
// IEventReceiver
bool UserInterface::OnEvent( const SEvent &event )
{
// Events arriving here should be destined for us
if( ! event.EventType == EET_GUI_EVENT )
return false;
const SEvent::SGUIEvent *ge = &( event.GUIEvent );
switch( ge->Caller->getID() )
{
case UIE_FILEMENU:
// call handler for all menu related actions
handleMenuItemPressed( static_cast<IGUIContextMenu *>( ge->Caller ));
break;
case UIE_LOADFILEDIALOG:
if( ge->EventType == EGET_FILE_SELECTED )
{
IGUIFileOpenDialog *fileOpenDialog = static_cast<IGUIFileOpenDialog *>( ge->Caller );
m_Engine->loadMesh( fileOpenDialog->getFileName() );
}
break;
default:
break;
}
return true;
}

54
UserInterface.h Normal file
View File

@ -0,0 +1,54 @@
#ifndef USERINTERFACE_H
#define USERINTERFACE_H
// Forward declaration of class Engine
class Engine;
#include <string>
#include <irrlicht.h>
#include "Debug.h"
#include "Engine.h"
using namespace irr;
using namespace irr::core;
using namespace irr::gui;
using std::string;
using std::wstring;
enum UserInterfaceElements
{
UIE_MAINWINDOW = 1000,
UIE_LOADBUTTON = 1001,
UIE_LOADFILEDIALOG = 1002,
UIE_FILEMENU = 1003
};
enum UserInterfaceCommands
{
UIC_FILE_LOAD = 1000,
UIC_FILE_QUIT = 1001
};
class UserInterface : public IEventReceiver
{
private:
Engine *m_Engine;
IGUIEnvironment *m_Gui;
IGUIFont *m_GuiFont;
void setupUserInterface();
void displayLoadFileDialog();
void handleMenuItemPressed( IGUIContextMenu *menu );
public:
UserInterface( Engine *device );
~UserInterface();
IGUIEnvironment * getGUIEnvironment() const;
// IEventReceiver
virtual bool OnEvent( const SEvent &event );
};
#endif // USERINTERFACE_H

6
Utils.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "Utils.h"
void dumpVectorToConsole( const vector3df &vector )
{
debug() << "X: " << vector.X << " Y: " << vector.Y << " Z: " << vector.Z << endl;
}

13
Utils.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef UTILS_H
#define UTILS_H
#include <cmath>
#include <irrlicht.h>
#include "Debug.h"
using irr::core::vector3df;
using namespace std;
void dumpVectorToConsole( const vector3df &vector );
#endif // UTILS_H

97
View.cpp Normal file
View File

@ -0,0 +1,97 @@
#include "View.h"
void View::setNewCameraPosition()
{
vector3d<f32> newCameraPosition;
ICameraSceneNode *camera = m_Engine->m_Scene->getActiveCamera();
newCameraPosition.X = 0;
newCameraPosition.Y = m_CameraDistance * sin( m_Pitch );
newCameraPosition.Z = m_CameraDistance * cos( m_Pitch );
matrix4 yawMatrix;
yawMatrix.setRotationRadians( vector3df( 0, m_Yaw, 0 ));
yawMatrix.transformVect( newCameraPosition );
camera->setPosition( newCameraPosition );
// Set Light direction
setNewLightDirection( newCameraPosition );
}
void View::setNewLightDirection( const vector3df &cameraPosition )
{
ILightSceneNode *light = static_cast<ILightSceneNode *>( m_Engine->m_Scene->getSceneNodeFromId( SIID_LIGHT ));
matrix4 m;
m.buildRotateFromTo( vector3df( 0, 0, 1 ), vector3df( cameraPosition ).invert().normalize() );
light->setRotation( m.getRotationDegrees() );
}
View::View( Engine *engine )
{
m_Engine = engine;
m_LastMousePosition = new vector2d<int>();
m_RotMouse = false;
m_Pitch = PI;
// Set Camera Distance
m_CameraDistance = 10;
debug() << "Yaw: " << m_Yaw << endl;
debug() << "Pitch: " << m_Pitch << endl;
}
View::~View()
{
delete m_LastMousePosition;
}
// IEventReceiver
bool View::OnEvent( const SEvent &event )
{
if( event.EventType != EET_MOUSE_INPUT_EVENT )
return false;
const SEvent::SMouseInput *mouseEvent = &( event.MouseInput );
if( mouseEvent->Event == EMIE_MMOUSE_PRESSED_DOWN )
{
m_RotMouse = true;
m_LastMousePosition->X = mouseEvent->X;
m_LastMousePosition->Y = mouseEvent->Y;
}
else if( mouseEvent->Event == EMIE_MMOUSE_LEFT_UP )
{
m_RotMouse = false;
}
else if( mouseEvent->Event == EMIE_MOUSE_WHEEL )
{
f32 distanceDelta = mouseEvent->Wheel / 2.5f;
if( m_CameraDistance - distanceDelta > 0.1f )
m_CameraDistance -= distanceDelta;
setNewCameraPosition();
}
else if( m_RotMouse )
{
int dx = mouseEvent->X - m_LastMousePosition->X;
int dy = mouseEvent->Y - m_LastMousePosition->Y;
m_LastMousePosition->X = mouseEvent->X;
m_LastMousePosition->Y = mouseEvent->Y;
f32 pitchDelta = dy / 120.0f;
if(( m_Pitch - pitchDelta > ( PI - ( PI / 2 ))) && ( m_Pitch - pitchDelta < PI + ( PI/2 )))
m_Pitch -= dy / 120.0f;
m_Yaw += dx / 120.0f;
// Set Camera to new rotation
setNewCameraPosition();
}
return true;
}

34
View.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef VIEW_H
#define VIEW_H
#include <irrlicht.h>
#include "Debug.h"
#include "Engine.h"
#include "Utils.h"
using namespace irr;
using namespace irr::scene;
using namespace irr::core;
using namespace irr::video;
class View : public IEventReceiver
{
private:
Engine *m_Engine;
f32 m_Yaw, m_Pitch, m_CameraDistance;
vector2d<int> *m_LastMousePosition;
bool m_RotMouse;
void setNewCameraPosition();
void setNewLightDirection( const vector3df &cameraPosition );
public:
View( Engine *engine );
~View();
// IEventReceiver
virtual bool OnEvent( const SEvent &event );
};
#endif // VIEW_H

BIN
build/arial.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 768 KiB

BIN
build/arial.xml Normal file

Binary file not shown.

BIN
build/ninja.b3d Normal file

Binary file not shown.

BIN
build/test.b3d Normal file

Binary file not shown.

9
main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "Engine.h"
int main( int argc, char **argv )
{
Engine *engine = new Engine();
engine->run();
delete engine;
}