package edu.ups.gamedev.player;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
/**
* A colored <code>Sphere</code> that represents a player in a game. Like
* all jMonkey <code>Spatial</code>s, it must have a name. Furthermore, it
* must have a color and may be given a default starting location.
*
* @author Walker Lindley
* @version $Revision: 1.1 $, $Date: 2008/01/26 08:13:22 $
*
* @see com.jme.scene.Spatial Spatial
* @see com.jme.scene.shape.Sphere Sphere
*
*/
public class PlayerSphere extends Sphere {
private static final long serialVersionUID = 1L;
private ColorRGBA color;
/**
* Constructor specifying name, color, and starting position.
*
* @param name the string containing this <code>Sphere</code>'s
* name
* @param color the color of the sphere
* @param pos the vector pointing to this <code>Sphere</code>'s
* starting position
*
* @see com.jme.renderer.ColorRGBA ColorRGBA
* @see com.jme.math.Vector3f Vector3f
*/
public PlayerSphere(String name, ColorRGBA color, Vector3f pos) {
super(name, 15, 15, 1); //the 15s tell us how many triangles to use and the 1 is the radius
this.color = color; //save the color for use later
setLocalTranslation(pos); //move the sphere to the location provided.
setModelBound(new BoundingSphere()); //create a bounding sphere for the sphere
updateModelBound(); //automatically resize the bounding sphere
MaterialState material = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); //use a factory method to generate a new material
material.setDiffuse(color); //set it's diffuse color (when light hits it) to red
//material.setEmissive(color); //set it's emmissive color (light it gives off) to red
setRenderState(material); //apply the material we've created to the sphere
}
/**
* Constructor specifying name and color.
*
* @param name the string containing this <code>Sphere</code>'s
* name
* @param color the color of the sphere
*
* @see com.jme.renderer.ColorRGBA ColorRGBA
* @see com.jme.math.Vector3f Vector3f
*/
public PlayerSphere(String name, ColorRGBA color) {
this(name, color, new Vector3f(0, 0, 0));
}
/**
* Returns the color of this <code>PlayerSphere</code>.
*
* @return the color
*/
public ColorRGBA getColor() {
return color;
}
/**
* Sets the color of this <code>PlayerSphere</code>.
*
* @param color the color to set
*/
public void setColor(ColorRGBA color) {
this.color = color;
}
}