Просмотр исходного кода

Merge branch 'master' into lua-env

mikymod 12 лет назад
Родитель
Сommit
9d2ad762f4
40 измененных файлов с 1195 добавлено и 1222 удалено
  1. 2 0
      samples/terrain/CMakeLists.txt
  2. 1 1
      samples/terrain/Terrain.cpp
  3. 0 0
      samples/terrain/Terrain.h
  4. 32 52
      samples/terrain/terrain.cpp
  5. 4 6
      src/CMakeLists.txt
  6. 0 1
      src/Crown.h
  7. 40 0
      src/Device.cpp
  8. 9 0
      src/Device.h
  9. 0 113
      src/EventBuffer.cpp
  10. 6 6
      src/FPSSystem.cpp
  11. 5 1
      src/Filesystem.cpp
  12. 0 261
      src/Image.cpp
  13. 0 118
      src/Image.h
  14. 8 8
      src/core/bv/Frustum.cpp
  15. 37 8
      src/core/compressors/Compressor.h
  16. 29 2
      src/core/compressors/ZipCompressor.cpp
  17. 29 1
      src/core/compressors/ZipCompressor.h
  18. 78 85
      src/core/math/Intersection.h
  19. 10 25
      src/input/Accelerometer.cpp
  20. 37 5
      src/input/Accelerometer.h
  21. 88 45
      src/input/InputManager.cpp
  22. 31 92
      src/input/InputManager.h
  23. 75 9
      src/input/KeyCode.h
  24. 24 32
      src/input/Keyboard.cpp
  25. 30 48
      src/input/Keyboard.h
  26. 95 0
      src/input/Mouse.cpp
  27. 63 7
      src/input/Mouse.h
  28. 26 20
      src/input/Touch.cpp
  29. 46 27
      src/input/Touch.h
  30. 14 2
      src/os/linux/GLXRenderWindow.cpp
  31. 29 19
      src/os/linux/Input.cpp
  32. 0 4
      src/renderers/gles/CMakeLists.txt
  33. 0 67
      src/renderers/gles/GLESIndexBuffer.cpp
  34. 17 21
      src/renderers/gles/GLESUtils.h
  35. 0 130
      src/renderers/gles/GLESVertexBuffer.cpp
  36. 37 4
      tools/editors/world-editor/CMakeLists.txt
  37. 2 2
      tools/editors/world-editor/CrownDrawingArea.cpp
  38. 175 0
      tools/editors/world-editor/terrain/Heightfield.cpp
  39. 94 0
      tools/editors/world-editor/terrain/Heightfield.h
  40. 22 0
      tools/editors/world-editor/ui/world-editor.glade

+ 2 - 0
samples/terrain/CMakeLists.txt

@@ -2,9 +2,11 @@ cmake_minimum_required(VERSION 2.8)
 
 set (SRC
 	terrain.cpp
+	Terrain.cpp
 )
 
 set (HEADERS
+	Terrain.h
 )
 
 add_library (game SHARED ${SRC} ${HEADERS})

+ 1 - 1
src/Terrain.cpp → samples/terrain/Terrain.cpp

