diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java index f6344c4..357f172 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java +++ b/src/ve/ucv/ciens/ccg/nxtar/entities/BombGameEntityCreator.java @@ -39,7 +39,7 @@ import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader; import com.badlogic.gdx.math.Matrix3; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.GdxRuntimeException; -import com.badlogic.gdx.utils.JsonReader; +import com.badlogic.gdx.utils.UBJsonReader; public class BombGameEntityCreator extends EntityCreatorBase{ private static final String TAG = "BOMB_ENTITY_CREATOR"; @@ -75,12 +75,12 @@ public class BombGameEntityCreator extends EntityCreatorBase{ private int currentBombId; public BombGameEntityCreator(){ - G3dModelLoader loader = new G3dModelLoader(new JsonReader()); + G3dModelLoader loader = new G3dModelLoader(new UBJsonReader()); currentBombId = 0; parameters = new EntityParameters(); parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f)); - parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, -0.5f))); + parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1))); // Load the shader. shader = new DirectionalLightPerPixelShader(); @@ -95,15 +95,15 @@ public class BombGameEntityCreator extends EntityCreatorBase{ // Create the models. // TODO: Set the correct model paths. // TODO: Load collision models. - doorModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - doorFrameModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelCombination = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelInclination = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelWires = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - easterEggModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); - bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("assets/models/render_models/")); + doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db")); + doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db")); +// bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/")); +// bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/")); + bombModelWires = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db")); +// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/")); + bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db")); + bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db")); + bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db")); } @Override @@ -111,23 +111,23 @@ public class BombGameEntityCreator extends EntityCreatorBase{ // TODO: Add the robot arms. // Add bombs. - parameters.markerCode = 89; - addBomb(parameters, bomb_type_t.COMBINATION); - - parameters.markerCode = 90; - addBomb(parameters, bomb_type_t.INCLINATION); +// parameters.markerCode = 89; +// addBomb(parameters, bomb_type_t.COMBINATION); +// +// parameters.markerCode = 90; +// addBomb(parameters, bomb_type_t.INCLINATION); parameters.markerCode = 91; addBomb(parameters, bomb_type_t.WIRES); // Add doors. - parameters.nextAnimation = 0; + parameters.nextAnimation = 1; parameters.loopAnimation = false; - parameters.markerCode = 89; - addDoor(parameters); - parameters.markerCode = 90; - addDoor(parameters); +// parameters.markerCode = 89; +// addDoor(parameters); +// parameters.markerCode = 90; +// addDoor(parameters); parameters.markerCode = 91; addDoor(parameters); } @@ -170,6 +170,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{ bomb.addComponent(bombComponent); bomb.addComponent(new VisibilityComponent()); + // Add the collision and render models depending on the bomb type. if(type == bomb_type_t.COMBINATION){ bomb.addComponent(new RenderModelComponent(bombModelCombination)); }else if(type == bomb_type_t.INCLINATION){ @@ -195,6 +196,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{ wire1.addComponent(new RenderModelComponent(bombModelWiresWire1)); wire1.addComponent(new BombComponent(bomb)); wire1.addComponent(new VisibilityComponent()); + wire1.addComponent(new MarkerCodeComponent(parameters.markerCode)); wire1.addToWorld(); wire2 = world.createEntity(); @@ -204,6 +206,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{ wire2.addComponent(new RenderModelComponent(bombModelWiresWire2)); wire2.addComponent(new BombComponent(bomb)); wire2.addComponent(new VisibilityComponent()); + wire2.addComponent(new MarkerCodeComponent(parameters.markerCode)); wire2.addToWorld(); wire3 = world.createEntity(); @@ -213,6 +216,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{ wire3.addComponent(new RenderModelComponent(bombModelWiresWire3)); wire3.addComponent(new BombComponent(bomb)); wire3.addComponent(new VisibilityComponent()); + wire3.addComponent(new MarkerCodeComponent(parameters.markerCode)); wire3.addToWorld(); } diff --git a/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java b/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java deleted file mode 100644 index c8ca5f3..0000000 --- a/src/ve/ucv/ciens/ccg/nxtar/exceptions/ShaderFailedToLoadException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2014 Miguel Angel Astor Romero - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package ve.ucv.ciens.ccg.nxtar.exceptions; - -public class ShaderFailedToLoadException extends Exception { - private static final long serialVersionUID = 9989L; - - public ShaderFailedToLoadException(String msg){ - super(msg); - } -} diff --git a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java index a210d02..0b4a9db 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java +++ b/src/ve/ucv/ciens/ccg/nxtar/graphics/shaders/DirectionalLightPerPixelShader.java @@ -36,6 +36,8 @@ public class DirectionalLightPerPixelShader implements Shader{ private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl"; private static final String FRAGMENT_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_frag.glsl"; private static final String INCLUDE_SKINNING = "#define SKINNING\n"; + private static final float DEFAULT_SHININESS = 50.0f; + private static final Vector3 DEFAULT_LIGHT = new Vector3(1, 1, 1); private ShaderProgram skinningProgram; private ShaderProgram baseProgram; @@ -134,22 +136,8 @@ public class DirectionalLightPerPixelShader implements Shader{ @Override public boolean canRender(Renderable renderable){ - // Check for all needed lighting and material attributes. - if(renderable.environment.directionalLights.size < 1) - return false; - - if(!renderable.environment.has(ColorAttribute.AmbientLight)) - return false; - - if(!renderable.material.has(ColorAttribute.Diffuse)) - return false; - - if(!renderable.material.has(ColorAttribute.Specular)) - return false; - - if(!renderable.material.has(FloatAttribute.Shininess)) - return false; - + // Easier to always return true. Missing material properties are replaced by + // default values during render. return true; } @@ -169,16 +157,43 @@ public class DirectionalLightPerPixelShader implements Shader{ @Override public void render(Renderable renderable){ ShaderProgram program; - int index; - boolean bonesEnabled; + int index; + boolean bonesEnabled; + Vector3 lightPosition; + Color diffuseLightColor; + Color diffuseColor; + Color specularColor; + Color ambientColor; + float shininess; // Get material colors. - Vector3 lightPosition = renderable.environment.directionalLights.get(0).direction; - Color diffuseLightColor = renderable.environment.directionalLights.get(0).color; - Color diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color; - Color specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color; - Color ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color; - float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value; + if(renderable.environment.directionalLights.size >= 1){ + lightPosition = renderable.environment.directionalLights.get(0).direction; + diffuseLightColor = renderable.environment.directionalLights.get(0).color; + }else{ + lightPosition = DEFAULT_LIGHT; + diffuseLightColor = Color.WHITE; + } + + if(renderable.material.has(ColorAttribute.Diffuse)) + diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color; + else + diffuseColor = Color.WHITE; + + if(renderable.material.has(ColorAttribute.Specular)) + specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color; + else + specularColor = Color.BLACK; + + if(renderable.environment.has(ColorAttribute.AmbientLight)) + ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color; + else + ambientColor = Color.BLACK; + + if(renderable.material.has(FloatAttribute.Shininess)) + shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value; + else + shininess = DEFAULT_SHININESS; if(renderable.mesh.getVertexAttribute(VertexAttributes.Usage.BoneWeight) != null){ program = skinningProgram; diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index 842c093..8a79d63 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -248,7 +248,7 @@ public class InGameState extends BaseState{ perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f); perspectiveCamera.update(); - gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera); +// gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera); } // Attempt to find the markers in the current video frame. diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java index 064f02c..cd73cb3 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java @@ -36,14 +36,16 @@ public class AnimationSystem extends EntityProcessingSystem { @Override protected void process(Entity e) { - AnimationComponent animation = animationMapper.get(e); + AnimationComponent animation = animationMapper.get(e); VisibilityComponent visibility = visibilityMapper.get(e); + int loopCount = animation.loop ? -1 : 1; if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){ - if(animation.loop) - animation.controller.animate(animation.animationsIds.get(animation.next), -1, 1, null,0.1f); - else - animation.controller.animate(animation.animationsIds.get(animation.next), 1, 1, null,0.1f); + if(animation.controller.current == null){ + animation.controller.setAnimation(animation.animationsIds.get(animation.next), loopCount, 1, null); + }else{ + animation.controller.animate(animation.animationsIds.get(animation.next), loopCount, 1, null, 0.1f); + } } if(visibility.visible) diff --git a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java index 000675c..3ba0194 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java +++ b/src/ve/ucv/ciens/ccg/nxtar/utils/GameSettings.java @@ -15,8 +15,8 @@ */ package ve.ucv.ciens.ccg.nxtar.utils; +import ve.ucv.ciens.ccg.nxtar.entities.BombGameEntityCreator; import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase; -import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator; import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase; public abstract class GameSettings{ @@ -24,7 +24,7 @@ public abstract class GameSettings{ public static GameLogicSystemBase gameLogicSystem = null; public static void initGameSettings(){ - entityCreator = new MarkerTestEntityCreator(); + entityCreator = new BombGameEntityCreator(); gameLogicSystem = null; //gameLogicSystem = new BombGameLogicSystem(); }