Преглед изворни кода

Merge in with latest cherry-picked master commits

Ivan Safrin пре 12 година
родитељ
комит
cb4d7c6bc4

+ 9 - 3
Core/Contents/Include/PolyCamera.h

@@ -24,6 +24,7 @@
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyEntity.h"
+#include "PolyVector2.h"
 
 namespace Polycode {
 
@@ -151,7 +152,7 @@ namespace Polycode {
 			/**
 			* Returns the shader material applied to the camera.
 			*/			
-			Material *getScreenShaderMaterial() { return filterShaderMaterial; }
+			Material *getScreenShaderMaterial() { return filterShaderMaterial; }	
 			
 			
 			Matrix4 getProjectionMatrix();
@@ -163,10 +164,15 @@ namespace Polycode {
 			
 			bool topLeftOrtho;
 			
-		protected:
+			Vector2 cameraShift;
 		
-			Matrix4 projectionMatrix;
+			/**
+			/* Shifts camera frustum by factor of the frustum size. (x=-1 will shift the frustum to the left by a whole screen width).
+			*/
+					
+		protected:
 		
+			Matrix4 projectionMatrix;	
 			Number orthoSizeX;
 			Number orthoSizeY;
 			

+ 5 - 0
Core/Contents/Include/PolyEntity.h

@@ -181,6 +181,11 @@ namespace Polycode {
 			*/
 			virtual void removeChild(Entity *entityToRemove);
 
+			void moveChildUp(Entity *child);
+			void moveChildDown(Entity *child);
+			void moveChildTop(Entity *child);
+			void moveChildBottom(Entity *child);
+
 			/**
 			* Manually sets the entity's parent. This method does not add the entity to the parent and should not be called manually.
 			@param entity Parent entity.

+ 1 - 1
Core/Contents/Include/PolyGLRenderer.h

@@ -174,7 +174,7 @@ namespace Polycode {
 		Matrix4 getProjectionMatrix();
 		Matrix4 getModelviewMatrix();		
 		void setModelviewMatrix(Matrix4 m);	
-		void multModelviewMatrix(Matrix4 m);
+		void multModelviewMatrix(Matrix4 m);		
 		
 		void enableDepthTest(bool val);
 		void enableDepthWrite(bool val);

+ 4 - 0
Core/Contents/Include/PolyRenderer.h

@@ -248,6 +248,8 @@ namespace Polycode {
 		Number getViewportWidth();
 		Number getViewportHeight();		
 		
+		void setViewportShift(Number shiftX, Number shiftY);
+		
 		void *getDataPointerForName(const String &name);
 		void setRendererShaderParams(Shader *shader, ShaderBinding *binding);
 		
@@ -311,6 +313,8 @@ namespace Polycode {
 	
 		Number viewportWidth;
 		Number viewportHeight;
+		
+		Vector2 viewportShift;
 			
 		bool cullingFrontFaces;
 				

+ 10 - 11
Core/Contents/Source/PolyCamera.cpp

@@ -315,7 +315,6 @@ void Camera::setLightDepthTexture(Texture *texture) {
 		localShaderOptions[i]->clearTexture("PolyLight0ZBuffer");
 		localShaderOptions[i]->addTexture("PolyLight0ZBuffer", texture);
 	}
-
 }
 
 void Camera::drawFilter(Texture *targetTexture, Number targetTextureWidth, Number targetTextureHeight, Texture *targetColorTexture, Texture *targetZTexture) {
@@ -387,7 +386,6 @@ void Camera::drawFilter(Texture *targetTexture, Number targetTextureWidth, Numbe
 		CoreServices::getInstance()->getRenderer()->clearShader();
 		CoreServices::getInstance()->getRenderer()->loadIdentity();
 	}
-
 }
 
 Matrix4 Camera::getProjectionMatrix() {
@@ -396,25 +394,26 @@ Matrix4 Camera::getProjectionMatrix() {
 
 void Camera::doCameraTransform() {
 
-	CoreServices::getInstance()->getRenderer()->setClippingPlanes(nearClipPlane, farClipPlane);
+	Renderer *renderer = CoreServices::getInstance()->getRenderer();
+	renderer->setClippingPlanes(nearClipPlane, farClipPlane);
 
 	if(!orthoMode) {
-		//renderer->setViewportShift(cameraShift.x, cameraShift.y);
-		CoreServices::getInstance()->getRenderer()->setFOV(fov);
-		CoreServices::getInstance()->getRenderer()->setPerspectiveMode();		
+		renderer->setViewportShift(cameraShift.x, cameraShift.y);
+		renderer->setFOV(fov);
+		renderer->setPerspectiveMode();		
 	} else {
-		CoreServices::getInstance()->getRenderer()->setOrthoMode(orthoSizeX, orthoSizeY, !topLeftOrtho);
+		renderer->setOrthoMode(orthoSizeX, orthoSizeY, !topLeftOrtho);
 	}	
-	CoreServices::getInstance()->getRenderer()->setExposureLevel(exposureLevel);
+	renderer->setExposureLevel(exposureLevel);
 
-	projectionMatrix = CoreServices::getInstance()->getRenderer()->getProjectionMatrix();
+	projectionMatrix = renderer->getProjectionMatrix();
 
 	if(matrixDirty) {
 		rebuildTransformMatrix();
 	}
 
 	Matrix4 camMatrix = getConcatenatedMatrix();
-	CoreServices::getInstance()->getRenderer()->setCameraMatrix(camMatrix);	
+	renderer->setCameraMatrix(camMatrix);	
 	camMatrix = camMatrix.Inverse();
-	CoreServices::getInstance()->getRenderer()->multModelviewMatrix(camMatrix);		
+	renderer->multModelviewMatrix(camMatrix);		
 }

+ 42 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -232,6 +232,48 @@ void Entity::removeChild(Entity *entityToRemove) {
 	}	
 }
 
+void Entity::moveChildUp(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i < children.size()-1) {
+			Entity *next = (Entity*)children[i+1];
+			children[i+1] = child;
+			children[i] = next;
+			break;
+		}
+	}
+}
+
+void Entity::moveChildDown(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i > 0) {
+			Entity *prev = (Entity*)children[i-1];
+			children[i-1] = child;
+			children[i] = prev;
+			break;
+		}
+	}
+}
+
+void Entity::moveChildTop(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i < children.size()-1) {
+			children.erase(children.begin()+i);
+			children.push_back(child);
+			break;
+		}
+	}
+}
+
+void Entity::moveChildBottom(Entity *child) {
+	for(int i=0; i < children.size(); i++) {
+		if(children[i] == child && i > 0) {
+			children.erase(children.begin()+i);
+			children.insert(children.begin(), child);
+			break;
+		}
+	}
+}
+
 unsigned int Entity::getNumChildren() {
 	return children.size();
 }

+ 10 - 5
Core/Contents/Source/PolyGLRenderer.cpp

@@ -24,6 +24,7 @@
 #include "PolyString.h"
 #include "PolyLogger.h"
 #include "PolyTexture.h"
+#include "PolyVector2.h"
 #include "PolyGLTexture.h"
 #include "PolyCubemap.h"
 #include "PolyGLCubemap.h"
@@ -165,9 +166,8 @@ void OpenGLRenderer::Resize(int xRes, int yRes) {
 	
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
-	gluPerspective(fov,(GLfloat)xRes/(GLfloat)yRes,nearPlane,farPlane);
-	glViewport(0, 0, xRes, yRes);
-	setScissorBox(Rectangle(0, 0, xRes, yRes));
+
+	resetViewport();
 	
 	glMatrixMode(GL_MODELVIEW);
 	glLineWidth(1);
@@ -220,9 +220,14 @@ void OpenGLRenderer::setLineSmooth(bool val) {
 void OpenGLRenderer::resetViewport() {
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	gluPerspective(fov,(GLfloat)viewportWidth/(GLfloat)viewportHeight,nearPlane,farPlane);	
+	//gluPerspective(fov,(GLfloat)viewportWidth/(GLfloat)viewportHeight,nearPlane,farPlane);		
+    Number fW, fH;
+    fH = tan( fov / 360.0 * PI ) * nearPlane;
+    fW = fH * ((GLfloat)viewportWidth/(GLfloat)viewportHeight);
+	glFrustum(-fW + (viewportShift.x*fW*2.0), fW + (viewportShift.x*fW*2.0), -fH + (viewportShift.y*fH*2.0), fH + (viewportShift.y*fH*2.0), nearPlane, farPlane);
+	
 	glViewport(0, 0, viewportWidth, viewportHeight);
-	glScissor(0, 0, viewportWidth, viewportHeight);
+	glScissor(0, 0,  viewportWidth, viewportHeight);
 	glMatrixMode(GL_MODELVIEW);	
 	glGetDoublev( GL_PROJECTION_MATRIX, sceneProjectionMatrix);
 }

+ 6 - 0
Core/Contents/Source/PolyRenderer.cpp

@@ -151,6 +151,12 @@ Polycode::Rectangle Renderer::getScissorBox() {
 	return scissorBox;
 }
 
+void Renderer::setViewportShift(Number shiftX, Number shiftY) {
+	viewportShift.x = shiftX;
+	viewportShift.y = shiftY;
+	resetViewport();
+}
+
 bool Renderer::isScissorEnabled() {
 	return scissorEnabled;
 }

+ 2 - 0
Modules/Contents/3DPhysics/Include/PolyPhysicsScene.h

@@ -135,9 +135,11 @@ namespace Polycode {
 			//@}
 			// ----------------------------------------------------------------------------------------------------------------
 
+		bool pausePhysics;
 		
 	protected:
 		
+		bool paused;
 		int maxSubSteps;
 		void initPhysicsScene(Vector3 size);		
 		

+ 1 - 1
Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp

@@ -26,7 +26,7 @@ THE SOFTWARE.
 
 using namespace Polycode;
 
-CollisionScene::CollisionScene(Vector3 size, bool virtualScene, bool deferInitCollision) : Scene(0, virtualScene), world(NULL), collisionConfiguration(NULL), dispatcher(NULL), axisSweep(NULL) {
+CollisionScene::CollisionScene(Vector3 size, bool virtualScene, bool deferInitCollision) : Scene(Scene::SCENE_3D, virtualScene), world(NULL), collisionConfiguration(NULL), dispatcher(NULL), axisSweep(NULL) {
 	if(!deferInitCollision) {
 		initCollisionScene(size);
 	}

+ 3 - 1
Modules/Contents/3DPhysics/Source/PolyPhysicsScene.cpp

@@ -44,6 +44,7 @@ PhysicsSceneEvent::~PhysicsSceneEvent() {
 
 PhysicsScene::PhysicsScene(int maxSubSteps, Vector3 size, bool virtualScene) : CollisionScene(size, virtualScene, true), physicsWorld(NULL), solver(NULL), broadphase(NULL), ghostPairCallback(NULL) {
 	this->maxSubSteps = maxSubSteps;
+	pausePhysics = false;	
 	initPhysicsScene(size);	
 }
 
@@ -142,7 +143,7 @@ void PhysicsScene::processWorldCollisions() {
 }
 
 void PhysicsScene::Update() {
-	
+	if(!pausePhysics) {
 	for(int i=0; i < physicsChildren.size(); i++) {
 //		if(physicsChildren[i]->enabled)
 			physicsChildren[i]->Update();
@@ -155,6 +156,7 @@ void PhysicsScene::Update() {
 	} else {
 		physicsWorld->stepSimulation(elapsed);		
 	}
+	}
 	CollisionScene::Update();
 	
 }