Removed needless source files. Added game settings.

This commit is contained in:
2014-05-28 14:22:46 -04:30
parent 5e66273396
commit eb8206668f
13 changed files with 236 additions and 493 deletions

View File

@@ -28,4 +28,11 @@ public class ModelComponent extends Component {
this.instance = new ModelInstance(model);
}
public ModelComponent(ModelInstance instance) throws IllegalArgumentException{
if(instance == null)
throw new IllegalArgumentException("Instance is null.");
this.instance = instance;
}
}

View File

@@ -15,18 +15,191 @@
*/
package ve.ucv.ciens.ccg.nxtar.entities;
public class BombGameEntityCreator extends EntityCreatorBase {
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity;
import com.artemis.World;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.Shader;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
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;
public class BombGameEntityCreator extends EntityCreatorBase{
private static final String TAG = "BOMB_ENTITY_CREATOR";
private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
/*private enum bomb_type_t{
COMBINATION(0), INCLINATION(1), WIRES(2);
private int value;
private bomb_type_t(int value){
this.value = value;
}
public int getValue(){
return this.value;
}
};*/
private class EntityParameters{
public Environment environment;
public Shader shader;
public Model model1;
public Model model2;
public int markerCode;
public int nextAnimation;
public boolean loopAnimation;
public EntityParameters(){
environment = new Environment();
shader = null;
model1 = null;
model2 = null;
markerCode = -1;
nextAnimation = -1;
loopAnimation = false;
}
}
private EntityParameters parameters;
private Shader shader;
private Model doorModel;
private Model doorFrameModel;
private Model bombModelCombination;
private Model bombModelInclination;
private Model bombModelWires;
private Model easterEggModel;
public BombGameEntityCreator(){
// TODO: Empty constructor.
G3dModelLoader loader = new G3dModelLoader(new JsonReader());
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)));
// Load the shader.
shader = new DirectionalLightPerPixelShader();
try{
shader.init();
}catch(GdxRuntimeException gdx){
Gdx.app.error(TAG, CLASS_NAME + ".BombGameEntityCreator(): Shader failed to load: " + gdx.getMessage());
shader = null;
}
parameters.shader = shader;
// Create the models.
// TODO: Set the correct model paths.
doorModel = loader.loadModel(Gdx.files.internal(""));
doorFrameModel = loader.loadModel(Gdx.files.internal(""));
bombModelCombination = loader.loadModel(Gdx.files.internal(""));
bombModelInclination = loader.loadModel(Gdx.files.internal(""));
bombModelWires = loader.loadModel(Gdx.files.internal(""));
easterEggModel = loader.loadModel(Gdx.files.internal(""));
}
@Override
public void createAllEntities() {
// TODO Auto-generated method stub
public void createAllEntities(){
// TODO: Create the scene.
// TODO: Add the robot arms.
// Add bombs.
parameters.markerCode = 89;
parameters.model1 = bombModelCombination;
addBomb(world, parameters);
parameters.markerCode = 90;
parameters.model1 = bombModelInclination;
addBomb(world, parameters);
parameters.markerCode = 91;
parameters.model1 = bombModelWires;
addBomb(world, parameters);
// Add doors.
parameters.model1 = doorFrameModel;
parameters.model2 = doorModel;
parameters.nextAnimation = 0;
parameters.loopAnimation = false;
parameters.markerCode = 89;
addDoor(world, parameters);
parameters.markerCode = 90;
addDoor(world, parameters);
parameters.markerCode = 91;
addDoor(world, parameters);
}
@Override
public void dispose() {
// TODO Auto-generated method stub
if(shader != null)
shader.dispose();
// Dispose of the models.
if(doorModel != null)
doorModel.dispose();
if(doorFrameModel != null)
doorFrameModel.dispose();
if(bombModelCombination != null)
bombModelCombination.dispose();
if(bombModelInclination != null)
bombModelInclination.dispose();
if(bombModelWires != null)
bombModelWires.dispose();
if(easterEggModel != null)
easterEggModel.dispose();
}
private void addBomb(World world, EntityParameters parameters){
Entity bomb;
bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
bomb.addComponent(new ModelComponent(parameters.model1));
bomb.addComponent(new EnvironmentComponent(parameters.environment));
bomb.addComponent(new ShaderComponent(parameters.shader));
bomb.addComponent(new MarkerCodeComponent(parameters.markerCode));
bomb.addToWorld();
}
private void addDoor(World world, EntityParameters parameters){
ModelInstance frameModel, doorModel;
Entity frame, door;
frameModel = new ModelInstance(parameters.model1);
doorModel = new ModelInstance(parameters.model2);
frame = world.createEntity();
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new ModelComponent(frameModel));
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
frame.addToWorld();
door = world.createEntity();
door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
door.addComponent(new ModelComponent(doorModel));
door.addComponent(new EnvironmentComponent(parameters.environment));
door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode));
door.addComponent(new AnimationComponent(doorModel, parameters.nextAnimation, parameters.loopAnimation));
door.addToWorld();
}
}

