Large diffs are not rendered by default.

@@ -17,6 +17,8 @@
#include <openlima/gui/LimaWindow.hpp>
#include <openlima/input/MouseButton.hpp>
#include <openlima/input/KeyboardButton.hpp>
#include <openlima/graphics/Environment.hpp>
#include <openlima/graphics/PerspectiveCamera.hpp>
#include <openlima/graphics/WavefrontObjReader.hpp>
#include <openlima/graphics/IRenderable.hpp>
#include <openlima/graphics/CachingRenderNode.hpp>
@@ -40,12 +42,8 @@ void showHelp();

class MyWindow : public LimaWindow {
public:
boost::shared_ptr<IRenderable> myRenderable;
Real xPos;
Real yPos;
Real zPos;
Real yRot;
Real xRot;
boost::shared_ptr<PerspectiveCamera> camera;
Environment env;

dtime lastMessage;
dtime time;
@@ -56,22 +54,18 @@ class MyWindow : public LimaWindow {
MyWindow* other;

MyWindow(boost::shared_ptr<IRenderable> renderable,
const char* title, GLfloat* lightColor) : LimaWindow(title, 640, 480) {
const char* title, GLfloat* lightColor)
: LimaWindow(title, 640, 480) {

camera = boost::make_shared<PerspectiveCamera>(OPENLIMA_REAL(75.0));
camera->position.z = -30;
env.setCamera(camera);

boost::shared_ptr<CachingRenderNode> node = boost::make_shared<CachingRenderNode>();
boost::shared_ptr<RotatingRenderNode> tNode = boost::make_shared<RotatingRenderNode>(
OPENLIMA_REAL(45.0), Vector3f(0, 0, 1));

tNode->addChild(renderable);
node->addChild(tNode);
myRenderable = node;
node->addChild(renderable);
env.getRenderNode().addChild(node);

fpsMode = false;
xPos = 0;
yPos = 0;
zPos = -30.0f;
yRot = 0;
xRot = 0;
lastMessage = 5;
time = 0;
amount = 0;
@@ -108,17 +102,17 @@ class MyWindow : public LimaWindow {

virtual void onMouseMove(Mouse& source, const MouseMoveEvent& e) {
if(fpsMode) {
yRot += e.getDelta().x / 10.0f;
xRot += e.getDelta().y / 10.0f;
while(yRot < 0)
yRot += 360;
while(yRot >= 360)
yRot -= 360;

if(xRot < -80)
xRot = -80;
if(xRot > 80)
xRot = 80;
camera->rotation.y += e.getDelta().x / 10.0f;
camera->rotation.x += e.getDelta().y / 10.0f;
while(camera->rotation.y < 0)
camera->rotation.y += 360;
while(camera->rotation.y >= 360)
camera->rotation.y -= 360;

if(camera->rotation.x < -80)
camera->rotation.x = -80;
if(camera->rotation.x > 80)
camera->rotation.x = 80;
}
}

@@ -146,12 +140,13 @@ class MyWindow : public LimaWindow {
virtual void onKeyboardButtonPressed(Keyboard& source, const KeyboardEvent& e) {
if(e.getButton() == KeyboardButtonType::KEY_F1) {
std::cout << "Camera Position:" << std::endl <<
" X: " << xPos << std::endl <<
" Y: " << yPos << std::endl <<
" Z: " << zPos << std::endl <<
" X Rotation: " << xRot << std::endl <<
" Y Rotation: " << yRot << std::endl;
" X: " << camera->position.x << std::endl <<
" Y: " << camera->position.y << std::endl <<
" Z: " << camera->position.z << std::endl <<
" X Rotation: " << camera->rotation.x << std::endl <<
" Y Rotation: " << camera->rotation.y << std::endl;
}


if(source.isPressed(KeyboardButtonType::KEY_CONTROL)) {
if(e.getButton() == KeyboardButtonType::KEY_ADD) {
@@ -241,20 +236,20 @@ class MyWindow : public LimaWindow {
movementSpeed *= 5;


Real yRotRadian = yRot / 180 * OPENLIMA_REAL(3.14159265);
Real yRotRadian = camera->rotation.y / 180 * OPENLIMA_REAL(3.14159265);

if(forwardMovement != 0) {
zPos += cos(-yRotRadian) * movementSpeed * forwardMovement;
xPos += sin(-yRotRadian) * movementSpeed * forwardMovement;
camera->position.z += cos(-yRotRadian) * movementSpeed * forwardMovement;
camera->position.x += sin(-yRotRadian) * movementSpeed * forwardMovement;
}

if(sidewardMovement != 0) {
zPos += sin(yRotRadian) * movementSpeed * sidewardMovement;
xPos += cos(yRotRadian) * movementSpeed * sidewardMovement;
camera->position.z += sin(yRotRadian) * movementSpeed * sidewardMovement;
camera->position.x += cos(yRotRadian) * movementSpeed * sidewardMovement;
}

if(upwardMovement != 0) {
yPos += movementSpeed * upwardMovement;
camera->position.y += movementSpeed * upwardMovement;
}
}
}
@@ -272,36 +267,8 @@ class MyWindow : public LimaWindow {

// You can skip the rendering if you neither call initializeRendering, nor finishRendering.
this->initializeRendering();

#ifdef OPENLIMA_PRECISE_REAL
glRotated(xRot, 1.0, 0.0, 0.0);
glRotated(yRot, 0.0, 1.0, 0.0);
glTranslated(xPos, yPos, zPos);

glTranslated(-10.0, 0.0, 0.0);
for(size_t x = 0; x < 6; x++) {
glTranslated(0.0, 10.0, 0.0);
for(size_t y = 0; y < 6; y++) {
myRenderable->render();
glTranslated(0.0, -4.0, 0.0);
}
glTranslated(4.0, 14.0, 0.0);
}
#else
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
glTranslatef(xPos, yPos, zPos);

glTranslatef(-10.0f, 0.0f, 0.0f);
for(size_t x = 0; x < 6; x++) {
glTranslatef(0.0f, 10.0f, 0.0f);
for(size_t y = 0; y < 6; y++) {
myRenderable->render();
glTranslatef(0.0f, -4.0f, 0.0f);
}
glTranslatef(4.0f, 14.0f, 0.0f);
}
#endif

env.render(Vector2i(this->getWidth(), this->getHeight()));

this->finishRendering();
}
@@ -339,10 +306,10 @@ OPENLIMA_MAIN(int argc, char** argv) {

resourceManager->registerReader<StaticMesh>(new WavefrontObjReader);
boost::shared_ptr<IRenderable> renderable =
resourceManager->getResource<StaticMesh>("monkey.obj");
resourceManager->getResource<StaticMesh>("sampleTerrain.obj");

if(!renderable) {
std::cout << "Failed to load resource: \"./resources/monkey.obj\"" << std::endl;
std::cout << "Failed to load resource: \"./resources/sampleTerrain.obj\"" << std::endl;
return 1;
}

@@ -0,0 +1,106 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_ENVIRONMENT_HPP
#define OPENLIMA_GRAPHICS_ENVIRONMENT_HPP

#include <boost/smart_ptr.hpp>

#include <openlima/util/macros.hpp>
#include <openlima/util/Vector2.hpp>
#include <openlima/graphics/RenderNode.hpp>
#include <openlima/graphics/ICamera.hpp>
#include <openlima/graphics/IRenderable.hpp>
#include <openlima/graphics/IProjectionModifier.hpp>


namespace openlima {
namespace graphics {

/**
* An environment which manages the lightning, cameras and contains a render node that gets
* drawn.
*/
class Environment {
private:

/** The "root" render node. */
RenderNode renderNode;

/** A render initializer. Can do pre-render stuff like camera offset. */
boost::shared_ptr<IRenderable> renderInitializer;

/** A projection modifier, that sets up the projection matrix. */
boost::shared_ptr<IProjectionModifier> projectionModifier;

public:

/**
* Creates a new environment.
*/
OPENLIMA_DLL Environment();

/**
* Finalizer.
*/
OPENLIMA_DLL virtual ~Environment();


/**
* Sets the projection modifier for this environment.
*
* @param projectionModifier The projection modifier.
*/
OPENLIMA_DLL void setProjectionModifier(
boost::shared_ptr<IProjectionModifier> projectionModifier);

/**
* Sets the render initializer for this environment.
*
* @param renderInitializer The render initializer.
*/
OPENLIMA_DLL void setRenderInitializer(
boost::shared_ptr<IRenderable> renderInitializer);

/**
* Sets the camera for this environment.
*
* @param camera The camera.
*/
OPENLIMA_DLL void setCamera(boost::shared_ptr<ICamera> camera);

/**
* Returns the projection modifier of this environment.
*
* @return The projection modifier of this environment.
*/
OPENLIMA_DLL boost::shared_ptr<IProjectionModifier> getProjectionModifier();

/**
* Returns the render initializer of this environment.
*
* @return The render initializer of this environment.
*/
OPENLIMA_DLL boost::shared_ptr<IRenderable> getRenderInitializer();

/**
* Returns the root render node of this environment.
*
* @return The root render node of this environment.
*/
OPENLIMA_DLL RenderNode& getRenderNode();

/**
* Renders this environment.
*/
OPENLIMA_DLL void render(openlima::util::Vector2i dimensions);

};

}
}

#endif /* OPENLIMA_GRAPHICS_ENVIRONMENT_HPP */
@@ -0,0 +1,39 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_ICAMERA_HPP
#define OPENLIMA_GRAPHICS_ICAMERA_HPP

#include <openlima/util/macros.hpp>
#include <openlima/graphics/IProjectionModifier.hpp>
#include <openlima/graphics/IRenderable.hpp>


namespace openlima {
namespace graphics {

/**
* An interface for cameras. Has a render()-method that should be called BEFORE rendering
* any other object of the scene, and a modifyProjectionMatrix(Vector2i)-method that
* modifies the projection matrix.
*
* @see IProjectionModifier
* @see IRenderable
*/
class ICamera : public IProjectionModifier, public IRenderable {
public:

/**
* Finalizer.
*/
OPENLIMA_DLL virtual ~ICamera() {}

};

}
}

#endif /* OPENLIMA_GRAPHICS_ICAMERA_HPP */
@@ -0,0 +1,42 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_IPROJECTIONMODIFIER_HPP
#define OPENLIMA_GRAPHICS_IPROJECTIONMODIFIER_HPP

#include <openlima/util/macros.hpp>
#include <openlima/util/Vector2.hpp>


namespace openlima {
namespace graphics {

/**
* An interface for projection modifiers.
*/
class IProjectionModifier {
public:

/**
* Finalizer.
*/
OPENLIMA_DLL virtual ~IProjectionModifier() {}


/**
* Modifies the projection matrix. The dimensions are sometimes needed for instance to
* calculate aspect ratios.
*
* @param dimensions The screen dimensions
*/
OPENLIMA_DLL virtual void modifyProjection(openlima::util::Vector2i dimensions) = 0;

};

}
}

#endif /* OPENLIMA_GRAPHICS_IPROJECTIONMODIFIER_HPP */
@@ -0,0 +1,72 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_PERSPECTIVECAMERA_HPP
#define OPENLIMA_GRAPHICS_PERSPECTIVECAMERA_HPP

#include <openlima/util/macros.hpp>
#include <openlima/util/types.hpp>
#include <openlima/util/Vector2.hpp>
#include <openlima/util/Vector3.hpp>
#include <openlima/graphics/ICamera.hpp>


namespace openlima {
namespace graphics {

/**
* A perspective camera that sets up a perspective projection.
*
* @see ICamera
*/
class PerspectiveCamera : public ICamera {
private:

/** The field of view for this camera. */
openlima::util::Real fov;

public:

/** The position of this camera. */
openlima::util::Vector3f position;

/** The rotation of this camera. */
openlima::util::Vector3f rotation;


/**
* Creates a new perspective camera.
*
* @param fov The field of view of this camera.
*/
OPENLIMA_DLL PerspectiveCamera(openlima::util::Real fov);

/**
* Finalizer.
*/
OPENLIMA_DLL virtual ~PerspectiveCamera();


/**
* Sets up a perspective projection. The dimensions are needed to calculate the aspect
* ratio.
*
* @param dimensions The screen dimensions
*/
OPENLIMA_DLL virtual void modifyProjection(openlima::util::Vector2i dimensions);

/**
* Renders this camera. In this case, modifies the current matrix to be affected by the
* position and rotation of this camera.
*/
OPENLIMA_DLL virtual void render();

};

}
}

#endif /* OPENLIMA_GRAPHICS_PERSPECTIVECAMERA_HPP */
@@ -0,0 +1,63 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#include <openlima/util/Vector2.hpp>
#include <openlima/sil/sigl.hpp>
#include <openlima/graphics/Environment.hpp>

using namespace openlima::util;


namespace openlima {
namespace graphics {

Environment::Environment() {
// Empty
}

Environment::~Environment() {
// Empty
}


void Environment::setProjectionModifier(
boost::shared_ptr<IProjectionModifier> projectionModifier) {
this->projectionModifier = projectionModifier;
}

void Environment::setRenderInitializer(boost::shared_ptr<IRenderable> renderInitializer) {
this->renderInitializer = renderInitializer;
}
boost::shared_ptr<IProjectionModifier> Environment::getProjectionModifier() {
return projectionModifier;
}

boost::shared_ptr<IRenderable> Environment::getRenderInitializer() {
return renderInitializer;
}

void Environment::setCamera(boost::shared_ptr<ICamera> camera) {
this->projectionModifier = camera;
this->renderInitializer = camera;
}

RenderNode& Environment::getRenderNode() {
return this->renderNode;
}

void Environment::render(Vector2i dimensions) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(projectionModifier) projectionModifier->modifyProjection(dimensions);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(renderInitializer) renderInitializer->render();
this->renderNode.render();
}

}
}
@@ -0,0 +1,47 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of OpenLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenLima. If not, see: <http://www.gnu.org/licenses/>.

#include <openlima/util/macros.hpp>
#include <openlima/graphics/PerspectiveCamera.hpp>
#include <openlima/sil/sigl.hpp>

using namespace openlima::util;


namespace openlima {
namespace graphics {

PerspectiveCamera::PerspectiveCamera(Real fov) {
this->fov = fov;
}

PerspectiveCamera::~PerspectiveCamera() {
// Empty
}


void PerspectiveCamera::modifyProjection(Vector2i dimensions) {
gluPerspective(fov,
(double)dimensions.x / (double)dimensions.y,
0.01, 200.0);
}

void PerspectiveCamera::render() {
#ifdef OPENLIMA_PRECISE_REAL
glRotated(rotation.x, 1.0, 0.0, 0.0);
glRotated(rotation.z, 0.0, 0.0, 1.0);
glRotated(rotation.y, 0.0, 1.0, 0.0);
glTranslated(position.x, position.y, position.z);
#else
glRotatef(rotation.x, 1.0f, 0.0f, 0.0f);
glRotatef(rotation.z, 0.0f, 0.0f, 1.0f);
glRotatef(rotation.y, 0.0f, 1.0f, 0.0f);
glTranslatef(position.x, position.y, position.z);
#endif
}

}
}