Pārlūkot izejas kodu

Fixed billboard entities, removed old billboard options, made icons in entity edtior in the IDE display in 2D instead of as billboards

Ivan Safrin 10 gadi atpakaļ
vecāks
revīzija
8308964977

+ 2 - 13
include/polycode/core/PolyEntity.h

@@ -611,19 +611,8 @@ namespace Polycode {
 			/**
 			* If this flag is true, the entity will always face the camera. False by default.
 			*/						
-			bool billboardMode;			
-			
-			/**
-			* Normally, if billboardMode is on, no rotation is allowed at all. If this flag is also true, you can rotate the entity around the axis pointing to the camera.
-			*/									
-			bool billboardRoll;
-			
-			/**
-			* If set to true, the entity will not be scaled by the modelview
-			* matrix when billboardMode is enabled
-			*/
-			bool billboardIgnoreScale;
-
+			bool billboardMode;
+        
 			/**
 			* The entity's color.
 			*/					

+ 1 - 1
include/polycode/ide/PolycodeEntityEditor.h

@@ -226,7 +226,7 @@ class EntityEditorMainView : public UIElement {
     
 			void handleEvent(Event *event);
 			void Resize(Number width, Number height);
-			void Update();
+			void fixedUpdate();
             void addEntityFromMenu(String command);
     
             void doEntityDeselect(Entity *targetEntity);

+ 17 - 14
src/core/PolyEntity.cpp

@@ -57,8 +57,6 @@ void Entity::initEntity() {
 	parentEntity = NULL;
 	matrixDirty = true;
 	billboardMode = false;
-	billboardRoll = false;
-	billboardIgnoreScale = false;
 	drawCall.options.depthOnly = false;
 	drawCall.options.blendingMode = Entity::defaultBlendingMode;    
 	depthWrite = true;
@@ -110,8 +108,7 @@ void Entity::applyClone(Entity *clone, bool deepClone, bool ignoreEditorOnly) co
 	clone->setRotationByQuaternion(rotationQuat);
 	clone->setScale(scale);
 	clone->color = color;
-	clone->billboardMode = billboardMode;	
-	clone->billboardRoll = billboardRoll;
+	clone->billboardMode = billboardMode;
 	clone->depthWrite = depthWrite;
 	clone->depthTest = depthTest;
 	clone->colorAffectsChildren = colorAffectsChildren;
@@ -525,18 +522,24 @@ void Entity::transformAndRender(GPUDrawBuffer *buffer, Polycode::Rectangle *pare
         drawCall.modelMatrix = drawCall.modelMatrix * getConcatenatedMatrix();
     }
     
-    /*
+
 	if(billboardMode) {
-		if(billboardIgnoreScale) {
-			renderer->billboardMatrix();
-		} else {
-			renderer->billboardMatrixWithScale(getCompoundScale());
-		}
-		if(billboardRoll) {
-			renderer->multModelviewMatrix(getConcatenatedRollMatrix());
-		}
+        
+        Vector3 scale = getCompoundScale();
+        
+        drawCall.modelMatrix[0][0] = buffer->viewMatrix.m[0][0];
+        drawCall.modelMatrix[0][1] = buffer->viewMatrix.m[1][0];
+        drawCall.modelMatrix[0][2] = buffer->viewMatrix.m[2][0];
+            
+        drawCall.modelMatrix[1][0] = buffer->viewMatrix.m[0][1];
+        drawCall.modelMatrix[1][1] = buffer->viewMatrix.m[1][1];
+        drawCall.modelMatrix[1][2] = buffer->viewMatrix.m[2][1];
+            
+        drawCall.modelMatrix[2][0] = buffer->viewMatrix.m[0][2];
+        drawCall.modelMatrix[2][1] = buffer->viewMatrix.m[1][2];
+        drawCall.modelMatrix[2][2] = buffer->viewMatrix.m[2][2];
+        
 	}
-*/
     
     
 	if(visible && rendererVis) {

+ 1 - 1
src/ide/PolycodeEditor.cpp

@@ -48,7 +48,7 @@ void PolycodeEditor::setFilePath(String newPath) {
 
 PolycodeEditor::PolycodeEditor(bool _isReadOnly) : UIElement(), ClipboardProvider() {
 	this->_isReadOnly = _isReadOnly;
-//	enableScissor = true;	
+    enableScissor = true;
 	processInputEvents = true;
 	_hasChanges = false;
 	

+ 9 - 23
src/ide/PolycodeEntityEditor.cpp

@@ -929,7 +929,7 @@ bool EntityDistanceSorter::operator() (MultiselectorEntry i,MultiselectorEntry j
     }
 }
 
-void EntityEditorMainView::Update() {
+void EntityEditorMainView::fixedUpdate() {
     
     // update dummy target if trasnforming dummy entity
     
@@ -965,8 +965,7 @@ void EntityEditorMainView::Update() {
         Number aspect = renderTextureShape->getWidth() / renderTextureShape->getHeight();
         mainScene->getDefaultCamera()->setOrthoSize(trackballCamera->getCameraDistance() * aspect, trackballCamera->getCameraDistance());
     }
-    
-    
+        
     for(int i=0; i < icons.size(); i++) {
         Number scale;
         
@@ -977,17 +976,11 @@ void EntityEditorMainView::Update() {
             icons[i]->visible = false;
         } else {
             icons[i]->visible = true;
-            Vector3 parentPosition = parentEntity->getConcatenatedMatrix().getPosition();
-            icons[i]->setPosition(parentPosition);
             
-            if(editorMode != EDITOR_MODE_3D) {
-                scale = trackballCamera->getCameraDistance() * 0.1;
-            } else {
-                scale = mainScene->getDefaultCamera()->getPosition().distance(icons[i]->getConcatenatedMatrix().getPosition()) * 0.1;
-            }
-            icons[i]->setScale(scale, scale, scale);
-            icons[i]->rebuildTransformMatrix();
-            icons[i]->recalculateAABBAllChildren();
+            Vector2 screenPos = parentEntity->getScreenPosition(mainScene->getDefaultCamera()->getProjectionMatrix(), mainScene->getDefaultCamera()->getConcatenatedMatrix().Inverse(), mainScene->getDefaultCamera()->getViewport());
+            
+            icons[i]->setPosition(screenPos.x, (mainScene->getDefaultCamera()->getViewport().h - screenPos.y) + 30);
+
         }
     }
     
@@ -1004,26 +997,19 @@ void EntityEditorMainView::createIcon(Entity *entity, String iconFile) {
     
     entity->removeAllHandlersForListener(this);
     
-    ScenePrimitive *iconPrimitive = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.3, 0.3);
-    
+    ScenePrimitive *iconPrimitive = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 32, 32);
     iconPrimitive->setMaterialByName("Unlit");
+    iconPrimitive->setBlendingMode(Renderer::BLEND_MODE_NORMAL);
 	Texture *tex = CoreServices::getInstance()->getMaterialManager()->createTextureFromFile("entityEditor/"+iconFile);
 	if(iconPrimitive->getLocalShaderOptions()) {
         iconPrimitive->getLocalShaderOptions()->setTextureForParam("diffuse", tex);
 	}
     
-    iconBase->addChild(iconPrimitive);
-    iconPrimitive->billboardMode = true;
+    addChild(iconPrimitive);
     iconPrimitive->setUserData((void*)entity);
     iconPrimitive->forceMaterial = true;
     iconPrimitive->processInputEvents = true;
     iconPrimitive->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
-    iconPrimitive->ignoreParentMatrix = true;
-    iconPrimitive->addTag("");
-    iconPrimitive->depthTest = false;
-    iconPrimitive->depthWrite = false;
-    iconPrimitive->editorOnly = true;
-    iconPrimitive->alphaTest = true;
     iconPrimitive->setUserData(entity);
     icons.push_back(iconPrimitive);
 }

+ 4 - 4
src/ide/PolycodeIDEApp.cpp

@@ -834,10 +834,10 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 	if(event->getDispatcher() == core) {
 		switch(event->getEventCode()) {
 			case Core::EVENT_LOST_FOCUS:
-				core->setFramerate(3);
+//				core->setFramerate(3);
 			break;		
 			case Core::EVENT_GAINED_FOCUS:
-				core->setFramerate(60);			
+//				core->setFramerate(60);
 			break;					
 			case Core::EVENT_CORE_RESIZE:
 				if(menuBar) {
@@ -1278,13 +1278,13 @@ void PolycodeIDEApp::applyFinalConfig() {
 		int newYRes = appHeight->intVal;		
 		if(newXRes > 100 && newYRes > 100) {
 			setResFromConfig = true;
-//			core->setVideoMode(newXRes, newYRes, false, true, 0, 0);
+            core->setVideoMode(newXRes, newYRes, false, true, 0, 0);
 			frame->Resize(newXRes, newYRes);
 		}
 	}
 	
 	if(!setResFromConfig) {
-	//	core->setVideoMode(1100, 700, false, true, 0, 0);
+        core->setVideoMode(1100, 700, false, true, 0, 0);
 		frame->Resize(1100, 700);			
 	}