View File

@@ -16,8 +16,9 @@
package ve.ucv.ciens.ccg.nxtar.entities;
import com.artemis.World;
import com.badlogic.gdx.utils.Disposable;
public abstract class EntityCreatorBase {
public abstract class EntityCreatorBase implements Disposable{
protected World world;
public void setWorld(World world) throws IllegalArgumentException{

View File

@@ -21,7 +21,7 @@ import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPerPixelShader;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity;
import com.badlogic.gdx.Gdx;
@@ -48,7 +48,7 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
private Model bombModel;
private Model animatedModel;
private Model boxModel;
private SingleLightPerPixelShader ppShader;
private DirectionalLightPerPixelShader ppShader;
@Override
public void createAllEntities() {
@@ -72,12 +72,12 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
boxModel = builder.createBox(0.5f, 0.5f, 6.0f, material, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")).getMask());
// Load the shader.
ppShader = new SingleLightPerPixelShader();
ppShader = new DirectionalLightPerPixelShader();
ppShader.init();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, 0.5f)));
environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, -0.5f)));
// Create the entities.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");

View File

@@ -1,134 +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.entities;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPhongShader;
import com.artemis.Entity;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
import com.badlogic.gdx.math.Matrix3;
import com.badlogic.gdx.math.Vector3;
public class TestGameEntityCreator extends EntityCreatorBase {
private static final String TAG = "TEST_ENTITY_CREATOR";
private static final String CLASS_NAME = TestGameEntityCreator.class.getSimpleName();
private MeshBuilder builder;
private Mesh sphereMesh;
private Mesh cubeMesh;
private Mesh capsuleMesh;
private CustomShaderBase singleLightPhongShader;
@Override
public void createAllEntities() {
Matrix3 identity = new Matrix3();
Entity sphere;
Entity cube;
Entity capsule1;
Entity capsule2;
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Started.");
identity.idt();
// Create the sphere.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
builder = new MeshBuilder();
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
builder.sphere(1.0f, 1.0f, 1.0f, 10, 10);
}sphereMesh = builder.end();
// Create the cube.
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
builder.setColor(0.2f, 0.5f, 1.0f, 1.0f);
builder.box(0.5f, 0.5f, 0.5f);
}cubeMesh = builder.end();
// Create the capsule.
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
builder.capsule(0.25f, 0.5f, 10);
}capsuleMesh = builder.end();
// Load the phong shader.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
try{
singleLightPhongShader = new SingleLightPhongShader().loadShader();
}catch(ShaderFailedToLoadException se){
Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + se.getMessage());
Gdx.app.exit();
}
// Create the entities.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
sphere = world.createEntity();
sphere.addComponent(new GeometryComponent(new Vector3(0.5f, 0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
sphere.addComponent(new MeshComponent(sphereMesh));
sphere.addComponent(new CustomShaderComponent(singleLightPhongShader));
cube = world.createEntity();
cube.addComponent(new GeometryComponent(new Vector3(-0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
cube.addComponent(new MeshComponent(cubeMesh));
cube.addComponent(new CustomShaderComponent(singleLightPhongShader));
capsule1 = world.createEntity();
capsule1.addComponent(new GeometryComponent(new Vector3(-0.5f, 0.5f, 0.0f), identity, new Vector3(1.5f, 1.0f, 1.0f)));
capsule1.addComponent(new MeshComponent(capsuleMesh));
capsule1.addComponent(new CustomShaderComponent(singleLightPhongShader));
capsule2 = world.createEntity();
capsule2.addComponent(new GeometryComponent(new Vector3(0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.5f, 1.0f)));
capsule2.addComponent(new MeshComponent(capsuleMesh));
capsule2.addComponent(new CustomShaderComponent(singleLightPhongShader));
// Add the entities to the world.
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
sphere.addToWorld();
cube.addToWorld();
capsule1.addToWorld();
capsule2.addToWorld();
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Finished.");
}
@Override
public void dispose() {
if(singleLightPhongShader != null && singleLightPhongShader.getShaderProgram() != null)
singleLightPhongShader.getShaderProgram().dispose();
if(sphereMesh != null)
sphereMesh.dispose();
if(cubeMesh != null)
cubeMesh.dispose();
if(capsuleMesh != null)
capsuleMesh.dispose();
}
}

View File

@@ -1,162 +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.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector3;
/**
* <p>A 3D light source.</p>
*/
public class LightSource{
private Vector3 position;
private Color ambientColor;
private Color diffuseColor;
private Color specularColor;
private float shinyness;
/**
* <p>Creates a default white light source positioned at (0,0,0).</p>
*/
public LightSource(){
position = new Vector3(0.0f, 0.0f, 0.0f);
ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
shinyness = 10.0f;
}
/**
* <p>Creates a white light source at the specified position.</p>
*
* @param position The location of the light source.
*/
public LightSource(Vector3 position){
this.position = new Vector3();
this.position.set(position);
ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
shinyness = 10.0f;
}
/**
* <p>Creates a custom light source.</p>
*
* @param position The location of the light source.
* @param ambientColor
* @param diffuseColor
* @param specularColor
* @param shinyness The shinyness component. Must be between (0.0, 128.0].
* @throws IllegalArgumentException When shinyness is outside the valid range.
*/
public LightSource(Vector3 position, Color ambientColor, Color diffuseColor, Color specularColor, float shinyness) throws IllegalArgumentException {
if(shinyness <= 0.0 || shinyness > 128.0)
throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
this.position = new Vector3();
this.ambientColor = new Color();
this.diffuseColor = new Color();
this.ambientColor = new Color();
this.specularColor = new Color();
this.position.set(position);
this.ambientColor.set(ambientColor);
this.diffuseColor.set(diffuseColor);
this.specularColor.set(specularColor);
this.shinyness = shinyness;
}
public LightSource(LightSource light){
this.position = new Vector3();
this.ambientColor = new Color();
this.diffuseColor = new Color();
this.ambientColor = new Color();
this.specularColor = new Color();
set(light);
}
public void set(LightSource light){
this.position.set(light.getPosition());
this.ambientColor.set(light.getAmbientColor());
this.diffuseColor.set(light.getDiffuseColor());
this.specularColor.set(light.getSpecularColor());
this.shinyness = light.shinyness;
}
public void setPosition(float x, float y, float z){
position.set(x, y, z);
}
public void setPosition(Vector3 position){
this.position.set(position);
}
public void setAmbientColor(float r, float g, float b, float a){
ambientColor.set(r, g, b, a);
}
public void setAmbientColor(Color ambientColor){
this.ambientColor.set(ambientColor);
}
public void setDiffuseColor(float r, float g, float b, float a){
diffuseColor.set(r, g, b, a);
}
public void setdiffuseColor(Color diffuseColor){
this.diffuseColor.set(diffuseColor);
}
public void setSpecularColor(float r, float g, float b, float a){
specularColor.set(r, g, b, a);
}
public void setSpecularColor(Color specularColor){
this.specularColor.set(specularColor);
}
public void setShinyness(float shinyness) throws IllegalArgumentException {
if(shinyness <= 0.0 || shinyness > 128.0)
throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
this.shinyness = shinyness;
}
public Vector3 getPosition(){
return position;
}
public Color getAmbientColor(){
return ambientColor;
}
public Color getDiffuseColor(){
return diffuseColor;
}
public Color getSpecularColor(){
return specularColor;
}
public float getShinyness(){
return shinyness;
}
}

View File

@@ -1,75 +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.graphics;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
public abstract class RenderParameters {
private static Matrix4 modelViewProjection;
private static Matrix4 geometricTransformation;
private static Vector3 eyePosition;
private static LightSource lightSource1;
private static LightSource lightSource2;
static{
modelViewProjection = new Matrix4();
geometricTransformation = new Matrix4();
eyePosition = new Vector3(0.0f, 0.0f, 1.4142f);
lightSource1 = new LightSource();
lightSource2 = new LightSource();
}
public static synchronized void setModelViewProjectionMatrix(Matrix4 modelViewMatrix){
modelViewProjection.set(modelViewMatrix);
}
public static synchronized void setTransformationMatrix(Matrix4 transformationMatrix){
geometricTransformation.set(transformationMatrix);
}
public static synchronized void setEyePosition(Vector3 newEyePostition){
eyePosition.set(newEyePostition);
}
public static synchronized void setLightSource1(LightSource newLightSource1){
lightSource1.set(newLightSource1);
}
public static synchronized void setLightSource2(LightSource newLightSource2){
lightSource2.set(newLightSource2);
}
public static synchronized Matrix4 getModelViewProjectionMatrix(){
return modelViewProjection;
}
public static synchronized Matrix4 getTransformationMatrix(){
return geometricTransformation;
}
public static synchronized Vector3 getEyePosition(){
return eyePosition;
}
public static synchronized LightSource getLightSource1(){
return lightSource1;
}
public static synchronized LightSource getLightSource2(){
return lightSource2;
}
}

View File

@@ -30,7 +30,7 @@ import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.GdxRuntimeException;
public class SingleLightPerPixelShader implements Shader{
public class DirectionalLightPerPixelShader implements Shader{
private static final int MAX_NUM_BONES = 4;
private static final Matrix4 IDENTITY = new Matrix4();
private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl";
@@ -56,7 +56,7 @@ public class SingleLightPerPixelShader implements Shader{
private int[] u_normalMatrix;
private int[] u_bones;
public SingleLightPerPixelShader(){
public DirectionalLightPerPixelShader(){
skinningProgram = null;
baseProgram = null;
camera = null;
@@ -79,7 +79,7 @@ public class SingleLightPerPixelShader implements Shader{
throw new GdxRuntimeException(skinningProgram.getLog());
if(!baseProgram.isCompiled())
throw new GdxRuntimeException(skinningProgram.getLog());
throw new GdxRuntimeException(baseProgram.getLog());
// Create uniform locations.
u_projTrans = new int[2];
@@ -198,7 +198,7 @@ public class SingleLightPerPixelShader implements Shader{
// Set model dependant uniforms.
program.setUniformMatrix(u_geomTrans[index], renderable.worldTransform);
program.setUniformMatrix(u_normalMatrix[index], normalMatrix.idt().mul(renderable.worldTransform).inv().tra());
program.setUniformMatrix(u_normalMatrix[index], normalMatrix.set(renderable.worldTransform).toNormalMatrix());
program.setUniformf(u_lightPos[index], lightPosition);
program.setUniformf(u_lightDiffuse[index], diffuseLightColor);
program.setUniformf(u_materialDiffuse[index], diffuseColor);

View File

@@ -1,58 +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.graphics.shaders;
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public class SingleLightPhongShader extends CustomShaderBase{
private static String VERTEX_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl";
private static String FRAGMENT_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl";
@Override
public SingleLightPhongShader loadShader() throws ShaderFailedToLoadException{
shaderProgram = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER_PATH), Gdx.files.internal(FRAGMENT_SHADER_PATH));
if(!shaderProgram.isCompiled()){
throw new ShaderFailedToLoadException("SingleLightPerPixelPhongShader failed to load.\n" + shaderProgram.getLog());
}
return this;
}
@Override
public void setUniforms(){
LightSource light = RenderParameters.getLightSource1();
float[] diffuseColor = {light.getDiffuseColor().r, light.getDiffuseColor().g, light.getDiffuseColor().b, light.getDiffuseColor().a};
float[] ambientColor = {light.getAmbientColor().r, light.getAmbientColor().g, light.getAmbientColor().b, light.getAmbientColor().a};
float[] specularColor = {light.getSpecularColor().r, light.getSpecularColor().g, light.getSpecularColor().b, light.getSpecularColor().a};
float[] position = {light.getPosition().x, light.getPosition().y, light.getPosition().z, 0.0f};
float[] shinyness = {light.getShinyness()};
shaderProgram.setUniformMatrix("u_projTrans", RenderParameters.getModelViewProjectionMatrix());
shaderProgram.setUniformMatrix("u_geomTrans", RenderParameters.getTransformationMatrix());
shaderProgram.setUniform4fv("u_lightPos", position, 0, 4);
shaderProgram.setUniform4fv("u_lightDiffuse", diffuseColor, 0, 4);
shaderProgram.setUniform4fv("u_specular", specularColor, 0, 4);
shaderProgram.setUniform4fv("u_ambient", ambientColor, 0, 4);
shaderProgram.setUniform1fv("u_shiny", shinyness, 0, 1);
shaderProgram.setUniformf("u_cameraPos", RenderParameters.getEyePosition());
}
}

View File

@@ -19,11 +19,7 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
@@ -31,6 +27,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
import com.artemis.World;
@@ -38,7 +35,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.mappings.Ouya;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Pixmap;
@@ -63,11 +59,6 @@ public class InGameState extends BaseState{
private static final float FAR = 100.0f;
private static final float FAR_PLUS_NEAR = FAR + NEAR;
private static final float FAR_LESS_NEAR = FAR - NEAR;
private static final Vector3 LIGHT_POSITION = new Vector3(2.0f, 2.0f, 4.0f);
private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.3f, 1.0f);
private static final Color DIFFUSE_COLOR = new Color(1.0f, 1.0f, 1.0f, 1.0f);
private static final Color SPECULAR_COLOR = new Color(1.0f, 0.8f, 0.0f, 1.0f);
private static final float SHINYNESS = 50.0f;
// Background related fields.
private float uScaling[];
@@ -83,7 +74,6 @@ public class InGameState extends BaseState{
// Game world objects.
private World gameWorld;
private EntityCreatorBase entityCreator;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
@@ -188,17 +178,18 @@ public class InGameState extends BaseState{
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
RenderParameters.setLightSource1(new LightSource(LIGHT_POSITION, AMBIENT_COLOR, DIFFUSE_COLOR, SPECULAR_COLOR, SHINYNESS));
// Set up the game world.
gameWorld = new World();
entityCreator = new MarkerTestEntityCreator();
entityCreator.setWorld(gameWorld);
entityCreator.createAllEntities();
GameSettings.initGameSettings();
GameSettings.entityCreator.setWorld(gameWorld);
GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new AnimationSystem());
// TODO: Add collision system.
//gameWorld.setSystem(GameSettings.gameLogicSystem);
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
@@ -313,8 +304,6 @@ public class InGameState extends BaseState{
// Set rendering parameters.
perspectiveCamera.update(projectionMatrix, true);
RenderParameters.setModelViewProjectionMatrix(perspectiveCamera.combined);
RenderParameters.setEyePosition(perspectiveCamera.position);
// Call rendering systems.
markerRenderingSystem.begin(perspectiveCamera, data);
@@ -395,8 +384,8 @@ public class InGameState extends BaseState{
if(modelBatch != null)
modelBatch.dispose();
if(entityCreator != null)
entityCreator.dispose();
if(GameSettings.entityCreator != null)
GameSettings.entityCreator.dispose();
if(videoFrameTexture != null)
videoFrameTexture.dispose();

View File

@@ -13,15 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ve.ucv.ciens.ccg.nxtar.components;
package ve.ucv.ciens.ccg.nxtar.systems;
import com.artemis.Component;
import com.badlogic.gdx.graphics.Mesh;
import com.artemis.Aspect;
import com.artemis.Entity;
public class MeshComponent extends Component {
public Mesh model;
public MeshComponent(Mesh model){
this.model = model;
public class BombGameLogicSystem extends GameLogicSystemBase {
@SuppressWarnings("unchecked")
public BombGameLogicSystem(){
super(Aspect.getAspectForAll(null));
}
@Override
protected void process(Entity e){
}
}

View File

@@ -13,19 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ve.ucv.ciens.ccg.nxtar.components;
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
import com.artemis.Aspect;
import com.artemis.Entity;
import com.artemis.systems.EntityProcessingSystem;
import com.artemis.Component;
public abstract class GameLogicSystemBase extends EntityProcessingSystem {
public class CustomShaderComponent extends Component {
public CustomShaderBase shader;
public CustomShaderComponent(CustomShaderBase shader) throws IllegalArgumentException{
if(shader == null)
throw new IllegalArgumentException("Shader cannot be null.");
this.shader = shader;
public GameLogicSystemBase(Aspect aspect){
super(aspect);
}
@Override
protected abstract void process(Entity e);
}

View File

@@ -13,20 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ve.ucv.ciens.ccg.nxtar.graphics.shaders;
package ve.ucv.ciens.ccg.nxtar.utils;
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
public abstract class GameSettings{
public static EntityCreatorBase entityCreator = null;
public static GameLogicSystemBase gameLogicSystem = null;
public abstract class CustomShaderBase{
protected ShaderProgram shaderProgram;
public abstract CustomShaderBase loadShader() throws ShaderFailedToLoadException;
public abstract void setUniforms();
public ShaderProgram getShaderProgram(){
return this.shaderProgram;
public static void initGameSettings(){
entityCreator = new MarkerTestEntityCreator();
gameLogicSystem = null;
//gameLogicSystem = new BombGameLogicSystem();
}
}