Browse Source

Import files

master
squeaky otter 11 years ago
parent
commit
c40fe16457
  1. 1
      .gitignore
  2. 287
      CMakeLists.txt
  3. 16
      README
  4. 0
      README.linux
  5. 9
      README.osx
  6. 3
      README.win32
  7. 421
      src/BaseApplication.cpp
  8. 95
      src/BaseApplication.h
  9. 719
      src/TutorialApplication.cpp
  10. 117
      src/TutorialApplication.h
  11. 27
      src/erosion.h
  12. 504
      src/noiseutils/COPYING.txt
  13. 1299
      src/noiseutils/noiseutils.cpp
  14. 2542
      src/noiseutils/noiseutils.h
  15. 4
      src/noiseutils/readme.txt

1
.gitignore

@ -0,0 +1 @@
build

287
CMakeLists.txt

@ -0,0 +1,287 @@
#/*
#-----------------------------------------------------------------------------
#Filename: CMakeLists.txt
#-----------------------------------------------------------------------------
# Based on the Ogre 3D CMakeLists.txt tutorial framework
cmake_minimum_required(VERSION 2.6)
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
cmake_policy(SET CMP0003 NEW)
# Use relative paths
# This is mostly to reduce path size for command-line limits on windows
if(WIN32)
# This seems to break Xcode projects so definitely don't enable on Apple builds
set(CMAKE_USE_RELATIVE_PATHS true)
set(CMAKE_SUPPRESS_REGENERATION true)
set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
set(OGRE_SAMPLES_INCLUDEPATH
$ENV{OGRE_HOME}/Samples/include)
endif()
# Assign compiler for Mac OS X-based systems
# NOTE: This logic is order-dependent and must occur here because the
# configuration phase of CMake projects will fall into an infinite loop
# if compiler assignments are modified after issuing a project(...) command.
#
if (OGRE_BUILD_PLATFORM_IPHONE)
# Force gcc <= 4.2 on iPhone
include(CMakeForceCompiler)
CMAKE_FORCE_C_COMPILER(gcc-4.2 GNU)
CMAKE_FORCE_CXX_COMPILER(gcc-4.2 GNU)
elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_IPHONE)
# Force gcc <= 4.0 on Mac OS X because 4.2 is not supported prior to Mac OS X 10.5
#include(CMakeForceCompiler)
#CMAKE_FORCE_C_COMPILER(gcc-4.0 GNU)
#CMAKE_FORCE_CXX_COMPILER(gcc-4.0 GNU)
endif ()
set(OGRE_PROJECT_NAME
"OGRETutorialFramework"
)
set(CMAKE_INSTALL_PREFIX "/Users/rhaamo/cubeworld/build/bin")
project(${OGRE_PROJECT_NAME})
# Include necessary submodules
set(OGRE_SOURCE_DIR "/Users/rhaamo/src/OgreSDK")
set(CMAKE_MODULE_PATH
"${OGRE_SOURCE_DIR}/CMake"
"${OGRE_SOURCE_DIR}/CMake/Utils"
"${OGRE_SOURCE_DIR}/CMake/Packages"
)
set(OGRE_SAMPLES_INCLUDEPATH
"${OGRE_SOURCE_DIR}/Samples/Common/include"
)
include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
include(MacroLogFeature)
include(OgreConfigTargets)
include(PreprocessorUtils)
set(OGRE_TEMPLATES_DIR "${OGRE_SOURCE_DIR}/CMake/Templates")
#####################################################################
# Set up the basic build environment
#####################################################################
if (CMAKE_BUILD_TYPE STREQUAL "")
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
# differentiation between debug and release builds.
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()
if (NOT APPLE)
# Create debug libraries with _d postfix
set(CMAKE_DEBUG_POSTFIX "_d")
endif ()
# Set compiler specific build flags
if (CMAKE_COMPILER_IS_GNUCXX)
check_cxx_compiler_flag(-msse OGRE_GCC_HAS_SSE)
if (OGRE_GCC_HAS_SSE)
add_definitions(-msse)
endif ()
endif ()
if (MSVC)
if (CMAKE_BUILD_TOOL STREQUAL "nmake")
# set variable to state that we are using nmake makefiles
set(NMAKE TRUE)
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
# Enable intrinsics on MSVC in debug mode
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Oi")
if (CMAKE_CL_64)
# Visual Studio bails out on debug builds in 64bit mode unless
# this flag is set...
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj")
endif ()
endif ()
if (MINGW)
add_definitions(-D_WIN32_WINNT=0x0500)
endif ()
if (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# Test for GCC visibility
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-fvisibility=hidden OGRE_GCC_VISIBILITY)
if (OGRE_GCC_VISIBILITY)
# determine gcc version
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
OUTPUT_VARIABLE OGRE_GCC_VERSION)
message(STATUS "Detected g++ ${OGRE_GCC_VERSION}")
message(STATUS "Enabling GCC visibility flags")
set(OGRE_GCC_VISIBILITY_FLAGS "-DOGRE_GCC_VISIBILITY -fvisibility=hidden")
# check if we can safely add -fvisibility-inlines-hidden
string(TOLOWER "${CMAKE_BUILD_TYPE}" OGRE_BUILD_TYPE)
if (OGRE_BUILD_TYPE STREQUAL "debug" AND OGRE_GCC_VERSION VERSION_LESS "4.2")
message(STATUS "Skipping -fvisibility-inlines-hidden due to possible bug in g++ < 4.2")
else ()
set(OGRE_GCC_VISIBILITY_FLAGS "${OGRE_GCC_VISIBILITY_FLAGS} -fvisibility-inlines-hidden")
endif ()
endif (OGRE_GCC_VISIBILITY)
# Fix x64 issues on Linux
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
add_definitions(-fPIC)
endif()
endif (CMAKE_COMPILER_IS_GNUCXX AND NOT MINGW)
# determine system endianess
#include(TestBigEndian)
#test_big_endian(OGRE_TEST_BIG_ENDIAN)
set(OGRE_TEST_BIG_ENDIAN FALSE)
# Add OgreMain include path
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include")
include_directories("${OGRE_BINARY_DIR}/include")
if (APPLE)
if (OGRE_BUILD_PLATFORM_IPHONE)
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/iPhone")
# Set static early for proper dependency detection
set(OGRE_STATIC TRUE)
else ()
include_directories("${OGRE_SOURCE_DIR}/OgreMain/include/OSX")
endif ()
endif (APPLE)
find_package(OGRE REQUIRED)
if(NOT "${OGRE_VERSION_NAME}" STREQUAL "Cthugha")
message(SEND_ERROR "You need Ogre 1.7 Cthugha to build this.")
endif()
find_package(OIS REQUIRED)
if(NOT OIS_FOUND)
message(SEND_ERROR "Failed to find OIS.")
endif()
# Find Boost
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
if (WIN32 OR APPLE)
set(Boost_USE_STATIC_LIBS TRUE)
else ()
# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
endif ()
if (MINGW)
# this is probably a bug in CMake: the boost find module tries to look for
# boost libraries with name libboost_*, but CMake already prefixes library
# search names with "lib". This is the workaround.
set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
endif ()
set(Boost_ADDITIONAL_VERSIONS "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
# Components that need linking (NB does not include header-only components like bind)
set(OGRE_BOOST_COMPONENTS thread date_time)
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
if (NOT Boost_FOUND)
# Try again with the other type of libs
set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET)
endif()
find_package(Boost QUIET)
# Set up referencing of Boost
include_directories(${Boost_INCLUDE_DIR})
add_definitions(-DBOOST_ALL_NO_LIB)
set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${Boost_LIBRARIES})
endif()
IF (APPLE)
FIND_LIBRARY(IOKIT_LIBRARY IOKit)
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation )
FIND_LIBRARY(OGRE_LIBRARY OGRE)
LINK_DIRECTORIES(${LINK_DIRECTORIES} /opt/local/lib)
# Ogre 3D is a 32bit only SDK build ATM :(
set(CMAKE_C_FLAGS "-m32")
set(CMAKE_CXX_FLAGS "-m32")
ENDIF (APPLE)
set(LIBNOISE_LIBRARIES noise)
set(HDRS
./src/BaseApplication.h
./src/TutorialApplication.h
./src/erosion.h
./src/noiseutils/noiseutils.h
)
set(SRCS
./src/BaseApplication.cpp
./src/TutorialApplication.cpp
./src/noiseutils/noiseutils.cpp
)
include_directories( ${OIS_INCLUDE_DIRS}
${OGRE_INCLUDE_DIRS}
${OGRE_SAMPLES_INCLUDEPATH}
)
add_executable(${OGRE_PROJECT_NAME} WIN32 ${HDRS} ${SRCS})
set_target_properties(${OGRE_PROJECT_NAME} PROPERTIES DEBUG_POSTFIX _d)
target_link_libraries(${OGRE_PROJECT_NAME} ${OGRE_LIBRARIES} ${OIS_LIBRARIES} ${LIBNOISE_LIBRARIES})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/bin)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist/media)
# post-build copy for win32
if(WIN32 AND NOT MINGW)
add_custom_command( TARGET ${OGRE_PROJECT_NAME} PRE_BUILD
COMMAND if not exist .\\dist\\bin mkdir .\\dist\\bin )
add_custom_command( TARGET ${OGRE_PROJECT_NAME} POST_BUILD
COMMAND copy \"$(TargetPath)\" .\\dist\\bin )
endif(WIN32 AND NOT MINGW)
if(MINGW)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/dist/bin)
endif(MINGW)
if(WIN32)
install(TARGETS ${OGRE_PROJECT_NAME}
RUNTIME DESTINATION bin
CONFIGURATIONS All)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/dist/Media
DESTINATION ./
CONFIGURATIONS Release RelWithDebInfo Debug
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources.cfg
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${CMAKE_SOURCE_DIR}/dist/bin/plugins_d.cfg
${CMAKE_SOURCE_DIR}/dist/bin/resources_d.cfg
DESTINATION bin
CONFIGURATIONS Debug
)
install(FILES ${OGRE_PLUGIN_DIR_REL}/OgreMain.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_Direct3D9.dll
${OGRE_PLUGIN_DIR_REL}/RenderSystem_GL.dll
${OGRE_PLUGIN_DIR_REL}/OIS.dll
DESTINATION bin
CONFIGURATIONS Release RelWithDebInfo
)
install(FILES ${OGRE_PLUGIN_DIR_DBG}/OgreMain_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_Direct3D9_d.dll
${OGRE_PLUGIN_DIR_DBG}/RenderSystem_GL_d.dll
${OGRE_PLUGIN_DIR_DBG}/OIS_d.dll
DESTINATION bin
CONFIGURATIONS Debug
)
endif(WIN32)
set_property(TARGET ${OGRE_PROJECT_NAME} PROPERTY MACOSX_BUNDLE TRUE)