@@ -237,7 +237,7 @@ bool Terrain::TraceRay(const Ray& ray, Triangle& result, Triangle& /*tri2*/, rea
 
 		real ret;
 		Vec3 int32_tersectionPoint32_t;
-		if (Intersection::TestRayTriangle(ray, tri, ret, int32_tersectionPoint32_t))
+		if (Intersection::test_ray_triangle(ray, tri, ret, int32_tersectionPoint32_t))
 		{
 			if (ret < minDist)
 			{

+ 0 - 0
src/Terrain.h → samples/terrain/Terrain.h


+ 32 - 52
samples/terrain/terrain.cpp

@@ -23,7 +23,7 @@ public:
 	}
 };
 
-class MainScene: public KeyboardListener, public MouseListener
+class MainScene
 {
 
 public:
@@ -34,8 +34,6 @@ public:
 		optShowTerrain(true),
 		camera_active(true)
 	{
-		device()->input_manager()->register_keyboard_listener(this);
-		device()->input_manager()->register_mouse_listener(this);
 		mouseRightPressed = false;
 		mouseLeftPressed = false;
 	}
@@ -44,83 +42,63 @@ public:
 	{
 	}
 
-	void key_released(const KeyboardEvent& event)
+	void poll_input()
 	{
-		if (event.key == '1')
+		Keyboard* keyb = device()->keyboard();
+		Mouse* mouse = device()->mouse();
+
+		if (keyb->key_pressed(KC_1))
 		{
 			terrain.PlotCircle(2, 2, 2, 2);
 		}
 
-		if (event.key == '2')
+		if (keyb->key_pressed(KC_2))
 		{
 			terrain.PlotCircle(4, 4, 4, 2);
 		}
 
-		if (event.key == '3')
+		if (keyb->key_pressed(KC_3))
 		{		
 			terrain.PlotCircle(8, 8, 8, 2);
 		}
 
-		if (event.key == KC_F5)
+		if (keyb->key_pressed(KC_F5))
 		{
 			device()->reload(grass);
 		}
 
-		if (event.key == KC_SPACE)
+		if (keyb->key_pressed(KC_SPACE))
 		{
 			camera_active = !camera_active;
 		}
-	}
 
-	void button_pressed(const MouseEvent& event)
-	{
-		if (event.button == MB_LEFT)
-		{
-			mouseLeftPressed = true;
+		//GLint view[4];
+		//GLdouble proj[16], model[16];
 
-			//GLint view[4];
-			//GLdouble proj[16], model[16];
+		//glGetDoublev(GL_MODELVIEW_MATRIX, model);
+		//glGetDoublev(GL_PROJECTION_MATRIX, proj);
+		//glGetIntegerv(GL_VIEWPORT, view);
 
-			//glGetDoublev(GL_MODELVIEW_MATRIX, model);
-			//glGetDoublev(GL_PROJECTION_MATRIX, proj);
-			//glGetIntegerv(GL_VIEWPORT, view);
+		//int x = event.x;
+		//int y = event.y;
 
-			//int x = event.x;
-			//int y = event.y;
+		// Adjust y wndCoord
+		//y = (625 - y);
 
-			// Adjust y wndCoord
-			//y = (625 - y);
+		//double sX, sY, sZ;
+		//double eX, eY, eZ;
 
-			//double sX, sY, sZ;
-			//double eX, eY, eZ;
+		//gluUnProject(x, y, 0.0f, model, proj, view, &sX, &sY, &sZ);
+		//gluUnProject(x, y, 1.0f, model, proj, view, &eX, &eY, &eZ);
 
-			//gluUnProject(x, y, 0.0f, model, proj, view, &sX, &sY, &sZ);
-			//gluUnProject(x, y, 1.0f, model, proj, view, &eX, &eY, &eZ);
+		//Vec3 dir = Vec3(eX, eY, eZ) - Vec3(sX, sY, sZ);
 
-			//Vec3 dir = Vec3(eX, eY, eZ) - Vec3(sX, sY, sZ);
+		//dir.normalize();
 
-			//dir.normalize();
+		//ray.direction = dir;
 
-			//ray.direction = dir;
-		}
-		else if (event.button == MB_RIGHT)
-		{
-			mouseRightPressed = true;
-		}
-		wheel += event.wheel * 0.25;
-	}
-
-	void button_released(const MouseEvent& event)
-	{
-		if (event.button == MB_LEFT)
-		{
-			mouseLeftPressed = false;
-		}
-		else if (event.button == MB_RIGHT)
-		{
-			mouseRightPressed = false;
-		}
-		wheel -= event.wheel * 0.25;
+		mouseLeftPressed = mouse->button_pressed(MB_LEFT);
+		mouseRightPressed = mouse->button_pressed(MB_RIGHT);
 	}
 		
 	void on_load()
@@ -164,8 +142,10 @@ public:
 		device()->unload(red_down);
 	}
 
-	void render(float dt)
+	void update(float dt)
 	{
+		poll_input();
+
 		Renderer* renderer = device()->renderer();
 
 		renderer->set_clear_color(Color4::LIGHTBLUE);
@@ -276,6 +256,6 @@ extern "C"
 
 	void frame(float dt)
 	{
-		m_scene.render(dt);
+		m_scene.update(dt);
 	}
 }

+ 4 - 6
src/CMakeLists.txt

@@ -1,13 +1,10 @@
 set (SRC
 	Camera.cpp
 	Device.cpp
-	EventBuffer.cpp
 	Filesystem.cpp
-	Image.cpp
 	MaterialResource.cpp
 	ResourceManager.cpp
 	Skybox.cpp
-	Terrain.cpp
 
 	TextureResource.cpp
 	TextResource.cpp
@@ -26,16 +23,13 @@ set (HEADERS
 	Config.h
 	Crown.h
 	Device.h
-	EventBuffer.h
 	Filesystem.h
 	Glyph.h
-	Image.h
 	MaterialResource.h
 	Resource.h
 	ResourceManager.h
 	ResourceArchive.h
 	Skybox.h
-	Terrain.h
 
 	TextureResource.h
 	TextResource.h
@@ -193,6 +187,10 @@ set (SETTINGS_HEADERS
 set (INPUT_SRC
 	input/EventDispatcher.cpp
 	input/InputManager.cpp
+	input/Keyboard.cpp
+	input/Mouse.cpp
+	input/Touch.cpp
+	input/Accelerometer.cpp
 )
 
 set (INPUT_HEADERS

+ 0 - 1
src/Crown.h

@@ -97,7 +97,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Camera.h"
 #include "Device.h"
 #include "Glyph.h"
-#include "Image.h"
 #include "ResourceArchive.h"
 #include "ArchiveResourceArchive.h"
 #include "FileResourceArchive.h"

+ 40 - 0
src/Device.cpp

@@ -40,6 +40,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "FileResourceArchive.h"
 #include "ResourceManager.h"
 #include "TextureResource.h"
+#include "Keyboard.h"
+#include "Mouse.h"
+#include "Touch.h"
+#include "Accelerometer.h"
 
 #ifdef CROWN_BUILD_OPENGL
 	#include "renderers/gl/GLRenderer.h"
@@ -111,18 +115,30 @@ bool Device::init(int argc, char** argv)
 
 	create_filesystem();
 
+	Log::d("Filesystem created.");
+
 	create_resource_manager();
 
+	Log::d("Resource manager created.");
+
 	create_input_manager();
 
+	Log::d("Input manager created.");
+
 	create_renderer();
 
+	Log::d("Renderer created.");
+
 	create_debug_renderer();
 
+	Log::d("Debug renderer created.");
+
 	Log::i("Crown Engine initialized.");
 
 	Log::i("Initializing Game...");
 
+	Log::d(m_filesystem->root_path());
+
 	// Try to locate the game library
 	if (!m_filesystem->exists(GAME_LIBRARY_NAME))
 	{
@@ -248,6 +264,30 @@ DebugRenderer* Device::debug_renderer()
 	return m_debug_renderer;
 }
 
+//-----------------------------------------------------------------------------
+Keyboard* Device::keyboard()
+{
+	return m_input_manager->keyboard();
+}
+
+//-----------------------------------------------------------------------------
+Mouse* Device::mouse()
+{
+	return m_input_manager->mouse();
+}
+
+//-----------------------------------------------------------------------------
+Touch* Device::touch()
+{
+	return m_input_manager->touch();
+}
+
+//-----------------------------------------------------------------------------
+Accelerometer* Device::accelerometer()
+{
+	return m_input_manager->accelerometer();
+}
+
 //-----------------------------------------------------------------------------
 void Device::start()
 {

+ 9 - 0
src/Device.h

@@ -40,6 +40,10 @@ class ResourceArchive;
 class Renderer;
 class DebugRenderer;
 class InputManager;
+class Keyboard;
+class Mouse;
+class Touch;
+class Accelerometer;
 class Game;
 
 /// The Engine.
@@ -97,6 +101,11 @@ public:
 	Renderer*				renderer();
 	DebugRenderer*			debug_renderer();
 
+	Keyboard*				keyboard();
+	Mouse*					mouse();
+	Touch*					touch();
+	Accelerometer*			accelerometer();
+
 private:
 
 	void					create_filesystem();

+ 0 - 113
src/EventBuffer.cpp

@@ -1,113 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "EventBuffer.h"
-#include "Types.h"
-#include <cstring>
-#include <stdio.h>
-
-namespace crown
-{
-
-EventBuffer::EventBuffer() : mBufferCount(0)
-{
-}
-
-EventBuffer::~EventBuffer()
-{
-}
-
-void EventBuffer::PushEvent(uint32_t eventType, void* eventData, size_t eventSize)
-{
-	if (mBufferCount + sizeof(eventType) + eventSize > MAX_EVENT_QUEUE_SIZE)
-	{
-		Flush();
-	}
-
-	uint8_t* q = mBuffer + mBufferCount;
-
-	*(uint32_t*) q = eventType;
-	*(size_t*) (q + sizeof(eventType)) = eventSize;
-	memcpy(q + sizeof(eventType) + sizeof(eventSize), eventData, eventSize);
-
-	mBufferCount += sizeof(eventType) + sizeof(eventSize) + eventSize;
-}
-
-void EventBuffer::PushEventBuffer(uint8_t* eventBuffer, size_t bufferSize)
-{
-	if (mBufferCount + bufferSize > MAX_EVENT_QUEUE_SIZE)
-	{
-		Flush();
-	}
-
-	uint8_t* q = mBuffer + mBufferCount;
-	memcpy(q, eventBuffer, bufferSize);
-
-	mBufferCount += bufferSize;
-}
-
-void* EventBuffer::NextEvent(uint32_t& eventType, size_t& size)
-{
-	static size_t read = 0;
-
-	if (read < mBufferCount)
-	{
-		uint8_t* q = mBuffer + read;
-
-		eventType = *(uint32_t*)q;
-		size = *(size_t*)(q + sizeof(uint32_t));
-
-		read += sizeof(uint32_t) + sizeof(size_t) + size;
-
-		return q + sizeof(uint32_t) + sizeof(size_t);
-	}
-
-	read = 0;
-
-	return NULL;
-}
-
-void EventBuffer::Clear()
-{
-	mBufferCount = 0;
-}
-
-void EventBuffer::Flush()
-{
-	mBufferCount = 0;
-}
-
-size_t EventBuffer::GetSize() const
-{
-	return mBufferCount;
-}
-
-uint8_t* EventBuffer::GetBuffer()
-{
-	return mBuffer;
-}
-
-} // namespace crown
-

+ 6 - 6
src/FPSSystem.cpp

@@ -52,7 +52,7 @@ FPSSystem::FPSSystem(Camera* camera, float speed, float sensibility) :
 	device()->input_manager()->register_keyboard_listener(this);
 	device()->input_manager()->register_accelerometer_listener(this);
 	//device()->input_manager()->register_mouse_listener(this);
-	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
+	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
 	
 }
 
@@ -176,9 +176,9 @@ void FPSSystem::update(float dt)
 //-----------------------------------------------------------------------	
 void FPSSystem::set_view_by_cursor()
 {
-	static Vec2 lastPos = device()->input_manager()->get_cursor_relative_xy();
-	Vec2 currentPos = device()->input_manager()->get_cursor_relative_xy();
-	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
+	static Vec2 lastPos = device()->mouse()->cursor_relative_xy();
+	Vec2 currentPos = device()->mouse()->cursor_relative_xy();
+	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
 
 	if (lastPos == currentPos)
 	{
@@ -187,8 +187,8 @@ void FPSSystem::set_view_by_cursor()
 
 	Vec2 delta = lastPos - currentPos;
 
-	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-	lastPos = device()->input_manager()->get_cursor_relative_xy();
+	device()->mouse()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
+	lastPos = device()->mouse()->cursor_relative_xy();
 
 	m_angle_x += delta.y * m_camera_sensibility;
 	m_angle_y += delta.x * m_camera_sensibility;

+ 5 - 1
src/Filesystem.cpp

@@ -172,11 +172,15 @@ bool Filesystem::delete_dir(const char* relative_path)
 //-----------------------------------------------------------------------------
 const char* Filesystem::os_path(const char* relative_path)
 {
+	static char os_path[os::MAX_PATH_LENGTH];
+
 	FilesystemEntry entry;
 
 	get_info(relative_path, entry);
 
-	return entry.os_path;
+	string::strncpy(os_path, entry.os_path, os::MAX_PATH_LENGTH);
+
+	return os_path;
 }
 
 //-----------------------------------------------------------------------------

+ 0 - 261
src/Image.cpp

@@ -1,261 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "Image.h"
-#include "Log.h"
-#include "Types.h"
-#include "Stream.h"
-
-namespace crown
-{
-
-Image::Image() :
-	mPixelFormat(PF_UNKNOWN),
-	mWidth(0),
-	mHeight(0),
-	mBuffer(NULL)
-{
-}
-
-Image::Image(PixelFormat pixelFormat, uint32_t width, uint32_t height, uint8_t* data) :
-	mPixelFormat(pixelFormat),
-	mWidth(width),
-	mHeight(height),
-	mBuffer(data)
-{
-	if (data == NULL)
-	{
-		CreateBuffer();
-		SetUniformColorImage(Color4::WHITE);
-	}
-}
-
-Image::~Image()
-{
-	DestroyImage();
-}
-
-void Image::CreateImage(PixelFormat pixelFormat, uint32_t width, uint32_t height, uint8_t* data)
-{
-	mPixelFormat = pixelFormat;
-	mWidth = width;
-	mHeight = height;
-	mBuffer = data;
-}
-
-void Image::DestroyImage()
-{
-	if (mBuffer)
-	{
-		delete[] mBuffer;
-	}
-
-	mPixelFormat = PF_UNKNOWN;
-	mWidth = 0;
-	mHeight = 0;
-	mBuffer = NULL;
-}
-
-void Image::SetUniformColorImage(Color4 color)
-{
-	AssertRGB8();
-	int32_t bpp = GetBytesPerPixel();
-
-	uint8_t red   = (uint8_t)(color.r * 255.0f);
-	uint8_t green = (uint8_t)(color.g * 255.0f);
-	uint8_t blue  = (uint8_t)(color.b * 255.0f);
-
-	for(uint32_t i = 0; i < mHeight; i++)
-	{
-		int32_t rowOffset = i * mWidth * bpp;
-		for(uint32_t j = 0; j < mWidth; j++)
-		{
-			int32_t offset = rowOffset + bpp * j;
-			mBuffer[offset    ] = red;
-			mBuffer[offset + 1] = green;
-			mBuffer[offset + 2] = blue;
-		}
-	}
-}
-
-uint32_t Image::GetWidth() const
-{
-	return mWidth;
-}
-
-uint32_t Image::GetHeight() const
-{
-	return mHeight;
-}
-
-PixelFormat Image::GetFormat() const
-{
-	return mPixelFormat;
-}
-
-uint32_t Image::GetBytesPerPixel() const
-{
-	return Pixel::bytes_per_pixel(mPixelFormat);
-}
-
-uint32_t Image::GetBitsPerPixel() const
-{
-	return Pixel::bytes_per_pixel(mPixelFormat);
-}
-
-uint8_t* Image::GetBuffer()
-{
-	return mBuffer;
-}
-
-const uint8_t* Image::GetBuffer() const
-{
-	return mBuffer;
-}
-
-void Image::ApplyColorKeying(const Color4& color)
-{
-	assert(mPixelFormat == PF_RGBA_8);
-
-	for (uint64_t i = 0; i < mWidth * mHeight * 4; i += 4)
-	{
-		if (Color4(mBuffer[i], mBuffer[i+1], mBuffer[i+2]) == color)
-		{
-			mBuffer[i] = 0;
-			mBuffer[i+1] = 0;
-			mBuffer[i+2] = 0;
-			mBuffer[i+3] = 0;
-		}
-	}
-}
-
-void Image::ApplyGreyscaleToAlpha(Image* greyscaleImage)
-{
-	if (mPixelFormat != PF_RGBA_8)
-	{
-		Log::e("Image::ApplyGreyscaleToAlpha: Can apply alpha only on RGBA8 pixel formats.");
-		return;
-	}
-
-	if (greyscaleImage == NULL)
-	{
-		Log::e("Image::ApplyGreyscaleToAlpha: greyscaleImage is NULL.");
-		return;
-	}
-
-	if (greyscaleImage->mPixelFormat != PF_RGBA_8)
-	{
-		Log::e("Image::ApplyGreyscaleToAlpha: greyscaleImage must have pixel format RGBA8.");
-		return;
-	}
-
-	if (mWidth != greyscaleImage->mWidth || mHeight != greyscaleImage->mHeight)
-	{
-		Log::e("Image::ApplyGreyscaleToAlpha: greyscaleImage must have the same dimensions of the image.");
-		return;
-	}
-
-	for (uint64_t i = 0; i < mWidth * mHeight * 4; i += 4)
-	{
-		mBuffer[i+3] = greyscaleImage->mBuffer[i];
-	}
-}
-
-void Image::AlphaToGreyscale()
-{
-	for (uint64_t i = 0; i < mWidth * mHeight * 4; i += 4)
-	{
-		mBuffer[i]   = mBuffer[i+3];
-		mBuffer[i+1] = mBuffer[i+3];
-		mBuffer[i+2] = mBuffer[i+3];
-		mBuffer[i+3] = 255;
-	}
-}
-
-void Image::CreateBuffer()
-{
-	if (mBuffer == NULL)
-	{
-		mBuffer = new uint8_t[mWidth * mHeight * GetBytesPerPixel()];
-	}
-}
-
-void Image::AssertRGB8()
-{
-	assert(mPixelFormat == PF_RGB_8);
-}
-
-void Image::SetPixel(uint32_t x, uint32_t y, Color4 color)
-{
-	/*AssertRGB8();
-	if (x >= mWidth || y >= mHeight)
-	{
-		throw ArgumentException("Coordinates outside the Image");
-	}*/
-
-	int32_t bpp = 3;//bytes_per_pixel();
-	int32_t offset = (y * mWidth + x) * GetBytesPerPixel();
-	mBuffer[offset    ] = (uint8_t)(color.r * 255);
-	mBuffer[offset + 1] = (uint8_t)(color.g * 255);
-	mBuffer[offset + 2] = (uint8_t)(color.b * 255);
-}
-
-void Image::CopyTo(Image& dest) const
-{
-	dest.mWidth = mWidth;
-	dest.mHeight = mHeight;
-	dest.mPixelFormat = mPixelFormat;
-	dest.CreateBuffer();
-
-	for (uint64_t i = 0; i < mWidth * mHeight * GetBytesPerPixel(); i++)
-	{
-		dest.mBuffer[i] = mBuffer[i];
-	}
-}
-
-void Image::ConvertToRGBA8()
-{
-	assert(mPixelFormat != PF_UNKNOWN);
-
-	uint8_t* newBuf = new uint8_t[mWidth * mHeight * 4];
-
-	uint32_t j = 0;
-	for (uint32_t i = 0; i < mWidth * mHeight * 2; i += 2)
-	{
-		newBuf[j + 0] = mBuffer[i + 0];
-		newBuf[j + 1] = mBuffer[i + 0];
-		newBuf[j + 2] = mBuffer[i + 0];
-		newBuf[j + 3] = mBuffer[i + 1];
-
-		j += 4;
-	}
-
-	delete[] mBuffer;
-	mBuffer = newBuf;
-	mPixelFormat = PF_RGBA_8;
-}
-
-} // namespace crown
-

+ 0 - 118
src/Image.h

@@ -1,118 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Color4.h"
-#include "Pixel.h"
-
-namespace crown
-{
-
-//! Holds an image
-class Image
-{
-
-public:
-
-	//! Constructor
-	Image();
-
-	//! Constructor
-	Image(PixelFormat pixelFormat, uint32_t width, uint32_t height, uint8_t* data);
-
-	//! Destructor
-	~Image();
-
-	//! Creates the image
-	void CreateImage(PixelFormat pixelFormat, uint32_t width, uint32_t height, uint8_t* data);
-
-	//! Destroys the image
-	void DestroyImage();
-
-	//! Returns the image's width in pixels
-	uint32_t GetWidth() const;
-
-	//! Returns the image's height in pixels
-	uint32_t GetHeight() const;
-
-	//! Returns the image's pixel format
-	PixelFormat GetFormat() const;
-
-	//! Returns the image's bits per pixel
-	uint32_t GetBitsPerPixel() const;
-
-	//! Returns the image's bytes per pixel
-	uint32_t GetBytesPerPixel() const;
-
-	//! Returns a point32_ter to the image data
-	uint8_t* GetBuffer();
-
-	//! Returns a const point32_ter to the image data
-	const uint8_t* GetBuffer() const;
-
-	//! Apply a color-keying
-	void ApplyColorKeying(const Color4& color);
-
-	//! Apply a greyscale image as alpha
-	void ApplyGreyscaleToAlpha(Image* greyscaleImage);
-
-	//! Use the alpha channel to build a greyscale opaque image
-	void AlphaToGreyscale();
-
-	//! Create a colored image of the same size of the current one
-	void SetUniformColorImage(Color4 color);
-
-	//! Set the pixel at location x,y to the specified color
-	void SetPixel(uint32_t x, uint32_t y, Color4 color);
-
-	void ConvertToRGBA8();
-
-	/**
-		Copies the image to dest.
-	@note
-		Destination image must be empty.
-	*/
-	void CopyTo(Image& dest) const;
-
-private:
-
-	PixelFormat	mPixelFormat;
-	uint32_t		mWidth;
-	uint32_t		mHeight;
-
-	uint8_t*		mBuffer;
-
-	void CreateBuffer();
-	void AssertRGB8();
-
-	// Disable copying
-	Image(const Image&);
-	Image& operator=(const Image&);
-};
-
-} // namespace crown
-

+ 8 - 8
src/core/bv/Frustum.cpp

@@ -79,21 +79,21 @@ Vec3 Frustum::vertex(uint32_t index) const
 	switch (index)
 	{
 		case 0:
-			return Intersection::TestPlane3(m_planes[4], m_planes[0], m_planes[2], ip);
+			return Intersection::test_plane_3(m_planes[4], m_planes[0], m_planes[2], ip);
 		case 1:
-			return Intersection::TestPlane3(m_planes[4], m_planes[1], m_planes[2], ip);
+			return Intersection::test_plane_3(m_planes[4], m_planes[1], m_planes[2], ip);
 		case 2:
-			return Intersection::TestPlane3(m_planes[4], m_planes[1], m_planes[3], ip);
+			return Intersection::test_plane_3(m_planes[4], m_planes[1], m_planes[3], ip);
 		case 3:
-			return Intersection::TestPlane3(m_planes[4], m_planes[0], m_planes[3], ip);
+			return Intersection::test_plane_3(m_planes[4], m_planes[0], m_planes[3], ip);
 		case 4:
-			return Intersection::TestPlane3(m_planes[5], m_planes[0], m_planes[2], ip);
+			return Intersection::test_plane_3(m_planes[5], m_planes[0], m_planes[2], ip);
 		case 5:
-			return Intersection::TestPlane3(m_planes[5], m_planes[1], m_planes[2], ip);
+			return Intersection::test_plane_3(m_planes[5], m_planes[1], m_planes[2], ip);
 		case 6:
-			return Intersection::TestPlane3(m_planes[5], m_planes[1], m_planes[3], ip);
+			return Intersection::test_plane_3(m_planes[5], m_planes[1], m_planes[3], ip);
 		case 7:
-			return Intersection::TestPlane3(m_planes[5], m_planes[0], m_planes[3], ip);
+			return Intersection::test_plane_3(m_planes[5], m_planes[0], m_planes[3], ip);
 		default:
 			break;
 	}

+ 37 - 8
src/core/compressors/Compressor.h

@@ -1,3 +1,28 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #pragma once
 
 #include "Types.h"
@@ -10,9 +35,18 @@ class Compressor
 {
 public:
 						Compressor(Allocator& allocator);
-	virtual 			~Compressor();	
+	virtual 			~Compressor() {}
 
+	/// Compresses the data pointed by @data of size @in_size (in bytes) and returns it.
+	/// The function also returns the size in bytes of the compressed data in @out_size.
+	/// @note
+	/// The returned data is automatically allocated using the passed allocator.
 	virtual uint8_t* 	compress(const void* data, size_t in_size, size_t& out_size) = 0;
+
+	/// Uncompresses the data pointed by @data of size @in_size (in bytes) and returns it.
+	/// The function also returns the size in bytes of the uncompressed data in @out_size.
+	/// @note
+	/// The returned data is automatically allocated using the passed allocator.
 	virtual uint8_t* 	uncompress(const void* data, size_t in_size, size_t& out_size) = 0;
 
 protected:
@@ -20,15 +54,10 @@ protected:
 	Allocator& 			m_allocator;
 };
 
+//-----------------------------------------------------------------------------
 inline Compressor::Compressor(Allocator& allocator) :
 	m_allocator(allocator)
 {
-
-}
-
-inline Compressor::~Compressor()
-{
-	
 }
 
-}
+} // namespace crown

+ 29 - 2
src/core/compressors/ZipCompressor.cpp

@@ -1,3 +1,28 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #include <cstring>
 
 #include "zlib.h"
@@ -6,17 +31,18 @@
 namespace crown
 {
 
+//-----------------------------------------------------------------------------
 ZipCompressor::ZipCompressor(Allocator& allocator) :
 	Compressor(allocator)
 {
-	
 }
 
+//-----------------------------------------------------------------------------
 ZipCompressor::~ZipCompressor()
 {
-
 }
 
+//-----------------------------------------------------------------------------
 uint8_t* ZipCompressor::compress(const void* data, size_t in_size, size_t& out_size)
 {
 	out_size = in_size + in_size * 0.1f + 12;
@@ -30,6 +56,7 @@ uint8_t* ZipCompressor::compress(const void* data, size_t in_size, size_t& out_s
 	return dest;
 }
 
+//-----------------------------------------------------------------------------
 uint8_t* ZipCompressor::uncompress(const void* data, size_t in_size, size_t& out_size)
 {
 	out_size = in_size + in_size * 0.1f + 12;

+ 29 - 1
src/core/compressors/ZipCompressor.h

@@ -1,11 +1,36 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #pragma once
 
 #include "Compressor.h"
-#include "List.h"
 
 namespace crown
 {
 
+/// Generic data compressor which uses zlib.
 class ZipCompressor : public Compressor
 {
 public:
@@ -13,7 +38,10 @@ public:
 				ZipCompressor(Allocator& allocator);
 				~ZipCompressor();
 	
+	/// @copydoc Compressor::compress()
 	uint8_t* 	compress(const void* data, size_t in_size, size_t& out_size);
+
+	/// @copydoc Compressor::uncompress()
 	uint8_t* 	uncompress(const void* data, size_t in_size, size_t& out_size);
 };
 

+ 78 - 85
src/core/math/Intersection.h

@@ -38,79 +38,72 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/**
- * Intersection test utils.
- *
- * Table of Intersection tests (3d)
- * +----------+----------+----------+----------+----------+----------+----------+
- * |          | Ray      | Plane    | Sphere   | Box      | Frustum  | Triangle |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Ray      | No       | Yes      | Yes      | No       | No       | Yes      |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Plane    | -        | Yes (1)  | Yes (+)  | No       | No       | No       |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Sphere   | -        | -        | Yes (+)  | No       | Yes      | Yes (+)  |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Box      | -        | -        | -        | Yes (+)  | Yes      | No       |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Frustum  | -        | -        | -        | -        | No       | No       |
- * +----------+----------+----------+----------+----------+----------+----------+
- * | Triangle | -        | -        | -        | -        | -        | No       |
- * +----------+----------+----------+----------+----------+----------+----------+
- *
- * Notes:
- * (1): Intersection of three planes
- * (-): Static intersection only
- * (+): Static/Dynamic intersection
- *
- * Table of Intersection tests (2d)
- * +---------------+----------+-------------+-------------+----------+----------+
- * |               | Circle   | Rect        | O Rect      | Segment  | Ray 2d   |
- * +---------------+----------+-------------+-------------+----------+----------+
- * | Circle        | Yes (p-) | No          | No          | No       | No       |
- * +---------------+----------+-------------+-------------+----------+----------+
- * | Rect          | -        | Yes         | No          | No       | No       | <- Axis Aligned Rect
- * +---------------+----------+-------------+-------------+----------+----------+
- * | O Rect        | -        | -           | No          | No       | No       | <- Oriented Rect
- * +---------------+----------+-------------+-------------+----------+----------+
- * | Segment       | -        | -           | -           | No       | No       |
- * +---------------+----------+-------------+-------------+----------+----------+
- * | Ray 2d        | -        | -           | -           | -        | No       |
- * +---------------+----------+-------------+-------------+----------+----------+
- *
- * Notes:
- * (p): Penetration vector
- * (-): Static intersection only
- * (+): Static/Dynamic intersection
- */
+/// Intersection test utils.
+/// Table of Intersection tests (3d)
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// |          | Ray      | Plane    | Sphere   | Box      | Frustum  | Triangle |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Ray      | No       | Yes      | Yes      | No       | No       | Yes      |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Plane    | -        | Yes (1)  | Yes (+)  | No       | No       | No       |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Sphere   | -        | -        | Yes (+)  | No       | Yes      | Yes (+)  |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Box      | -        | -        | -        | Yes (+)  | Yes      | No       |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Frustum  | -        | -        | -        | -        | No       | No       |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// | Triangle | -        | -        | -        | -        | -        | No       |
+/// +----------+----------+----------+----------+----------+----------+----------+
+/// Notes:
+/// (1): Intersection of three planes
+/// (-): Static intersection only
+/// (+): Static/Dynamic intersection
+/// Table of Intersection tests (2d)
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// |               | Circle   | Rect        | O Rect      | Segment  | Ray 2d   |
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// | Circle        | Yes (p-) | No          | No          | No       | No       |
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// | Rect          | -        | Yes         | No          | No       | No       | <- Axis Aligned Rect
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// | O Rect        | -        | -           | No          | No       | No       | <- Oriented Rect
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// | Segment       | -        | -           | -           | No       | No       |
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// | Ray 2d        | -        | -           | -           | -        | No       |
+/// +---------------+----------+-------------+-------------+----------+----------+
+/// Notes:
+/// (p): Penetration vector
+/// (-): Static intersection only
+/// (+): Static/Dynamic intersection
 class Intersection
 {
-
 public:
 
-	static bool TestRayPlane(const Ray& r, const Plane& p, real& distance, Vec3& inttersectionPoint_t);
-	static bool TestRaySphere(const Ray& r, const Sphere& s, real& distance, Vec3& intersectionPoint);
-	static bool TestRayBox(const Ray& r, const Box& b, real& distance, Vec3& intersectionPoint);
-	static bool TestRayTriangle(const Ray& r, const Triangle& t, real& distance, Vec3& intersectionPoint);
+	static bool test_ray_plane(const Ray& r, const Plane& p, real& distance, Vec3& inttersectionPoint_t);
+	static bool test_ray_sphere(const Ray& r, const Sphere& s, real& distance, Vec3& intersectionPoint);
+	static bool test_ray_box(const Ray& r, const Box& b, real& distance, Vec3& intersectionPoint);
+	static bool test_ray_triangle(const Ray& r, const Triangle& t, real& distance, Vec3& intersectionPoint);
 
-	static bool TestPlane3(const Plane& p1, const Plane& p2, const Plane& p3, Vec3& ip);
+	static bool test_plane_3(const Plane& p1, const Plane& p2, const Plane& p3, Vec3& ip);
 
-	static bool TestStaticSpherePlane(const Sphere& s, const Plane& p);
-	static bool TestStaticSphereSphere(const Sphere& a, const Sphere& b);
-	static bool TestDynamicSpherePlane(const Sphere& s, const Vec3& d, const Plane& p, real& it, Vec3& intersectionPoint);
-	static bool TestDynamicSphereTriangle(const Sphere& s, const Vec3& d, const Triangle& tri, real& it, Vec3& intersectionPoint);
-	static bool TestDynamicSphereSphere(const Sphere& s1, const Vec3& d1, const Sphere& s2, const Vec3& d2, real& it, Vec3& intersectionPoint);
+	static bool test_static_sphere_plane(const Sphere& s, const Plane& p);
+	static bool test_static_sphere_sphere(const Sphere& a, const Sphere& b);
+	static bool test_dynamic_sphere_plane(const Sphere& s, const Vec3& d, const Plane& p, real& it, Vec3& intersectionPoint);
+	static bool test_dynamic_sphere_triangle(const Sphere& s, const Vec3& d, const Triangle& tri, real& it, Vec3& intersectionPoint);
+	static bool test_dynamic_sphere_sphere(const Sphere& s1, const Vec3& d1, const Sphere& s2, const Vec3& d2, real& it, Vec3& intersectionPoint);
 
-	static bool TestStaticBoxBox(const Box& b1, const Box& b2);
-	static bool TestDynamicBoxBox(const Box& b1, const Vec3& v1, const Box& b2, const Vec3& v2, real& it);
+	static bool test_static_box_box(const Box& b1, const Box& b2);
+	static bool test_dynamic_box_box(const Box& b1, const Vec3& v1, const Box& b2, const Vec3& v2, real& it);
 
-	static bool TestFrustumSphere(const Frustum& f, const Sphere& s);
-	static bool TestFrustumBox(const Frustum& f, const Box& box);
+	static bool test_frustum_sphere(const Frustum& f, const Sphere& s);
+	static bool test_frustum_box(const Frustum& f, const Box& box);
 
-	static bool TestCircleCircle(const Circle& c1, const Circle& c2, Vec2& penetration);
-	static bool TestDynamicCircleCircle(const Circle& c1, const Vec2& d1, const Circle& c2, const Vec2& d2, real& it);
-	static bool TestRectRect(const Rect& r1, const Rect& r2, Vec2& penetration);
-	static bool TestCircleRect(const Circle& c1, const Rect& r2, Vec2& penetration);
+	static bool test_circle_circle(const Circle& c1, const Circle& c2, Vec2& penetration);
+	static bool test_dynamic_circle_circle(const Circle& c1, const Vec2& d1, const Circle& c2, const Vec2& d2, real& it);
+	static bool test_rect_rect(const Rect& r1, const Rect& r2, Vec2& penetration);
+	static bool test_circle_rect(const Circle& c1, const Rect& r2, Vec2& penetration);
 
 private:
 
@@ -119,7 +112,7 @@ private:
 };
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestRayPlane(const Ray& r, const Plane& p, real& distance, Vec3& intersectionPoint)
+inline bool Intersection::test_ray_plane(const Ray& r, const Plane& p, real& distance, Vec3& intersectionPoint)
 {
 	real nd = r.direction().dot(p.n);
 	real orpn = r.origin().dot(p.n);
@@ -139,7 +132,7 @@ inline bool Intersection::TestRayPlane(const Ray& r, const Plane& p, real& dista
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestRaySphere(const Ray& r, const Sphere& s, real& distance, Vec3& intersectionPoint)
+inline bool Intersection::test_ray_sphere(const Ray& r, const Sphere& s, real& distance, Vec3& intersectionPoint)
 {
 	Vec3 v = s.center() - r.origin();
 	real b = v.dot(r.direction());
@@ -157,7 +150,7 @@ inline bool Intersection::TestRaySphere(const Ray& r, const Sphere& s, real& dis
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestRayBox(const Ray& r, const Box& b, real& /*distance*/, Vec3& /*intersectionPoint*/)
+inline bool Intersection::test_ray_box(const Ray& r, const Box& b, real& /*distance*/, Vec3& /*intersectionPoint*/)
 {
 	if (r.origin().x < b.min().x)
 	{
@@ -214,9 +207,9 @@ inline bool Intersection::TestRayBox(const Ray& r, const Box& b, real& /*distanc
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestRayTriangle(const Ray& r, const Triangle& t, real& distance, Vec3& intersectionPoint)
+inline bool Intersection::test_ray_triangle(const Ray& r, const Triangle& t, real& distance, Vec3& intersectionPoint)
 {
-	if (Intersection::TestRayPlane(r, t.to_plane(), distance, intersectionPoint))
+	if (Intersection::test_ray_plane(r, t.to_plane(), distance, intersectionPoint))
 	{
 		if (t.contains_point(intersectionPoint))
 		{
@@ -228,7 +221,7 @@ inline bool Intersection::TestRayTriangle(const Ray& r, const Triangle& t, real&
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestPlane3(const Plane& p1, const Plane& p2, const Plane& p3, Vec3& ip)
+inline bool Intersection::test_plane_3(const Plane& p1, const Plane& p2, const Plane& p3, Vec3& ip)
 {
 	const Vec3& n1 = p1.n;
 	const Vec3& n2 = p2.n;
@@ -248,7 +241,7 @@ inline bool Intersection::TestPlane3(const Plane& p1, const Plane& p2, const Pla
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestStaticSpherePlane(const Sphere& s, const Plane& p)
+inline bool Intersection::test_static_sphere_plane(const Sphere& s, const Plane& p)
 {
 	if (math::abs(p.distance_to_point(s.center())) < s.radius())
 	{
@@ -259,14 +252,14 @@ inline bool Intersection::TestStaticSpherePlane(const Sphere& s, const Plane& p)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestStaticSphereSphere(const Sphere& a, const Sphere& b)
+inline bool Intersection::test_static_sphere_sphere(const Sphere& a, const Sphere& b)
 {
 	real dist = (b.center() - a.center()).squared_length();
 	return (dist < (b.radius() + a.radius()) * (b.radius() + a.radius()));
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestDynamicSpherePlane(const Sphere& s, const Vec3& d, const Plane& p, real& it, Vec3& intersectionPoint)
+inline bool Intersection::test_dynamic_sphere_plane(const Sphere& s, const Vec3& d, const Plane& p, real& it, Vec3& intersectionPoint)
 {
 	const Vec3& sphereCenter = s.center();
 	const real sphereRadius = s.radius();
@@ -314,13 +307,13 @@ inline bool Intersection::TestDynamicSpherePlane(const Sphere& s, const Vec3& d,
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestDynamicSphereTriangle(const Sphere& s, const Vec3& d, const Triangle& tri, real& it, Vec3& intersectionPoint)
+inline bool Intersection::test_dynamic_sphere_triangle(const Sphere& s, const Vec3& d, const Triangle& tri, real& it, Vec3& intersectionPoint)
 {
 	Plane triPlane = tri.to_plane();
 
 	// Test against the plane containing the triangle
 	real spherePlaneIt;
-	if (!TestDynamicSpherePlane(s, d, triPlane, spherePlaneIt, intersectionPoint))
+	if (!test_dynamic_sphere_plane(s, d, triPlane, spherePlaneIt, intersectionPoint))
 	{
 		return false;
 	}
@@ -329,7 +322,7 @@ inline bool Intersection::TestDynamicSphereTriangle(const Sphere& s, const Vec3&
 	if (tri.contains_point(intersectionPoint))
 	{
 		it = spherePlaneIt;
-		// intersectionPoint is already returned by the above call to TestDynamicSpherePlane
+		// intersectionPoint is already returned by the above call to test_dynamic_sphere_plane
 		return true;
 	}
 
@@ -464,7 +457,7 @@ inline bool Intersection::TestDynamicSphereTriangle(const Sphere& s, const Vec3&
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestDynamicSphereSphere(const Sphere& s1, const Vec3& d1, const Sphere& s2, const Vec3& d2, real& it, Vec3& /*intersectionPoint*/)
+inline bool Intersection::test_dynamic_sphere_sphere(const Sphere& s1, const Vec3& d1, const Sphere& s2, const Vec3& d2, real& it, Vec3& /*intersectionPoint*/)
 {
 	// s1 == static sphere
 	// s2 == moving sphere
@@ -508,7 +501,7 @@ inline bool Intersection::TestDynamicSphereSphere(const Sphere& s1, const Vec3&
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestStaticBoxBox(const Box& b1, const Box& b2)
+inline bool Intersection::test_static_box_box(const Box& b1, const Box& b2)
 {
 	if (b1.min().x > b2.max().x || b1.max().x < b2.min().x)
 	{
@@ -529,7 +522,7 @@ inline bool Intersection::TestStaticBoxBox(const Box& b1, const Box& b2)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestDynamicBoxBox(const Box& b1, const Vec3& v1, const Box& b2, const Vec3& v2, real& it)
+inline bool Intersection::test_dynamic_box_box(const Box& b1, const Vec3& v1, const Box& b2, const Vec3& v2, real& it)
 {
 	// b1 == static box
 	// b2 == moving box
@@ -610,7 +603,7 @@ inline bool Intersection::TestDynamicBoxBox(const Box& b1, const Vec3& v1, const
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestFrustumSphere(const Frustum& f, const Sphere& s)
+inline bool Intersection::test_frustum_sphere(const Frustum& f, const Sphere& s)
 {
 	if (f.m_planes[0].distance_to_point(s.center()) < -s.radius() || f.m_planes[1].distance_to_point(s.center()) < -s.radius())
 	{
@@ -631,7 +624,7 @@ inline bool Intersection::TestFrustumSphere(const Frustum& f, const Sphere& s)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestFrustumBox(const Frustum& f, const Box& b)
+inline bool Intersection::test_frustum_box(const Frustum& f, const Box& b)
 {
 	uint32_t vertexOutCount;
 
@@ -659,7 +652,7 @@ inline bool Intersection::TestFrustumBox(const Frustum& f, const Box& b)
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestCircleCircle(const Circle& c1, const Circle& c2, Vec2& penetration)
+inline bool Intersection::test_circle_circle(const Circle& c1, const Circle& c2, Vec2& penetration)
 {
 	Vec2 distance = c1.center() - c2.center();
 	real distanceLen2 = distance.squared_length();
@@ -682,7 +675,7 @@ inline bool Intersection::TestCircleCircle(const Circle& c1, const Circle& c2, V
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestDynamicCircleCircle(const Circle& c1, const Vec2& d1, const Circle& c2, const Vec2& d2, real& it)
+inline bool Intersection::test_dynamic_circle_circle(const Circle& c1, const Vec2& d1, const Circle& c2, const Vec2& d2, real& it)
 {
 	// c1 == static circle
 	// c2 == moving circle
@@ -726,7 +719,7 @@ inline bool Intersection::TestDynamicCircleCircle(const Circle& c1, const Vec2&
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestRectRect(const Rect& r1, const Rect& r2, Vec2& penetration)
+inline bool Intersection::test_rect_rect(const Rect& r1, const Rect& r2, Vec2& penetration)
 {
 	//x
 	real min1MinusMax2 = r1.min().x - r2.max().x;
@@ -783,7 +776,7 @@ inline bool Intersection::TestRectRect(const Rect& r1, const Rect& r2, Vec2& pen
 }
 
 //-----------------------------------------------------------------------------
-inline bool Intersection::TestCircleRect(const Circle& c1, const Rect& r2, Vec2& penetration)
+inline bool Intersection::test_circle_rect(const Circle& c1, const Rect& r2, Vec2& penetration)
 {
 	bool circleIsAtRight;
 	if (c1.center().x > (r2.min().x + r2.max().x) / 2)

+ 10 - 25
src/renderers/gles/GLESIndexBuffer.h → src/input/Accelerometer.cpp

@@ -23,36 +23,21 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#pragma once
-
-#include "IndexBuffer.h"
-#include "Types.h"
-#include <GLES/gl.h>
+#include "Accelerometer.h"
 
 namespace crown
 {
 
-class GLESIndexBuffer: public IndexBuffer
+//-----------------------------------------------------------------------------
+Accelerometer::Accelerometer() :
+	m_orientation(0.0f, 0.0f, 0.0f)
 {
+}
 
-public:
-
-				GLESIndexBuffer();
-				~GLESIndexBuffer();
-
-	void		SetIndexData(const uint16_t* indexData, uint32_t indexCount);
-	void		SetIndexSubData(const uint16_t* indexData, uint32_t indexOffset, uint32_t indexCount);
-
-	uint32_t	GetIndexCount() const { return mCount; }
-
-	void		Bind() const;
-	void		Unbind() const;
-
-private:
-	
-	GLuint		mBufferID;
-	GLuint		mCount;
-};
-
+//-----------------------------------------------------------------------------
+const Vec3& Accelerometer::orientation() const
+{
+	return m_orientation;
 }
 
+} // namespace crown

+ 37 - 5
src/input/Accelerometer.h

@@ -1,5 +1,33 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
 #pragma once
 
+#include "Types.h"
+#include "Vec3.h"
+
 namespace crown
 {
 
@@ -15,22 +43,26 @@ struct AccelerometerEvent
 class AccelerometerListener
 {
 public:
+
 	virtual void accelerometer_changed(const AccelerometerEvent& event) { (void)event; }
 };
 
+/// Interface for accessing accelerometer input device.
 class Accelerometer
 {
 public:
 	
-	Accelerometer() : m_listener(NULL) {}
+					Accelerometer();
 
-	virtual ~Accelerometer() {}
-
-	inline void set_listener(AccelerometerListener* listener) { m_listener = listener; }
+	/// Returns the orientation of the accelerometer.
+	/// FIXME NEED MORE DOCUMENTATION
+	const Vec3&		orientation() const;
 
 private:
 
-	AccelerometerListener* m_listener;
+	Vec3			m_orientation;
+
+	friend class	InputManager;
 };
 
 } // namespace crown

+ 88 - 45
src/input/InputManager.cpp

@@ -41,6 +41,60 @@ InputManager::~InputManager()
 {
 }
 
+//-----------------------------------------------------------------------------
+Keyboard* InputManager::keyboard()
+{
+	return &m_keyboard;
+}
+
+//-----------------------------------------------------------------------------
+Mouse* InputManager::mouse()
+{
+	return &m_mouse;
+}
+
+//-----------------------------------------------------------------------------
+Touch* InputManager::touch()
+{
+	return &m_touch;
+}
+
+//-----------------------------------------------------------------------------
+Accelerometer* InputManager::accelerometer()
+{
+	return &m_accelerometer;
+}
+
+//-----------------------------------------------------------------------------
+void InputManager::register_mouse_listener(MouseListener* listener)
+{
+	m_event_dispatcher.add_mouse_listener(listener);
+}
+
+//-----------------------------------------------------------------------------
+void InputManager::register_keyboard_listener(KeyboardListener* listener)
+{
+	m_event_dispatcher.add_keyboard_listener(listener);
+}
+
+//-----------------------------------------------------------------------------
+void InputManager::register_touch_listener(TouchListener* listener)
+{
+	m_event_dispatcher.add_touch_listener(listener);
+}
+
+//-----------------------------------------------------------------------------
+void InputManager::register_accelerometer_listener(AccelerometerListener* listener)
+{
+	m_event_dispatcher.add_accelerometer_listener(listener);
+}
+
+//-----------------------------------------------------------------------------
+EventDispatcher* InputManager::get_event_dispatcher()
+{
+	return &m_event_dispatcher;
+}
+
 //-----------------------------------------------------------------------------
 void InputManager::event_loop()
 {
@@ -67,10 +121,12 @@ void InputManager::event_loop()
 
 				if (event.type == os::OSET_BUTTON_PRESS)
 				{
+					m_mouse.m_buttons[mouse_event.button] = true;
 					m_event_dispatcher.button_pressed(mouse_event);
 				}
 				else
 				{
+					m_mouse.m_buttons[mouse_event.button] = false;
 					m_event_dispatcher.button_released(mouse_event);
 				}
 
@@ -81,13 +137,18 @@ void InputManager::event_loop()
 			{
 				KeyboardEvent keyboard_event;
 				keyboard_event.key = event.data_a.int_value;
+				keyboard_event.modifier = (uint8_t)event.data_b.int_value;
+
+				m_keyboard.m_modifier = keyboard_event.modifier;
 
 				if (event.type == os::OSET_KEY_PRESS)
 				{
+					m_keyboard.m_keys[keyboard_event.key] = true;
 					m_event_dispatcher.key_pressed(keyboard_event);
 				}
 				else
 				{
+					m_keyboard.m_keys[keyboard_event.key] = false;
 					m_event_dispatcher.key_released(keyboard_event);
 				}
 
@@ -100,14 +161,25 @@ void InputManager::event_loop()
 				touch_event.pointer_id = event.data_a.int_value;
 				touch_event.x = event.data_b.int_value;
 				touch_event.y = event.data_c.int_value;
+
+				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
+				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
+
+				// FIXME
+				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
+				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
+
 				if (event.type == os::OSET_TOUCH_DOWN)
 				{
+					m_touch.m_pointers[touch_event.pointer_id].up = false;
 					m_event_dispatcher.touch_down(touch_event);
 				}
 				else
 				{
+					m_touch.m_pointers[touch_event.pointer_id].up = true;
 					m_event_dispatcher.touch_up(touch_event);
 				}
+
 				break;
 			}
 			case os::OSET_TOUCH_MOVE:
@@ -115,8 +187,17 @@ void InputManager::event_loop()
 				TouchEvent touch_event;
 				touch_event.pointer_id = event.data_a.int_value;
 				touch_event.x = event.data_b.int_value;
-				touch_event.y = event.data_c.int_value;	
-				m_event_dispatcher.touch_move(touch_event);			
+				touch_event.y = event.data_c.int_value;
+
+				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
+				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
+
+				// FIXME
+				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
+				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
+
+				m_event_dispatcher.touch_move(touch_event);
+
 				break;
 			}
 			case os::OSET_ACCELEROMETER:
@@ -125,6 +206,11 @@ void InputManager::event_loop()
 				sensor_event.x = event.data_a.float_value;
 				sensor_event.y = event.data_b.float_value;
 				sensor_event.z = event.data_c.float_value;
+
+				m_accelerometer.m_orientation.x = sensor_event.x;
+				m_accelerometer.m_orientation.y = sensor_event.y;
+				m_accelerometer.m_orientation.z = sensor_event.z;
+
 				m_event_dispatcher.accelerometer_changed(sensor_event);
 				break;
 			}
@@ -157,48 +243,5 @@ void InputManager::set_cursor_visible(bool visible)
 	m_cursor_visible = visible;
 }
 
-//-----------------------------------------------------------------------------
-Point2 InputManager::get_cursor_xy() const
-{
-	Point2 xy;
-
-	os::get_cursor_xy(xy.x, xy.y);
-
-	return xy;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::set_cursor_xy(const Point2& position)
-{
-	os::set_cursor_xy(position.x, position.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 InputManager::get_cursor_relative_xy() const
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	os::get_render_window_metrics(window_width, window_height);
-
-	Vec2 pos = get_cursor_xy().to_vec2();
-
-	pos.x = pos.x / (float) window_width;
-	pos.y = pos.y / (float) window_height;
-
-	return pos;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::set_cursor_relative_xy(const Vec2& position)
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	os::get_render_window_metrics(window_width, window_height);
-
-	set_cursor_xy(Point2((int32_t)(position.x * (float) window_width), (int32_t)(position.y * (float) window_height)));
-}
-
 } // namespace crown
 

+ 31 - 92
src/input/InputManager.h

@@ -26,9 +26,10 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "EventDispatcher.h"
-#include "Point2.h"
-#include "Vec2.h"
-#include "Log.h"
+#include "Mouse.h"
+#include "Keyboard.h"
+#include "Touch.h"
+#include "Accelerometer.h"
 
 namespace crown
 {
@@ -39,102 +40,40 @@ class TouchListener;
 
 class InputManager
 {
-
 public:
 
-	InputManager();
-	~InputManager();
-
-	//! Initializes the input manager.
-	void init();
-
-	bool is_mouse_available() { return true; }
-	bool is_keyboard_available() { return true; }
-	bool is_touch_available() { return true; }
-	bool is_accelerometer_available() { return true; }
-
-
-	inline void register_mouse_listener(MouseListener* listener)
-	{
-		m_event_dispatcher.add_mouse_listener(listener);
-	}
-
-	inline void register_keyboard_listener(KeyboardListener* listener)
-	{
-		m_event_dispatcher.add_keyboard_listener(listener);
-	}
-
-	inline void register_touch_listener(TouchListener* listener)
-	{
-		m_event_dispatcher.add_touch_listener(listener);
-	}
-
-	inline void register_accelerometer_listener(AccelerometerListener* listener)
-	{
-		m_event_dispatcher.add_accelerometer_listener(listener);
-	}
-
-	inline EventDispatcher* get_event_dispatcher()
-	{
-		return &m_event_dispatcher;
-	}
-
-	void event_loop();
-
-	//! Returns whether the cursor is visible.
-	bool is_cursor_visible() const;
-
-	//! Sets whether the cursor is visible.
-	void set_cursor_visible(bool visible);
-
-	/**
-		Returns the position of the cursor in window space.
-	@note
-		Coordinates in window space have the origin at the
-		upper-left corner of the window. +X extends from left
-		to right and +Y extends from top to bottom.
-	*/
-	Point2 get_cursor_xy() const;
-
-	/**
-		Sets the position of the cursor in window space.
-	@note
-		Coordinates in window space have the origin at the
-		upper-left corner of the window. +X extends from left
-		to right and +Y extends from top to bottom.
-	*/
-	void set_cursor_xy(const Point2& position);
-
-	/**
-		Returns the relative position of the cursor in window space.
-	@note
-		Coordinates in window space have the origin at the
-		upper-left corner of the window. +X extends from left
-		to right and +Y extends from top to bottom.
-	@note
-		Relative coordinates are mapped to a real varying
-		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
-		maximum extent of the cosidered axis.
-	*/
-	Vec2 get_cursor_relative_xy() const;
-
-	/**
-		Sets the relative position of the cursor in window space.
-	@note
-		Coordinates in window space have the origin at the
-		upper-left corner of the window. +X extends from left
-		to right and +Y extends from top to bottom.
-	@note
-		Relative coordinates are mapped to a real varying
-		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
-		maximum extent of the cosidered axis.
-	*/
-	void set_cursor_relative_xy(const Vec2& position);
+						InputManager();
+						~InputManager();
+
+	Keyboard*			keyboard();
+	Mouse*				mouse();
+	Touch*				touch();
+	Accelerometer*		accelerometer();
+
+	void				register_mouse_listener(MouseListener* listener);
+	void				register_keyboard_listener(KeyboardListener* listener);
+	void				register_touch_listener(TouchListener* listener);
+	void				register_accelerometer_listener(AccelerometerListener* listener);
+
+	EventDispatcher*	get_event_dispatcher();
+
+	/// Returns whether the cursor is visible.
+	bool				is_cursor_visible() const;
+
+	/// Sets whether the cursor is visible.
+	void				set_cursor_visible(bool visible);
+
+	void				event_loop();
 
 private:
 
 	EventDispatcher		m_event_dispatcher;
 
+	Keyboard			m_keyboard;
+	Mouse				m_mouse;
+	Touch				m_touch;
+	Accelerometer		m_accelerometer;
+
 	bool				m_cursor_visible;
 };
 

+ 75 - 9
src/input/KeyCode.h

@@ -28,10 +28,12 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/**
-	A KeyCode is the number which uniquely identifies a key
-	on the keyboard.
-*/
+const uint16_t MAX_KEYCODES = 256;
+
+typedef uint8_t Key;
+
+/// A KeyCode is the number which uniquely identifies a key
+/// on the keyboard.
 enum KeyCode
 {
 	KC_NOKEY		= 0x00,
@@ -89,12 +91,76 @@ enum KeyCode
 	KC_RSUPER		= 0xB8,
 
 	/* [0x30, 0x39] reserved for ASCII digits */
-	/* [0x41, 0x5A] and [0x61, 0x7A] reserved for ASCII alphabet */
-
-	KC_COUNT		= 0xFF		// The last key must be <= 0xFF
+	KC_0			= 0x30,
+	KC_1			= 0x31,
+	KC_2			= 0x32,
+	KC_3			= 0x33,
+	KC_4			= 0x34,
+	KC_5			= 0x35,
+	KC_6			= 0x36,
+	KC_7			= 0x37,
+	KC_8			= 0x38,
+	KC_9			= 0x39,
+
+	/* [0x41, 0x5A] reserved for ASCII alphabet */
+	KC_A			= 0x41,
+	KC_B			= 0x42,
+	KC_C			= 0x43,
+	KC_D			= 0x44,
+	KC_E			= 0x45,
+	KC_F			= 0x46,
+	KC_G			= 0x47,
+	KC_H			= 0x48,
+	KC_I			= 0x49,
+	KC_J			= 0x4A,
+	KC_K			= 0x4B,
+	KC_L			= 0x4C,
+	KC_M			= 0x4D,
+	KC_N			= 0x4E,
+	KC_O			= 0x4F,
+	KC_P			= 0x50,
+	KC_Q			= 0x51,
+	KC_R			= 0x52,
+	KC_S			= 0x53,
+	KC_T			= 0x54,
+	KC_U			= 0x55,
+	KC_V			= 0x56,
+	KC_W			= 0x57,
+	KC_X			= 0x58,
+	KC_Y			= 0x59,
+	KC_Z			= 0x5A,
+
+	/* [0x61, 0x7A] reserved for ASCII alphabet */
+	KC_a			= 0x61,
+	KC_b			= 0x62,
+	KC_c			= 0x63,
+	KC_d			= 0x64,
+	KC_e			= 0x65,
+	KC_f			= 0x66,
+	KC_g			= 0x67,
+	KC_h			= 0x68,
+	KC_i			= 0x69,
+	KC_j			= 0x6A,
+	KC_k			= 0x6B,
+	KC_l			= 0x6C,
+	KC_m			= 0x6D,
+	KC_n			= 0x6E,
+	KC_o			= 0x6F,
+	KC_p			= 0x70,
+	KC_q			= 0x71,
+	KC_r			= 0x72,
+	KC_s			= 0x73,
+	KC_t			= 0x74,
+	KC_u			= 0x75,
+	KC_v			= 0x76,
+	KC_w			= 0x77,
+	KC_x			= 0x78,
+	KC_y			= 0x79,
+	KC_z			= 0x7A,
+
+	// The last key _must_ be <= 0xFF
+	KC_COUNT		= 0xFF
 };
 
-typedef uint8_t Key;
-
 } // namespace crown
 

+ 24 - 32
src/EventBuffer.h → src/input/Keyboard.cpp

@@ -23,44 +23,36 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#pragma once
-
-#include "Types.h"
-
-#define MAX_EVENT_QUEUE_SIZE 64 * 1024
+#include "Keyboard.h"
 
 namespace crown
 {
 
-/**
-	Buffer of variable-lenght events.
-
-	[type1][size1][struct1][type2][size2][struct2]...
-*/
-class EventBuffer
+//-----------------------------------------------------------------------------
+Keyboard::Keyboard()
 {
+	for (uint32_t i = 0; i < MAX_KEYCODES; i++)
+	{
+		m_keys[i] = false;
+	}
+}
+
+//-----------------------------------------------------------------------------
+bool Keyboard::modifier_pressed(ModifierKey modifier) const
+{
+	return (m_modifier & modifier) == modifier;
+}
 
-public:
-
-				EventBuffer();
-				~EventBuffer();
-
-	void		PushEvent(uint32_t eventType, void* eventData, size_t eventSize);
-	void		PushEventBuffer(uint8_t* eventBuffer, size_t bufferSize);
-
-	void*		NextEvent(uint32_t& eventType, size_t& size);
-
-	void		Clear();
-	void		Flush();
-
-	size_t		GetSize() const;
-	uint8_t*		GetBuffer();
-
-public:
+//-----------------------------------------------------------------------------
+bool Keyboard::key_pressed(KeyCode key) const
+{
+	return m_keys[key] == true;
+}
 
-	size_t		mBufferCount;					// Number of bytes in the buffer
-	uint8_t		mBuffer[MAX_EVENT_QUEUE_SIZE];
-};
+//-----------------------------------------------------------------------------
+bool Keyboard::key_released(KeyCode key) const
+{
+	return m_keys[key] == false;
+}
 
 } // namespace crown
-

+ 30 - 48
src/input/Keyboard.h

@@ -28,16 +28,13 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "KeyCode.h"
 
-#define MAX_KEYCODES 256
-
 namespace crown
 {
 
 class InputManager;
 
-/**
-	Enumerates modifier keys.
-*/
+
+/// Enumerates modifier keys.
 enum ModifierKey
 {
 	MK_SHIFT	= 1,
@@ -47,8 +44,9 @@ enum ModifierKey
 
 struct KeyboardEvent
 {
-	Key key;
-	char text[4];
+	Key			key;
+	uint8_t		modifier;
+	char		text[4];
 };
 
 class KeyboardListener
@@ -61,51 +59,35 @@ public:
 	virtual void text_input(const KeyboardEvent& event) { (void)event; }
 };
 
-/**
-	Interface for accessing keyboard input device.
-*/
+/// Interface for accessing keyboard input device.
 class Keyboard
 {
-
 public:
 
-	/**
-		Constructor.
-	*/
-	Keyboard() : m_listener(NULL) {}
-
-	/**
-		Destructor.
-	*/
-	virtual ~Keyboard() {}
-
-	/**
-		Returns whether the specified modifier is pressed.
-	@note
-		A modifier is a special key that modifies the normal action
-		of another key when the two are pressed in combination. (Thanks wikipedia.)
-		Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
-	*/
-	virtual bool is_modifier_pressed(ModifierKey modifier) const = 0;
-
-	/**
-		Returns whether the specified key is pressed.
-	*/
-	virtual bool is_key_pressed(KeyCode key) const = 0;
-
-	/**
-		Returns whether the specified key is released.
-	*/
-	virtual bool is_key_released(KeyCode key) const = 0;
-
-	/**
-		Sets the listener for this device.
-	*/
-	inline void set_listener(KeyboardListener* listener) { m_listener = listener; }
-
-protected:
-
-	KeyboardListener* m_listener;
+					Keyboard();
+
+	/// Returns whether the specified @modifier is pressed.
+	/// @note
+	/// A modifier is a special key that modifies the normal action
+	/// of another key when the two are pressed in combination. (Thanks wikipedia.)
+	/// @note
+	/// Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
+	bool			modifier_pressed(ModifierKey modifier) const;
+
+	/// Returns whether the specified @key is pressed.
+	bool			key_pressed(KeyCode key) const;
+
+	/// Returns whether the specified @key is released.
+	bool			key_released(KeyCode key) const;
+
+private:
+
+	uint8_t			m_modifier;
+
+	// True if key pressed, false otherwise.
+	bool			m_keys[MAX_KEYCODES];
+
+	friend class	InputManager;
 };
 
 } // namespace crown

+ 95 - 0
src/input/Mouse.cpp

@@ -0,0 +1,95 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Mouse.h"
+#include "OS.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+Mouse::Mouse()
+{
+	m_buttons[MB_LEFT] = false;
+	m_buttons[MB_MIDDLE] = false;
+	m_buttons[MB_RIGHT] = false;
+}
+
+//-----------------------------------------------------------------------------
+bool Mouse::button_pressed(MouseButton button) const
+{
+	return m_buttons[button] == true;
+}
+
+//-----------------------------------------------------------------------------
+bool Mouse::button_released(MouseButton button) const
+{
+	return m_buttons[button] == false;
+}
+
+//-----------------------------------------------------------------------------
+Point2 Mouse::cursor_xy() const
+{
+	Point2 xy;
+
+	os::get_cursor_xy(xy.x, xy.y);
+
+	return xy;
+}
+
+//-----------------------------------------------------------------------------
+void Mouse::set_cursor_xy(const Point2& position)
+{
+	os::set_cursor_xy(position.x, position.y);
+}
+
+//-----------------------------------------------------------------------------
+Vec2 Mouse::cursor_relative_xy() const
+{
+	uint32_t window_width;
+	uint32_t window_height;
+
+	os::get_render_window_metrics(window_width, window_height);
+
+	Vec2 pos = cursor_xy().to_vec2();
+
+	pos.x = pos.x / (float) window_width;
+	pos.y = pos.y / (float) window_height;
+
+	return pos;
+}
+
+//-----------------------------------------------------------------------------
+void Mouse::set_cursor_relative_xy(const Vec2& position)
+{
+	uint32_t window_width;
+	uint32_t window_height;
+
+	os::get_render_window_metrics(window_width, window_height);
+
+	set_cursor_xy(Point2((int32_t)(position.x * (float) window_width), (int32_t)(position.y * (float) window_height)));
+}
+
+} // namespace crown

+ 63 - 7
src/input/Mouse.h

@@ -26,15 +26,15 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
+#include "Vec2.h"
+#include "Point2.h"
 
 namespace crown
 {
 
-class InputManager;
+const uint32_t MAX_MOUSE_BUTTONS = 3;
 
-/**
-	Enumerates mouse buttons.
-*/
+/// Enumerates mouse buttons.
 enum MouseButton
 {
 	MB_LEFT		= 0,
@@ -50,9 +50,7 @@ struct MouseEvent
 	float wheel;
 };
 
-/**
-	Interface for managing mouse input
-*/
+/// Interface for managing mouse input.
 class MouseListener
 {
 
@@ -63,5 +61,63 @@ public:
 	virtual void cursor_moved(const MouseEvent& event) { (void)event; }
 };
 
+/// Interface for accessing mouse input device.
+class Mouse
+{
+public:
+
+			Mouse();
+
+
+	/// Returns whether @button is pressed.
+	bool	button_pressed(MouseButton button) const;
+
+	/// Returns whether @button is released.
+	bool	button_released(MouseButton button) const;
+
+	/// Returns the position of the cursor in window space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	Point2	cursor_xy() const;
+
+	/// Sets the position of the cursor in window space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	void	set_cursor_xy(const Point2& position);
+
+	/// Returns the relative position of the cursor in window space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	/// @note
+	/// Relative coordinates are mapped to a real varying
+	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
+	/// maximum extent of the cosidered axis.
+	Vec2	cursor_relative_xy() const;
+
+	/// Sets the relative position of the cursor in window space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	/// @note
+	/// Relative coordinates are mapped to a real varying
+	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
+	/// maximum extent of the cosidered axis.
+	void	set_cursor_relative_xy(const Vec2& position);
+
+private:
+
+	// True if correspondig button is pressed, false otherwise.
+	bool	m_buttons[MAX_MOUSE_BUTTONS];
+
+	friend class	InputManager;
+};
+
 } // namespace crown
 

+ 26 - 20
src/renderers/gles/GLESVertexBuffer.h → src/input/Touch.cpp

@@ -23,37 +23,43 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#pragma once
-
-#include "VertexBuffer.h"
-#include <GLES/gl.h>
+#include "Touch.h"
 
 namespace crown
 {
 
-class GLESVertexBuffer: public VertexBuffer
+//-----------------------------------------------------------------------------
+Touch::Touch()
 {
 
-public:
+}
 
-	GLESVertexBuffer();
-	~GLESVertexBuffer();
+//-----------------------------------------------------------------------------
+bool Touch::touch_up(uint16_t id) const
+{
+	return m_pointers[id].up == true;
+}
 
-	void		SetVertexData(VertexBufferMode mode, const void* vertexData, uint32_t vertexCount);
-	void		SetVertexSubData(const void* vertexData, uint32_t vertexOffset, uint32_t vertexCount);
+//-----------------------------------------------------------------------------
+bool Touch::touch_down(uint16_t id) const
+{
+	return m_pointers[id].up == false;
+}
 
-	uint32_t	GetSize() const;
-	uint32_t	GetVertexCount() const;
+//----------------------------------------------------------------------------- 
+Point2 Touch::touch_xy(uint16_t id) const
+{
+	const PointerData& data = m_pointers[id];
 
-	void		Bind() const;
-	void		Unbind() const;
+	return Point2(data.x, data.y);
+}
 
-private:
-	
-	GLuint		mBufferID;
-	GLuint		mSize;
-	GLuint		mVertexCount;
-};
+//-----------------------------------------------------------------------------
+Vec2 Touch::touch_relative_xy(uint16_t id)
+{
+	const PointerData& data = m_pointers[id];
 
+	return Vec2(data.relative_x, data.relative_y);
 }
 
+} // namespace crown

+ 46 - 27
src/input/Touch.h

@@ -25,21 +25,32 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #pragma once
 
+#include "Types.h"
+#include "Vec2.h"
+#include "Point2.h"
+
 namespace crown
 {
 
-class InputManager;
+const uint32_t MAX_POINTER_IDS = 4;
+
+struct PointerData
+{
+	uint32_t	x;
+	uint32_t	y;
+	float		relative_x;
+	float		relative_y;
+	bool		up;
+};
 
 struct TouchEvent
 {
-	int32_t pointer_id;
-	int32_t x;
-	int32_t y;
+	uint32_t	pointer_id;
+	uint32_t	x;
+	uint32_t	y;
 };
 
-/**
-	Interface for managing touch input device.	
-*/
+/// Interface for managing touch input device.
 class TouchListener
 {
 
@@ -51,34 +62,42 @@ public:
 	virtual void touch_cancel(const TouchEvent& event) { (void)event; }
 };
 
-/**
-	Interface for accessing touch input device.
-*/
+/// Interface for accessing touch input device.
 class Touch
 {
-
 public:
 
-	/**
-		Constructor.
-	*/
-	Touch() : m_listener(NULL) {}
+					Touch();
+
+	/// Returns whether the touch pointer @id is up.
+	bool			touch_up(uint16_t id) const;
+
+	/// Returns whether the touch pointer @id is down.
+	bool			touch_down(uint16_t id) const;
+
+	/// Returns the position of the pointer @id in windows space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	Point2			touch_xy(uint16_t id) const;
 
-	/**
-		Destructor.
-	*/
-	virtual ~Touch() {}
+	/// Returns the relative position of the pointer @id in window space.
+	/// @note
+	/// Coordinates in window space have the origin at the
+	/// upper-left corner of the window. +X extends from left
+	/// to right and +Y extends from top to bottom.
+	/// @note
+	/// Relative coordinates are mapped to a real varying
+	/// from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
+	/// maximum extent of the cosidered axis.
+	Vec2			touch_relative_xy(uint16_t id);
 
-	/**
-		Sets the listener for this device.
-	@param listener
-		The listener
-	*/
-	inline void set_listener(TouchListener* listener) { m_listener = listener; }
+private:
 
-protected:
+	PointerData		m_pointers[MAX_POINTER_IDS];
 
-	TouchListener* m_listener;
+	friend class	InputManager;
 };
 
 }

+ 14 - 2
src/os/linux/GLXRenderWindow.cpp

@@ -41,6 +41,10 @@ Display*		display = NULL;
 Window			window = None;
 GLXContext		glx_context = NULL;
 GLXDrawable		glx_window = None;
+uint32_t		window_x = 0;
+uint32_t		window_y = 0;
+uint32_t		window_width = 0;
+uint32_t		window_height = 0;
 
 //-----------------------------------------------------------------------------
 bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t height, bool fullscreen)
@@ -135,6 +139,11 @@ bool create_render_window(uint32_t x, uint32_t y, uint32_t width, uint32_t heigh
 	XFree(fbConfig);
 	XFlush(display);
 
+	window_x = x;
+	window_y = y;
+	window_width = width;
+	window_height = height;
+
 	return true;
 }
 
@@ -179,8 +188,11 @@ void get_render_window_metrics(uint32_t& width, uint32_t& height)
 
 	XFlush(display);
 
-	width = attribs.width;
-	height = attribs.height;
+	window_width = attribs.width;
+	window_height = attribs.height;
+
+	width = window_width;
+	height = window_height;
 }
 
 ////-----------------------------------------------------------------------------

+ 29 - 19
src/os/linux/Input.cpp

@@ -39,6 +39,10 @@ namespace os
 //-----------------------------------------------------------------------------
 extern Display*		display;
 extern Window		window;
+extern uint32_t		window_x;
+extern uint32_t		window_y;
+extern uint32_t		window_width;
+extern uint32_t		window_height;
 
 static bool			x11_detectable_autorepeat = false;
 static Cursor		x11_hidden_cursor = None;
@@ -180,12 +184,15 @@ void event_loop()
 
 		switch (event.type)
 		{
-//			case ConfigureNotify:
-//			{
-//				_NotifyMetricsChange(event.xconfigure.x, event.xconfigure.y,
-//										event.xconfigure.width, event.xconfigure.height);
-//				break;
-//			}
+			case ConfigureNotify:
+			{
+				window_x = event.xconfigure.x;
+				window_y = event.xconfigure.y;
+				window_width = event.xconfigure.width;
+				window_height = event.xconfigure.height;
+
+				break;
+			}
 			case ButtonPress:
 			case ButtonRelease:
 			{
@@ -234,23 +241,26 @@ void event_loop()
 
 				Key kc = x11_translate_key(key);
 
-//				// Check if any modifier key is pressed or released
-//				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_SHIFT : mModifierMask &= ~MK_SHIFT;
-//				}
-//				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_CTRL : mModifierMask &= ~MK_CTRL;
-//				}
-//				else if (kc == KC_LALT || kc == KC_RALT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_ALT : mModifierMask &= ~MK_ALT;
-//				}
+				// Check if any modifier key is pressed or released
+				int32_t modifier_mask = 0;
+
+				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_SHIFT : modifier_mask &= ~MK_SHIFT;
+				}
+				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_CTRL : modifier_mask &= ~MK_CTRL;
+				}
+				else if (kc == KC_LALT || kc == KC_RALT)
+				{
+					(event.type == KeyPress) ? modifier_mask |= MK_ALT : modifier_mask &= ~MK_ALT;
+				}
 
 				OSEventType oset_type = event.type == KeyPress ? OSET_KEY_PRESS : OSET_KEY_RELEASE;
 
 				data_key[0].int_value = ((int32_t)kc);
+				data_key[1].int_value = modifier_mask;
 
 				push_event(oset_type, data_key[0], data_key[1], data_key[2], data_key[3]);
 

+ 0 - 4
src/renderers/gles/CMakeLists.txt

@@ -3,15 +3,11 @@ cmake_minimum_required(VERSION 2.8)
 project(crown-gles)
 
 set (GLES_SRC
-	GLESIndexBuffer.cpp
-	GLESVertexBuffer.cpp
 	GLESRenderer.cpp
 	GLESUtils.cpp
 )
 
 set (GLES_HEADERS
-	GLESIndexBuffer.h
-	GLESVertexBuffer.h
 	GLESRenderer.h
 	GLESUtils.h
 )

+ 0 - 67
src/renderers/gles/GLESIndexBuffer.cpp

@@ -1,67 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "GLESIndexBuffer.h"
-
-namespace crown
-{
-
-//!Constructor
-GLESIndexBuffer::GLESIndexBuffer()
-{
-	glGenBuffers(1, &mBufferID);
-}
-
-//!Destructor
-GLESIndexBuffer::~GLESIndexBuffer()
-{
-	glDeleteBuffers(1, &mBufferID);
-}
-
-void GLESIndexBuffer::SetIndexData(const uint16_t* indexData, uint32_t indexCount)
-{
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferID);
-	glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexCount * sizeof(uint16_t), indexData, GL_DYNAMIC_DRAW);
-	mCount = indexCount;
-}
-
-void GLESIndexBuffer::SetIndexSubData(const uint16_t* indexData, uint32_t indexOffset, uint32_t indexCount)
-{
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferID);
-	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, indexOffset * sizeof(uint16_t), indexCount * sizeof(uint16_t), indexData);
-}
-
-void GLESIndexBuffer::Bind() const
-{
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferID);
-}
-
-void GLESIndexBuffer::Unbind() const
-{
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-}
-
-}
-

+ 17 - 21
src/renderers/gles/GLESUtils.h

@@ -34,23 +34,19 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/**
- * OpenGLES utilities.
- */
+/// OpenGL utilities for converting from wrapped names to GL names and vice-versa.
 class GLES
 {
-
 public:
 
-
-	static GLenum			GetCompareFunction(CompareFunction function);
-	static GLenum			GetBlendFunction(BlendFunction function);
-	static GLenum			GetTextureMode(TextureMode mode);
-	static GLenum			GetTextureWrap(TextureWrap wrap);
-	static void				GetTextureFilter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
-	static GLenum			GetFogMode(FogMode mode);
-	static GLenum			GetPixelFormat(PixelFormat format);
-	static PixelFormat		GetPixelFormatFromGLFormat(GLenum format);
+	static GLenum			compare_function(CompareFunction function);
+	static GLenum			blend_function(BlendFunction function);
+	static GLenum			texture_mode(TextureMode mode);
+	static GLenum			texture_wrap(TextureWrap wrap);
+	static void				texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter);
+	static GLenum			fog_mode(FogMode mode);
+	static GLenum			pixel_format(PixelFormat format);
+	static PixelFormat		pixel_format_from_gl_format(GLenum format);
 
 private:
 
@@ -67,7 +63,7 @@ private:
 };
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetCompareFunction(CompareFunction function)
+inline GLenum GLES::compare_function(CompareFunction function)
 {
 	assert(function < CF_COUNT);
 
@@ -75,7 +71,7 @@ inline GLenum GLES::GetCompareFunction(CompareFunction function)
 }
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetBlendFunction(BlendFunction function)
+inline GLenum GLES::blend_function(BlendFunction function)
 {
 	assert(function < BF_COUNT);
 
@@ -83,7 +79,7 @@ inline GLenum GLES::GetBlendFunction(BlendFunction function)
 }
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetTextureMode(TextureMode mode)
+inline GLenum GLES::texture_mode(TextureMode mode)
 {
 	assert(mode < TM_COUNT);
 
@@ -91,7 +87,7 @@ inline GLenum GLES::GetTextureMode(TextureMode mode)
 }
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetTextureWrap(TextureWrap wrap)
+inline GLenum GLES::texture_wrap(TextureWrap wrap)
 {
 	assert(wrap < TW_COUNT);
 
@@ -99,7 +95,7 @@ inline GLenum GLES::GetTextureWrap(TextureWrap wrap)
 }
 
 //-----------------------------------------------------------------------------
-inline void GLES::GetTextureFilter(TextureFilter filter, GLint& minFilter, GLint& magFilter)
+inline void GLES::texture_filter(TextureFilter filter, GLint& minFilter, GLint& magFilter)
 {
 	assert(filter < TF_COUNT);
 
@@ -108,7 +104,7 @@ inline void GLES::GetTextureFilter(TextureFilter filter, GLint& minFilter, GLint
 }
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetFogMode(FogMode mode)
+inline GLenum GLES::fog_mode(FogMode mode)
 {
 	assert(mode < FM_COUNT);
 
@@ -116,7 +112,7 @@ inline GLenum GLES::GetFogMode(FogMode mode)
 }
 
 //-----------------------------------------------------------------------------
-inline GLenum GLES::GetPixelFormat(PixelFormat format)
+inline GLenum GLES::pixel_format(PixelFormat format)
 {
 	switch (format)
 	{
@@ -134,7 +130,7 @@ inline GLenum GLES::GetPixelFormat(PixelFormat format)
 }
 
 //-----------------------------------------------------------------------------
-inline PixelFormat GLES::GetPixelFormatFromGLFormat(GLenum format)
+inline PixelFormat GLES::pixel_format_from_gl_format(GLenum format)
 {
 	switch (format)
 	{

+ 0 - 130
src/renderers/gles/GLESVertexBuffer.cpp

@@ -1,130 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "GLESVertexBuffer.h"
-#include <GLES/gl.h>
-
-namespace crown
-{
-
-GLESVertexBuffer::GLESVertexBuffer():
-	mSize(0), mVertexCount(0)
-{
-	glGenBuffers(1, &mBufferID);
-}
-
-GLESVertexBuffer::~GLESVertexBuffer()
-{
-	glDeleteBuffers(1, &mBufferID);
-}
-
-void GLESVertexBuffer::SetVertexData(VertexBufferMode mode, const void* vertexData, uint32_t vertexCount)
-{
-	mMode = mode;
-
-	uint32_t vertexSize = sizeof(float) * 3;
-	if (HasNormalCoords())
-		vertexSize += sizeof(float) * 3;
-	if (HasTextureCoords())
-		vertexSize += sizeof(float) * 2;
-	if (HasColorCoords())
-		vertexSize += sizeof(float) * 3;
-
-	mSize = vertexCount * vertexSize;
-	mVertexCount = vertexCount;
-
-	glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
-	glBufferData(GL_ARRAY_BUFFER, mSize, vertexData, GL_DYNAMIC_DRAW);
-}
-
-void GLESVertexBuffer::SetVertexSubData(const void* vertexData, uint32_t vertexOffset, uint32_t vertexCount)
-{
-	uint32_t vertexSize = sizeof(float) * 3;
-	if (HasNormalCoords())
-		vertexSize += sizeof(float) * 3;
-	if (HasTextureCoords())
-		vertexSize += sizeof(float) * 2;
-	if (HasColorCoords())
-		vertexSize += sizeof(float) * 3;
-
-	if (vertexSize * vertexCount + vertexOffset > mSize)
-		return;
-
-	glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
-	glBufferSubData(GL_ARRAY_BUFFER, vertexOffset * vertexSize, vertexCount * vertexSize, vertexData);
-}
-
-uint32_t GLESVertexBuffer::GetSize() const
-{
-	return mSize;
-}
-
-uint32_t GLESVertexBuffer::GetVertexCount() const
-{
-	return mVertexCount;
-}
-
-void GLESVertexBuffer::Bind() const
-{
-	uint32_t vertexSize = sizeof(float) * 3;
-	uint32_t offset = vertexSize;
-	if (HasNormalCoords())
-		vertexSize += sizeof(float) * 3;
-	if (HasTextureCoords())
-		vertexSize += sizeof(float) * 2;
-	if (HasColorCoords())
-		vertexSize += sizeof(float) * 4;
-
-	glBindBuffer(GL_ARRAY_BUFFER, mBufferID);
-
-	glVertexPointer(3, GL_FLOAT, vertexSize, (void*) 0);
-
-	if (HasNormalCoords())
-	{
-		glNormalPointer(GL_FLOAT, vertexSize, (void*) offset);
-		offset += sizeof(float) * 3;
-	}
-
-	if (HasTextureCoords())
-	{
-		glClientActiveTexture(GL_TEXTURE0);
-		glTexCoordPointer(2, GL_FLOAT, vertexSize, (void*) offset);
-		offset += sizeof(float) * 2;
-	}
-
-	if (HasColorCoords())
-	{
-		glColorPointer(4, GL_FLOAT, vertexSize, (void*) offset);
-		offset += sizeof(float) * 4;
-	}
-}
-
-void GLESVertexBuffer::Unbind() const
-{
-	glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-}
-

+ 37 - 4
tools/editors/world-editor/CMakeLists.txt

@@ -6,11 +6,44 @@ pkg_check_modules(GTKMM gtkmm-3.0)
 
 link_directories(${GTKMM_LIBRARY_DIRS} ${CROWN_BINARY_DIR})
 
-include_directories(${GTKMM_INCLUDE_DIRS})
+set (INCLUDES
+	terrain
+)
 
-add_executable(world-editor world-editor.cpp CrownDrawingArea.h CrownDrawingArea.cpp)
+set (SRC
+	world-editor.cpp
+	CrownDrawingArea.cpp
+)
+
+set (HEADERS
+	CrownDrawingArea.h
+)
+
+set (TERRAIN_SRC
+	terrain/Heightfield.cpp
+)
+
+set (TERRAIN_HEADERS
+	terrain/Heightfield.h
+)
+
+set (WORLD_EDITOR_SRC
+	${SRC}
+
+	${TERRAIN_SRC}
+)
+
+set (WORLD_EDITOR_HEADERS
+	${HEADERS}
+
+	${TERRAIN_HEADERS}
+)
+
+include_directories(${GTKMM_INCLUDE_DIRS} ${INCLUDES})
+
+add_executable(world-editor ${WORLD_EDITOR_SRC} ${WORLD_EDITOR_HEADERS})
 
 target_link_libraries(world-editor ${GTKMM_LIBRARIES} X11 GL crown)
 
-install (TARGETS world-editor DESTINATION bin)
-install (FILES ui/world-editor.glade DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/ui)
+install (TARGETS world-editor DESTINATION bin/world-editor)
+install (FILES ui/world-editor.glade DESTINATION ${CMAKE_INSTALL_PREFIX}/bin/world-editor/ui)

+ 2 - 2
tools/editors/world-editor/CrownDrawingArea.cpp

@@ -142,9 +142,9 @@ void CrownDrawingArea::on_realize()
 
 	make_current();
 
-	char* argv[1];
+	char* argv[] = {"crown", "--dev" };
 
-	m_engine->init(0, argv);
+	m_engine->init(2, argv);
 
 	Glib::signal_idle().connect(sigc::mem_fun(*this, &CrownDrawingArea::on_idle));
 }

+ 175 - 0
tools/editors/world-editor/terrain/Heightfield.cpp

@@ -0,0 +1,175 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Heightfield.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+Heightfield::Heightfield() :
+	m_initial_width(0),
+	m_initial_height(0),
+	m_initial_meters_per_tile(0),
+	m_initial_altitude(0.0f),
+	m_initial_min_altitude(0.0f),
+	m_initial_max_altitude(0.0f),
+
+	m_width(0),
+	m_height(0),
+	m_meters_per_tile(0),
+
+	m_min_altitude(0.0f),
+	m_max_altitude(0.0f),
+
+	m_altitudes(NULL)
+{
+}
+
+//-----------------------------------------------------------------------------
+Heightfield::~Heightfield()
+{
+	if (m_altitudes != NULL)
+	{
+		m_allocator.deallocate(m_altitudes);
+	}
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::recreate(uint32_t width, uint32_t height, uint32_t meters_per_tile, float initial_altitude, float min_altitude, float max_altitude)
+{
+	// Recreate the heightfield if already existent
+	if (m_altitudes != NULL)
+	{
+		m_allocator.deallocate(m_altitudes);
+		m_altitudes = NULL;
+	}
+
+	m_initial_width = width;
+	m_initial_height = height;
+	m_initial_meters_per_tile = meters_per_tile;
+	m_initial_altitude = initial_altitude;
+	m_initial_min_altitude = min_altitude;
+	m_initial_max_altitude = max_altitude;
+
+	m_width = width;
+	m_height = height;
+	m_meters_per_tile = meters_per_tile;
+	m_min_altitude = min_altitude;
+	m_max_altitude = max_altitude;
+
+	m_altitudes = (float*)m_allocator.allocate(width * height * sizeof(float));
+
+	set_altitudes(m_initial_altitude);
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::clear()
+{
+	m_width = m_initial_width;
+	m_height = m_initial_height;
+	m_meters_per_tile = m_initial_meters_per_tile;
+	m_min_altitude = m_initial_min_altitude;
+	m_max_altitude = m_initial_max_altitude;
+
+	set_altitudes(m_initial_altitude);
+}
+
+//-----------------------------------------------------------------------------
+uint32_t Heightfield::width() const
+{
+	return m_width;
+}
+
+//-----------------------------------------------------------------------------
+uint32_t Heightfield::height() const
+{
+	return m_height;
+}
+
+//-----------------------------------------------------------------------------
+float Heightfield::min_altitude() const
+{
+	return m_min_altitude;
+}
+
+//-----------------------------------------------------------------------------
+float Heightfield::max_altitude() const
+{
+	return m_max_altitude;
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::set_min_altitude(float min)
+{
+	m_min_altitude = min;
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::set_max_altitude(float max)
+{
+	m_max_altitude = max;
+}
+
+//-----------------------------------------------------------------------------
+float Heightfield::altitude(uint32_t x, uint32_t y) const
+{
+	assert(x < m_width);
+	assert(y < m_height);
+
+	return m_altitudes[coords_to_index(x, y)];
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::set_altitude(uint32_t x, uint32_t y, float altitude)
+{
+	const uint32_t adjusted_altitude = (altitude < m_min_altitude) ? m_min_altitude : (altitude > m_max_altitude) ? m_max_altitude : altitude;
+
+	m_altitudes[coords_to_index(x, y)] = adjusted_altitude;
+}
+
+//-----------------------------------------------------------------------------
+void Heightfield::set_altitudes(float altitude)
+{
+	for (uint32_t w = 0; w < m_width; w++)
+	{
+		for (uint32_t h = 0; h < m_height; h++)
+		{
+			set_altitude(w, h, altitude);
+		}
+	}
+}
+
+//-----------------------------------------------------------------------------
+uint32_t Heightfield::coords_to_index(uint32_t x, uint32_t y) const
+{
+	assert(x < m_width);
+	assert(y < m_height);
+
+	return m_width * y + x;
+}
+
+} // namespace crown
+

+ 94 - 0
tools/editors/world-editor/terrain/Heightfield.h

@@ -0,0 +1,94 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "Types.h"
+#include "MallocAllocator.h"
+
+namespace crown
+{
+
+/// Represents a heightfiled.
+class Heightfield
+{
+public:
+
+				Heightfield();
+				~Heightfield();
+
+	/// (Re)Creates the heightfield of sizes @width by @height.
+	/// The param @meters_per_tile indicates how many meters should be mapped per tile unit. (Higher values
+	///	means better quality at same sizes. You can also specify an @initial_height for all the tiles of the heightmap.
+	void		recreate(uint32_t width, uint32_t height, uint32_t meters_per_tile, float initial_altitude, float min_altitude, float max_altitude);
+
+	/// Clears the content of the heightfield, switching it to the initial parameters passed to @recreate().
+	void		clear();
+
+	uint32_t	width() const;
+	uint32_t	height() const;
+
+	float		min_altitude() const;
+	float		max_altitude() const;
+
+	void		set_min_altitude(float min);
+	void		set_max_altitude(float max);
+
+	/// Returns the altitude value for the tile at @x and @y coordinates.
+	float		altitude(uint32_t x, uint32_t y) const;
+
+	/// Sets the @height value for the tile @x and @y coordinates.
+	void		set_altitude(uint32_t x, uint32_t y, float altitude);
+
+	/// Sets the @height value for all the tiles.
+	void		set_altitudes(float altitude);
+
+private:
+
+	uint32_t	coords_to_index(uint32_t x, uint32_t y) const;
+
+private:
+
+	MallocAllocator	m_allocator;
+
+	uint32_t		m_initial_width;
+	uint32_t		m_initial_height;
+	uint32_t		m_initial_meters_per_tile;
+	float			m_initial_altitude;
+	float			m_initial_min_altitude;
+	float			m_initial_max_altitude;
+
+	uint32_t		m_width;
+	uint32_t		m_height;
+	uint32_t		m_meters_per_tile;
+	float			m_min_altitude;
+	float			m_max_altitude;
+
+	// A buffer of heights of width by height.
+	float*			m_altitudes;
+};
+
+} // namespace crown
+

+ 22 - 0
tools/editors/world-editor/ui/world-editor.glade

@@ -202,6 +202,28 @@
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes">_Tools</property>
                 <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu5">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <child>
+                      <object class="GtkMenuItem" id="menuitem7">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Resource browser</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkMenuItem" id="menuitem8">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">Terrain</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
             <child>