16
README

@ -0,0 +1,16 @@
CubeWorld is an attempt to make a MineCraft-like world using Ogre 3D
Requirements:
- Ogre3D
- OIS
- libnoise
Global instructions:
Edit the CMakeLists.txt and adapt:
- CMAKE_INSTALL_PREFIX line 43
- OGRE_SOURCE_DIR line 48 (path to the SDK)
At this moment please see the README.<your OS>

0
README.linux

9
README.osx

@ -0,0 +1,9 @@
You need the OgreSDK and OIS framework, also install libnoise with the CVS version !
Pkg-config stuff are required for libnoise !
After build you need to run "../do_ugly_osx_bundle.sh" FROM THE 'build' directory !
This will copy resources.cfg and plugins.cfg and also copy stuff to the bundle to ... hum ... works
This is very ugly but i'm very lazy to fix it for the moment ... eh, that's not a pre-alpha! ;)

3
README.win32

@ -0,0 +1,3 @@
Should not work ...
I don't have a window machine to test ...

421
src/BaseApplication.cpp

@ -0,0 +1,421 @@
/*
-----------------------------------------------------------------------------
Filename: BaseApplication.cpp
-----------------------------------------------------------------------------
This source file is part of the
___ __ __ _ _ _
/___\__ _ _ __ ___ / / /\ \ (_) | _(_)
// // _` | '__/ _ \ \ \/ \/ / | |/ / |
/ \_// (_| | | | __/ \ /\ /| | <| |
\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
|___/
Tutorial Framework
http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#include "BaseApplication.h"
//-------------------------------------------------------------------------------------
BaseApplication::BaseApplication(void)
: mRoot(0),
mCamera(0),
mSceneMgr(0),
mWindow(0),
mResourcesCfg(Ogre::StringUtil::BLANK),
mPluginsCfg(Ogre::StringUtil::BLANK),
mTrayMgr(0),
mCameraMan(0),
mDetailsPanel(0),
mCursorWasVisible(false),
mShutDown(false),
mInputManager(0),
mMouse(0),
mKeyboard(0)
{
}
//-------------------------------------------------------------------------------------
BaseApplication::~BaseApplication(void)
{
if (mTrayMgr) delete mTrayMgr;
if (mCameraMan) delete mCameraMan;
//Remove ourself as a Window listener
Ogre::WindowEventUtilities::removeWindowEventListener(mWindow, this);
windowClosed(mWindow);
delete mRoot;
}
//-------------------------------------------------------------------------------------
bool BaseApplication::configure(void)
{
// Show the configuration dialog and initialise the system
// You can skip this and use root.restoreConfig() to load configuration
// settings if you were sure there are valid ones saved in ogre.cfg
if(mRoot->showConfigDialog())
{
// If returned true, user clicked OK so initialise
// Here we choose to let the system create a default rendering window by passing 'true'
mWindow = mRoot->initialise(true, "TutorialApplication Render Window");
return true;
}
else
{
return false;
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::chooseSceneManager(void)
{
// Get the SceneManager, in this case a generic one
mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC);
}
//-------------------------------------------------------------------------------------
void BaseApplication::createCamera(void)
{
// Create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// Position it at 500 in Z direction
mCamera->setPosition(Ogre::Vector3(-31,140,202));
// Look back along -Z
mCamera->lookAt(Ogre::Vector3(0.084, -0.6, 0.05));
mCamera->setNearClipDistance(5);
mCameraMan = new OgreBites::SdkCameraMan(mCamera); // create a default camera controller
}
//-------------------------------------------------------------------------------------
void BaseApplication::createFrameListener(void)
{
Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
OIS::ParamList pl;
size_t windowHnd = 0;
std::ostringstream windowHndStr;
mWindow->getCustomAttribute("WINDOW", &windowHnd);
windowHndStr << windowHnd;
pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
mInputManager = OIS::InputManager::createInputSystem( pl );
mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true ));
mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true ));
mMouse->setEventCallback(this);
mKeyboard->setEventCallback(this);
//Set initial mouse clipping size
windowResized(mWindow);
//Register as a Window listener
Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this);
mTrayMgr = new OgreBites::SdkTrayManager("InterfaceName", mWindow, mMouse, this);
mTrayMgr->showFrameStats(OgreBites::TL_BOTTOMLEFT);
mTrayMgr->showLogo(OgreBites::TL_BOTTOMRIGHT);
mTrayMgr->hideCursor();
// create a params panel for displaying sample details
Ogre::StringVector items;
items.push_back("cam.pX");
items.push_back("cam.pY");
items.push_back("cam.pZ");
items.push_back("");
items.push_back("cam.oW");
items.push_back("cam.oX");
items.push_back("cam.oY");
items.push_back("cam.oZ");
items.push_back("");
items.push_back("Filtering");
items.push_back("Poly Mode");
mDetailsPanel = mTrayMgr->createParamsPanel(OgreBites::TL_NONE, "DetailsPanel", 200, items);
mDetailsPanel->setParamValue(9, "Bilinear");
mDetailsPanel->setParamValue(10, "Solid");
mDetailsPanel->hide();
mRoot->addFrameListener(this);
}
//-------------------------------------------------------------------------------------
void BaseApplication::destroyScene(void)
{
}
//-------------------------------------------------------------------------------------
void BaseApplication::createViewports(void)
{
// Create one viewport, entire window
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(
Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight()));
}
//-------------------------------------------------------------------------------------
void BaseApplication::setupResources(void)
{
// Load resource paths from config file
Ogre::ConfigFile cf;
cf.load(mResourcesCfg);
// Go through all sections & settings in the file
Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator();
Ogre::String secName, typeName, archName;
while (seci.hasMoreElements())
{
secName = seci.peekNextKey();
Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext();
Ogre::ConfigFile::SettingsMultiMap::iterator i;
for (i = settings->begin(); i != settings->end(); ++i)
{
typeName = i->first;
archName = i->second;
Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
archName, typeName, secName);
}
}
}
//-------------------------------------------------------------------------------------
void BaseApplication::createResourceListener(void)
{
}
//-------------------------------------------------------------------------------------
void BaseApplication::loadResources(void)
{
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
}
//-------------------------------------------------------------------------------------
void BaseApplication::go(void)
{
#ifdef _DEBUG
mResourcesCfg = "resources_d.cfg";
mPluginsCfg = "plugins_d.cfg";
#else
mResourcesCfg = "resources.cfg";
mPluginsCfg = "plugins.cfg";
#endif
if (!setup())
return;
mRoot->startRendering();
// clean up
destroyScene();
}
//-------------------------------------------------------------------------------------
bool BaseApplication::setup(void)
{
mRoot = new Ogre::Root(mPluginsCfg);
setupResources();
bool carryOn = configure();
if (!carryOn) return false;
chooseSceneManager();
createCamera();
createViewports();
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
// Create any resource listeners (for loading screens)
createResourceListener();
// Load resources
loadResources();
// Create the scene
createScene();
createFrameListener();
return true;
};
//-------------------------------------------------------------------------------------
bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
if(mWindow->isClosed())
return false;
if(mShutDown)
return false;
//Need to capture/update each device
mKeyboard->capture();
mMouse->capture();
mTrayMgr->frameRenderingQueued(evt);
if (!mTrayMgr->isDialogVisible())
{
mCameraMan->frameRenderingQueued(evt); // if dialog isn't up, then update the camera
if (mDetailsPanel->isVisible()) // if details panel is visible, then update its contents
{
mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));
mDetailsPanel->setParamValue(1, Ogre::StringConverter::toString(mCamera->getDerivedPosition().y));
mDetailsPanel->setParamValue(2, Ogre::StringConverter::toString(mCamera->getDerivedPosition().z));
mDetailsPanel->setParamValue(4, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().w));
mDetailsPanel->setParamValue(5, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().x));
mDetailsPanel->setParamValue(6, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().y));
mDetailsPanel->setParamValue(7, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().z));
}
}
return true;
}
//-------------------------------------------------------------------------------------
bool BaseApplication::keyPressed( const OIS::KeyEvent &arg )
{
if (mTrayMgr->isDialogVisible()) return true; // don't process any more keys if dialog is up
if (arg.key == OIS::KC_F) // toggle visibility of advanced frame stats
{
mTrayMgr->toggleAdvancedFrameStats();
}
else if (arg.key == OIS::KC_G) // toggle visibility of even rarer debugging details
{
if (mDetailsPanel->getTrayLocation() == OgreBites::TL_NONE)
{
mTrayMgr->moveWidgetToTray(mDetailsPanel, OgreBites::TL_TOPRIGHT, 0);
mDetailsPanel->show();
}
else
{
mTrayMgr->removeWidgetFromTray(mDetailsPanel);
mDetailsPanel->hide();
}
}
else if (arg.key == OIS::KC_T) // cycle polygon rendering mode
{
Ogre::String newVal;
Ogre::TextureFilterOptions tfo;
unsigned int aniso;
switch (mDetailsPanel->getParamValue(9).asUTF8()[0])
{
case 'B':
newVal = "Trilinear";
tfo = Ogre::TFO_TRILINEAR;
aniso = 1;
break;
case 'T':
newVal = "Anisotropic";
tfo = Ogre::TFO_ANISOTROPIC;
aniso = 8;
break;
case 'A':
newVal = "None";
tfo = Ogre::TFO_NONE;
aniso = 1;
break;
default:
newVal = "Bilinear";
tfo = Ogre::TFO_BILINEAR;
aniso = 1;
}
Ogre::MaterialManager::getSingleton().setDefaultTextureFiltering(tfo);
Ogre::MaterialManager::getSingleton().setDefaultAnisotropy(aniso);
mDetailsPanel->setParamValue(9, newVal);
}
else if (arg.key == OIS::KC_R) // cycle polygon rendering mode
{
Ogre::String newVal;
Ogre::PolygonMode pm;
switch (mCamera->getPolygonMode())
{
case Ogre::PM_SOLID:
newVal = "Wireframe";
pm = Ogre::PM_WIREFRAME;
break;
case Ogre::PM_WIREFRAME:
newVal = "Points";
pm = Ogre::PM_POINTS;
break;
default:
newVal = "Solid";
pm = Ogre::PM_SOLID;
}
mCamera->setPolygonMode(pm);
mDetailsPanel->setParamValue(10, newVal);
}
else if(arg.key == OIS::KC_F5) // refresh all textures
{
Ogre::TextureManager::getSingleton().reloadAll();
}
else if (arg.key == OIS::KC_N) // take a screenshot
{
mWindow->writeContentsToTimestampedFile("screenshot", ".jpg");
mWindow->writeContentsToTimestampedFile("screenshot", ".png");
}
else if (arg.key == OIS::KC_ESCAPE)
{
mShutDown = true;
}
mCameraMan->injectKeyDown(arg);
return true;
}
bool BaseApplication::keyReleased( const OIS::KeyEvent &arg )
{
mCameraMan->injectKeyUp(arg);
return true;
}
bool BaseApplication::mouseMoved( const OIS::MouseEvent &arg )
{
if (mTrayMgr->injectMouseMove(arg)) return true;
mCameraMan->injectMouseMove(arg);
return true;
}
bool BaseApplication::mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
if (mTrayMgr->injectMouseDown(arg, id)) return true;
mCameraMan->injectMouseDown(arg, id);
return true;
}
bool BaseApplication::mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id )
{
if (mTrayMgr->injectMouseUp(arg, id)) return true;
mCameraMan->injectMouseUp(arg, id);
return true;
}
//Adjust mouse clipping area
void BaseApplication::windowResized(Ogre::RenderWindow* rw)
{
unsigned int width, height, depth;
int left, top;
rw->getMetrics(width, height, depth, left, top);
const OIS::MouseState &ms = mMouse->getMouseState();
ms.width = width;
ms.height = height;
}
//Unattach OIS before window shutdown (very important under Linux)
void BaseApplication::windowClosed(Ogre::RenderWindow* rw)
{
//Only close for window that created OIS (the main window in these demos)
if( rw == mWindow )
{
if( mInputManager )
{
mInputManager->destroyInputObject( mMouse );
mInputManager->destroyInputObject( mKeyboard );
OIS::InputManager::destroyInputSystem(mInputManager);
mInputManager = 0;
}
}
}

95
src/BaseApplication.h

@ -0,0 +1,95 @@
/*
-----------------------------------------------------------------------------
Filename: BaseApplication.h
-----------------------------------------------------------------------------
This source file is part of the
___ __ __ _ _ _
/___\__ _ _ __ ___ / / /\ \ (_) | _(_)
// // _` | '__/ _ \ \ \/ \/ / | |/ / |
/ \_// (_| | | | __/ \ /\ /| | <| |
\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
|___/
Tutorial Framework
http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#ifndef __BaseApplication_h_
#define __BaseApplication_h_
#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>
#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>
#include <SdkTrays.h>
#include <SdkCameraMan.h>
class BaseApplication : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener, OgreBites::SdkTrayListener
{
public:
BaseApplication(void);
virtual ~BaseApplication(void);
virtual void go(void);
protected:
virtual bool setup();
virtual bool configure(void);
virtual void chooseSceneManager(void);
virtual void createCamera(void);
virtual void createFrameListener(void);
virtual void createScene(void) = 0; // Override me!
virtual void destroyScene(void);
virtual void createViewports(void);
virtual void setupResources(void);
virtual void createResourceListener(void);
virtual void loadResources(void);
// Ogre::FrameListener
virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
// OIS::KeyListener
virtual bool keyPressed( const OIS::KeyEvent &arg );
virtual bool keyReleased( const OIS::KeyEvent &arg );
// OIS::MouseListener
virtual bool mouseMoved( const OIS::MouseEvent &arg );
virtual bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
virtual bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
// Ogre::WindowEventListener
//Adjust mouse clipping area
virtual void windowResized(Ogre::RenderWindow* rw);
//Unattach OIS before window shutdown (very important under Linux)
virtual void windowClosed(Ogre::RenderWindow* rw);
Ogre::Root *mRoot;
Ogre::Camera* mCamera;
Ogre::SceneManager* mSceneMgr;
Ogre::RenderWindow* mWindow;
Ogre::String mResourcesCfg;
Ogre::String mPluginsCfg;
// OgreBites
OgreBites::SdkTrayManager* mTrayMgr;
OgreBites::SdkCameraMan* mCameraMan; // basic camera controller
OgreBites::ParamsPanel* mDetailsPanel; // sample details panel
bool mCursorWasVisible; // was cursor visible before dialog appeared
bool mShutDown;
//OIS Input devices
OIS::InputManager* mInputManager;
OIS::Mouse* mMouse;
OIS::Keyboard* mKeyboard;
};
#endif // #ifndef __BaseApplication_h_

719
src/TutorialApplication.cpp

@ -0,0 +1,719 @@
/*
-----------------------------------------------------------------------------
Filename: TutorialApplication.cpp
-----------------------------------------------------------------------------
This source file is part of the
___ __ __ _ _ _
/___\__ _ _ __ ___ / / /\ \ (_) | _(_)
// // _` | '__/ _ \ \ \/ \/ / | |/ / |
/ \_// (_| | | | __/ \ /\ /| | <| |
\___/ \__, |_| \___| \/ \/ |_|_|\_\_|
|___/
Tutorial Framework
http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
// Linux Compat for wind0ws
typedef char TCHAR;
#include "erosion.h"
#include "TutorialApplication.h"
//-------------------------------------------------------------------------------------
TutorialApplication::TutorialApplication(void)
{
m_Blocks = new block_t[WORLD_SIZE * WORLD_SIZE * WORLD_SIZE * 16000];
memset(m_Blocks, 0, sizeof(block_t) * WORLD_SIZE * WORLD_SIZE * WORLD_SIZE);
//initWorldBlocksSphere();
initWorldBlocksLand();
m_ChunkID = 1;
m_BlockLight = new blocklight_t[WORLD_SIZE3 + 16000];
memset(m_BlockLight, 255, sizeof(blocklight_t) * WORLD_SIZE3);
initWorldBlocksLight();
}
//-------------------------------------------------------------------------------------
TutorialApplication::~TutorialApplication(void)
{
delete [] m_Blocks;
delete [] m_BlockLight;
}
void TutorialApplication::initWorldBlocksLight()
{
int x, y, z;
blocklight_t Light;
blocklight_t DeltaLight = 16;
for (z = 0; z < WORLD_SIZE; ++z)
{
for (x = 0; x < WORLD_SIZE; ++x)
{
Light = 255;
for (y = WORLD_SIZE - 1; y >= 0; --y)
{
GetBlockLight(x, y, z) = Light;
if (GetBlock(x, y, z) != 0)
{
if (Light >= DeltaLight)
Light -= DeltaLight;
else
Light = 0;
}
}
}
}
}
void TutorialApplication::initWorldBlocksSphere(void)
{
for (int z = 0; z < WORLD_SIZE; ++z)
{
for (int y = 0; y < WORLD_SIZE; ++y)
{
for (int x = 0; x < WORLD_SIZE; ++x)
{
if (sqrt((float) (x-WORLD_SIZE/2)*(x-WORLD_SIZE/2) + (y-WORLD_SIZE/2)*(y-WORLD_SIZE/2) + (z-WORLD_SIZE/2)*(z-WORLD_SIZE/2)) < WORLD_SIZE/2) GetBlock(x,y,z) = 1;
}
}
}
}
void TutorialApplication::initWorldBlocksRandom(const int Divisor)
{
srand(12345); // To keep it consistent between runs
for (int z = 0; z < WORLD_SIZE; ++z)
{
for (int y = 0; y < WORLD_SIZE; ++y)
{
for (int x = 0; x < WORLD_SIZE; ++x)
{
GetBlock(x,y,z) = rand() % Divisor;
}
}
}
}
Ogre::ManualObject* TutorialApplication::createCubeMesh (Ogre::String name, Ogre::String matName)
{
Ogre::ManualObject* cube = new Ogre::ManualObject(name);
cube->begin(matName);
cube->position(0.5f,-0.5f,1.0f);cube->normal(0.408248f,-0.816497f,0.408248f);cube->textureCoord(1,0);
cube->position(-0.5f,-0.5f,0.0f);cube->normal(-0.408248f,-0.816497f,-0.408248f);cube->textureCoord(0,1);
cube->position(0.5f,-0.5f,0.0f);cube->normal(0.666667f,-0.333333f,-0.666667f);cube->textureCoord(1,1);
cube->position(-0.5f,-0.5f,1.0f);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,0);
cube->position(0.5f,0.5f,1.0f);cube->normal(0.666667f,0.333333f,0.666667f);cube->textureCoord(1,0);
cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667f,-0.333333f,0.666667f);cube->textureCoord(0,1);
cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248f);cube->textureCoord(1,1);
cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(0,0);
cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(0,1);
cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(1,1);
cube->position(-0.5,-0.5,1.0);cube->normal(-0.666667,-0.333333,0.666667);cube->textureCoord(1,0);
cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(0,1);
cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(1,1);
cube->position(0.5,-0.5,1.0);cube->normal(0.408248,-0.816497,0.408248);cube->textureCoord(0,0);
cube->position(0.5,-0.5,0.0);cube->normal(0.666667,-0.333333,-0.666667);cube->textureCoord(1,0);
cube->position(-0.5,-0.5,0.0);cube->normal(-0.408248,-0.816497,-0.408248);cube->textureCoord(0,0);
cube->position(-0.5,0.5,1.0);cube->normal(-0.408248,0.816497,0.408248);cube->textureCoord(1,0);
cube->position(0.5,0.5,0.0);cube->normal(0.408248,0.816497,-0.408248);cube->textureCoord(0,1);
cube->position(-0.5,0.5,0.0);cube->normal(-0.666667,0.333333,-0.666667);cube->textureCoord(1,1);
cube->position(0.5,0.5,1.0);cube->normal(0.666667,0.333333,0.666667);cube->textureCoord(0,0);
cube->triangle(0,1,2); cube->triangle(3,1,0);
cube->triangle(4,5,6); cube->triangle(4,7,5);
cube->triangle(8,9,10); cube->triangle(10,7,8);
cube->triangle(4,11,12); cube->triangle(4,13,11);
cube->triangle(14,8,12); cube->triangle(14,15,8);
cube->triangle(16,17,18); cube->triangle(16,19,17);
cube->end();
return cube;
}
void TutorialApplication::createChunk (const int StartX, const int StartY, const int StartZ)
{
block_t LastBlock = 0;
Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshMatChunk" + Ogre::StringConverter::toString(m_ChunkID));
MeshChunk->begin("Combined4");
int iVertex = 0;
block_t Block;
block_t Block1;
/* Only create visible faces of chunk */
block_t DefaultBlock = 1;
int SX = 0;
int SY = 0;
int SZ = 0;
int MaxSize = WORLD_SIZE;
float BlockLight, BlockLight1, BlockLight2;
float V1, V2;
for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
{
for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
{
for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
{
Block = GetBlock(x, y, z);
if (Block == 0) continue;
if (Block == 5) continue;
// Compute the block's texture coordinates
V1 = 0.25f * (float)(Block - 1);
V2 = V1 + 0.25f;
//x-1
Block1 = DefaultBlock;
if (x > SX)
Block1 = GetBlock(x-1, y, z);
BlockLight = GetBlockLight(x, y, z) / 255.0f; // x
BlockLight1 = BlockLight * 0.9f; // z
BlockLight2 = BlockLight * 0.8f; // y
//MeshChunk->colour(BlockLight, BlockLight1, BlockLight2); // Crash
if (Block1 == 0)
{
MeshChunk->position(x, y, z+1); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x, y+1, z); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//x+1
Block1 = DefaultBlock;
if (x < SX + MaxSize - 1)
Block1 = GetBlock(x+1,y,z);
if (Block1 == 0)
{
MeshChunk->position(x+1, y, z); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y-1
Block1 = DefaultBlock;
if (y > SY)
Block1 = GetBlock(x,y-1,z);
if (Block1 == 0)
{
MeshChunk->position(x, y, z); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y, z); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z+1); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y+1
Block1 = DefaultBlock;
if (y < SY + MaxSize - 1)
Block1 = GetBlock(x,y+1,z);
if (Block1 == 0)
{
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y+1, z); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z-1
Block1 = DefaultBlock;
if (z > SZ)
Block1 = GetBlock(x,y,z-1);
if (Block1 == 0)
{
MeshChunk->position(x, y+1, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z+1
Block1 = DefaultBlock;
if (z < SZ + MaxSize - 1)
Block1 = GetBlock(x,y,z+1);
if (Block1 == 0)
{
MeshChunk->position(x, y, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
}
}
}
MeshChunk->colour(BlockLight, BlockLight1, BlockLight2);
MeshChunk->end();
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(MeshChunk);
++m_ChunkID;
}
void TutorialApplication::createChunkWater (const int StartX, const int StartY, const int StartZ)
{
block_t LastBlock = 0;
int iVertex = 0;
block_t Block;
block_t Block1;
/* Only create visible faces of chunk */
block_t DefaultBlock = 1;
int SX = 0;
int SY = 0;
int SZ = 0;
int MaxSize = WORLD_SIZE;
float BlockLight, BlockLight1, BlockLight2;
float V1, V2;
Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshWaterChunk" + Ogre::StringConverter::toString(m_ChunkID));
MeshChunk->setDynamic(true);
MeshChunk->begin("WaterTest");
for (int z = StartZ; z < CHUNK_SIZE + StartZ; ++z)
{
for (int y = StartY; y < CHUNK_SIZE + StartY; ++y)
{
for (int x = StartX; x < CHUNK_SIZE + StartX; ++x)
{
Block = GetBlock(x,y,z);
if (Block != 5) continue; //Only create water meshes
BlockLight = GetBlockLight(x, y, z) / 255.0f;
BlockLight1 = BlockLight * 0.9f;
BlockLight2 = BlockLight * 0.8f;
V1 = 1.0f/5.0f * (float)(Block - 1);
V2 = V1 + 1.0f/5.0f;
//x-1
Block1 = DefaultBlock;
if (x > SX) Block1 = GetBlock(x-1,y,z);
if (Block1 != 5)
{
MeshChunk->position(x, y, z+1); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x, y+1, z); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z); MeshChunk->normal(-1,0,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//x+1
Block1 = DefaultBlock;
if (x < SX + MaxSize - 1)
Block1 = GetBlock(x+1,y,z);
if (Block1 != 5)
{
MeshChunk->position(x+1, y, z); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(1,0,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y-1
Block1 = DefaultBlock;
if (y > SY)
Block1 = GetBlock(x,y-1,z);
if (Block1 != 5)
{
MeshChunk->position(x, y, z); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y, z); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z+1); MeshChunk->normal(0,-1,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//y+1
Block1 = DefaultBlock;
if (y < SY + MaxSize - 1)
Block1 = GetBlock(x,y+1,z);
if (Block1 != 5)
{
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y+1, z); MeshChunk->normal(0,1,0); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z-1
Block1 = DefaultBlock;
if (z > SZ)
Block1 = GetBlock(x,y,z-1);
if (Block1 != 5)
{
MeshChunk->position(x, y+1, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y+1, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y, z); MeshChunk->normal(0,0,-1); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
//z+1
Block1 = DefaultBlock;
if (z < SZ + MaxSize - 1)
Block1 = GetBlock(x,y,z+1);
if (Block1 != 5)
{
MeshChunk->position(x, y, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V2);
MeshChunk->position(x+1, y, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V2);
MeshChunk->position(x+1, y+1, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(1, V1);
MeshChunk->position(x, y+1, z+1); MeshChunk->normal(0,0,1); MeshChunk->textureCoord(0, V1);
MeshChunk->triangle(iVertex, iVertex+1, iVertex+2);
MeshChunk->triangle(iVertex+2, iVertex+3, iVertex);
iVertex += 4;
}
}
}
}
}
void TutorialApplication::createSolidTexture(const TCHAR* pName)
{
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true);
Ogre::Technique* tech = mat->getTechnique(0);
Ogre::Pass* pass = tech->getPass(0);
Ogre::TextureUnitState* tex = pass->createTextureUnitState();
tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0.5, 0));
}
void TutorialApplication::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
std::cerr << "*** Creating texture " << pImageFilename << std::endl;
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
Ogre::Technique* tech = mat->getTechnique(0);
Ogre::Pass* pass = tech->getPass(0);
Ogre::TextureUnitState* tex = pass->createTextureUnitState();
tex->setTextureName(pImageFilename);
tex->setNumMipmaps(4);
tex->setTextureAnisotropy(1);
tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);
pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);
tech->setLightingEnabled(false);
std::cerr << "*** Texture created " << pImageFilename << std::endl;
}
void TutorialApplication::createWaterTexture(const TCHAR* pName)
{
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
Ogre::Technique* tech = mat->getTechnique(0);
Ogre::Pass* pass = tech->getPass(0);
Ogre::TextureUnitState* tex = pass->createTextureUnitState();
tech->setLightingEnabled(false);
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
pass->setDepthWriteEnabled(false);
tex->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(0, 0, 1));
tex->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.5);
std::cerr << "*** Texture created " << pName << std::endl;
}
void TutorialApplication::createScene(void)
{
// Create textures
createTexture("Combined4", "minecraft/terrain.png");
createWorldChunks();
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 2, 8, 100);
mSceneMgr->setFog(Ogre::FOG_LINEAR, Ogre::ColourValue(0.8, 0.8, 1), 0.5, 0.0, 200);
mCamera->setFarClipDistance(256); // 256
mCamera->setNearClipDistance(0.01);
}
void TutorialApplication::initWorldBlocksLayers()
{
// DEACTIVATED BY MISSING FULL TERRAIN GENERATION CODE ... :(
/*
int HeightMap[WORLD_SIZE][WORLD_SIZE];
LandMapErosion LayerMaps[10]; // Hard coded because i'm lazy
// Also, WTF is this var ? The number of Layers ?
// 10 layers seems expensive!
int NumLayerMaps = 0;
int BaseSeed;
LandMapErosion m_Landscape;
m_Landscape.CreateBaseNoise(WORLD_SIZE, WORLD_SIZE);
BaseSeed = m_Landscape.m_HeightMap.GetModule.GetSeed();
LandMapErosion Map = m_Landscape.GetAltitudeMap();
// Initialize our temporary height map array
for (int z = 0; z < WORLD_SIZE; ++z)
{
for (int x = 0; x < WORLD_SIZE; ++x