env3d
Class EnvBasic

java.lang.Object
  extended by com.jme3.app.Application
      extended by env3d.EnvBasic
All Implemented Interfaces:
com.jme3.system.SystemListener
Direct Known Subclasses:
Env, EnvAndroid

public class EnvBasic
extends com.jme3.app.Application

Env stands for environment and is the entry point to interface with the opengl engine class. This class is written to provide students with a way to access a virtual environment. Students can put any arbitrary objects into this world. This class make exclusive use of reflection so that any object can be added without the object having to extend another class or implement an interface. This makes teaching introduction courses much easier as students do not have to be exposed to the idea of inheritance right away. This class also provide a way to access to the camera as well as access the keyboard.


Field Summary
protected  java.util.HashMap<java.lang.String,com.jme3.audio.AudioNode> audioMap
           
protected  EnvCamera flyCam
           
protected  com.jme3.font.BitmapFont guiFont
           
protected  com.jme3.scene.Node guiNode
           
protected  boolean init
           
protected  java.util.HashMap<java.lang.String,java.lang.Object> internalObjects
           
protected  java.util.HashMap<java.lang.Object,GameObjectAdapter> objectsMap
           
protected  RoomAdapter roomObject
           
protected  com.jme3.scene.Node rootNode
           
protected  com.jme3.scene.Node statusNode
           
protected  com.jme3.font.BitmapText statusText
           
protected  float tpf
           
 
Fields inherited from class com.jme3.app.Application
assetManager, audioRenderer, cam, context, guiViewPort, inputEnabled, inputManager, joyInput, keyInput, listener, mouseInput, paused, pauseOnFocus, renderer, renderManager, settings, speed, stateManager, timer, touchInput, viewPort
 
Constructor Summary
EnvBasic()
          Create an environment.
EnvBasic(boolean defaultControl)
          Creates a 3d environment.
 
Method Summary
 void addObject(java.lang.Object obj)
          Add an object to the environment
 void destroy()
           
 void disableLighting()
          Disable light effect
 void enableLighting()
          Enable the lighting effect.
 void exit()
          Exit the program cleanly.
 double getCameraPitch()
          Get the pitch (up and down) angle of the camera, in degrees.
 double getCameraX()
           
 double getCameraY()
           
 double getCameraYaw()
          Get the yaw (up and down) angle of the camera, in degrees.
 double getCameraZ()
           
 de.lessvoid.nifty.Nifty getNiftyGUI()
          Returns the nifty gui object for GUI programming
<T> T
getObject(java.lang.Class<T> c)
          Returns the first object that matches class c
 java.util.Collection getObjects()
          Get all the objects that has been added to the environment
<T> java.util.Collection<T>
getObjects(java.lang.Class<T> c)
          Returns all objects of class c
 java.lang.Object getPick(int x, int y)
          Get the closest object that is under the current mouse position.
 java.util.List<EnvPickResult> getPickList(int x, int y)
           
 EnvRay getPickRay(int x, int y)
           
 com.jme3.scene.Node getRootNode()
          Returns the root node of the underlying scene graph.
 double getVolume()
          Get the current sound level
 void initialize()
           
 boolean isDefaultControl()
           
 boolean isLightingEnabled()
          Check if lighting is enabled or not
 void removeObject(java.lang.Object obj)
          Removes an object from the environment
 void setCameraPitch(double angle)
          Sets the camera pitch (up and down) in degrees in relation to the default camera orientation (0, 0, -1)
 void setCameraXYZ(double x, double y, double z)
          Put the camera at a particular location in 3D space.
 void setCameraYaw(double angle)
          Sets the camera yaw (left and right) in degrees in relation to the default camera orientation (0, 0, -1)
 void setDefaultControl(boolean firstPersonControl)
          Activate the first person control scheme.
 void setDisplayStr(java.lang.String displayStr)
          Display a string in the middle of the screen
 void setDisplayStr(java.lang.String displayStr, int x, int y)
          Puts a string at a particular location on screen
 void setDisplayStr(java.lang.String displayStr, int x, int y, double size, double r, double g, double b, double a)
          Put a string in a particular location on screen.
 void setRoom(java.lang.Object o)
          Sets the current room.
 void setShowStatus(boolean show)
          Show the current fps (frames per second) on screen
 void setVolume(double level)
          Sets the current sound level
 void soundLoad(java.lang.String soundFile)
          Load sound into memory
 void soundLoop(java.lang.String soundFile)
          Loop a sound file.
 void soundPlay(java.lang.String soundFile)
          Play a sound file without position.
 void soundPlay(java.lang.String soundFile, double x, double y, double z, double cutoff_distance)
          Play a sound file at a particular location
 void soundStop(java.lang.String soundFile)
          Stop a sound file.
 void start(com.jme3.system.JmeContext.Type contextType)
           
 void update()
           
 
Methods inherited from class com.jme3.app.Application
createCanvas, destroyInput, enqueue, gainFocus, getAssetManager, getAudioRenderer, getCamera, getContext, getGuiViewPort, getInputManager, getListener, getRenderer, getRenderManager, getStateManager, getTimer, getViewPort, handleError, isPauseOnLostFocus, loseFocus, requestClose, reshape, restart, runQueuedTasks, setAssetManager, setPauseOnLostFocus, setSettings, setTimer, start, startCanvas, startCanvas, stop, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

init

protected boolean init

rootNode

protected com.jme3.scene.Node rootNode

guiNode

protected com.jme3.scene.Node guiNode

statusNode

protected com.jme3.scene.Node statusNode

guiFont

protected com.jme3.font.BitmapFont guiFont

tpf

protected float tpf

objectsMap

protected java.util.HashMap<java.lang.Object,GameObjectAdapter> objectsMap

internalObjects

protected java.util.HashMap<java.lang.String,java.lang.Object> internalObjects

audioMap

protected java.util.HashMap<java.lang.String,com.jme3.audio.AudioNode> audioMap

roomObject

protected RoomAdapter roomObject

flyCam

protected EnvCamera flyCam

statusText

protected com.jme3.font.BitmapText statusText
Constructor Detail

EnvBasic

public EnvBasic()
Create an environment. The default is to have the environment take control of the mouse.


EnvBasic

public EnvBasic(boolean defaultControl)
Creates a 3d environment.

Parameters:
defaultControl - true to grab the mouse, false to release the mouse
Method Detail

addObject

public void addObject(java.lang.Object obj)
Add an object to the environment

Parameters:
obj -

removeObject

public void removeObject(java.lang.Object obj)
Removes an object from the environment

Parameters:
obj -

getObjects

public java.util.Collection getObjects()
Get all the objects that has been added to the environment

Returns:

getObjects

public <T> java.util.Collection<T> getObjects(java.lang.Class<T> c)
Returns all objects of class c

Type Parameters:
T -
Parameters:
c -
Returns:

getObject

public <T> T getObject(java.lang.Class<T> c)
Returns the first object that matches class c

Type Parameters:
T -
Parameters:
c -
Returns:

setRoom

public void setRoom(java.lang.Object o)
Sets the current room. Calling this will remove all the objects in the current room.

Parameters:
o - the room object

setCameraXYZ

public void setCameraXYZ(double x,
                         double y,
                         double z)
Put the camera at a particular location in 3D space. The camera looks down the z axis by default. i.e. (0, 0, -1)

Parameters:
x - x coordinate of the camera
y - y coordinate of the camera
z - z coordinate of the camera

getCameraX

public double getCameraX()
Returns:
the x location of the camera

getCameraY

public double getCameraY()
Returns:
the y location of the camera

getCameraZ

public double getCameraZ()
Returns:
the z location of the camera

getCameraPitch

public double getCameraPitch()
Get the pitch (up and down) angle of the camera, in degrees. This is in relation to the default camera orientation (0, 0, -1)

Returns:
the camera pitch in degrees

getCameraYaw

public double getCameraYaw()
Get the yaw (up and down) angle of the camera, in degrees. This is in relation to the default camera orientation (0, 0, -1)

Returns:
the camera yaw in degrees

setCameraPitch

public void setCameraPitch(double angle)
Sets the camera pitch (up and down) in degrees in relation to the default camera orientation (0, 0, -1)

Parameters:
angle - the angle to set the pitch to, in degrees

setCameraYaw

public void setCameraYaw(double angle)
Sets the camera yaw (left and right) in degrees in relation to the default camera orientation (0, 0, -1)

Parameters:
angle - the angle to set the pitch to, in degrees

setDisplayStr

public void setDisplayStr(java.lang.String displayStr,
                          int x,
                          int y,
                          double size,
                          double r,
                          double g,
                          double b,
                          double a)
Put a string in a particular location on screen.

Parameters:
displayStr -
x - x location of the screen (2D)
y - y location of the screen (2D)
size - the size of the font
r - red component. Value from 0 - 1.
g - green component. Value from 0 - 1.
b - blue component. Value from 0 - 1.
a - alpha component. Value from 0 - 1. 0 is invisible. 1 is opaque.

setDisplayStr

public void setDisplayStr(java.lang.String displayStr,
                          int x,
                          int y)
Puts a string at a particular location on screen

Parameters:
displayStr -
x -
y -
See Also:
setDisplayStr(java.lang.String, int, int, double, double, double, double, double)

setDisplayStr

public void setDisplayStr(java.lang.String displayStr)
Display a string in the middle of the screen

Parameters:
displayStr -
See Also:
setDisplayStr(java.lang.String, int, int, double, double, double, double, double)

setShowStatus

public void setShowStatus(boolean show)
Show the current fps (frames per second) on screen

Parameters:
show - true to show fps, false to hide it.

setDefaultControl

public void setDefaultControl(boolean firstPersonControl)
Activate the first person control scheme. Uses W, A, S, D for movement and the mouse to look around. SPACE and C are used to move the camera up and down.

Parameters:
firstPersonControl - true to enable first person control, false to disable it.

isDefaultControl

public boolean isDefaultControl()

getVolume

public double getVolume()
Get the current sound level

Returns:
the sound level, a value between 0 and 1.

setVolume

public void setVolume(double level)
Sets the current sound level

Parameters:
level - a number between 0 and 1.

soundPlay

public void soundPlay(java.lang.String soundFile,
                      double x,
                      double y,
                      double z,
                      double cutoff_distance)
Play a sound file at a particular location

Parameters:
soundFile - the file to play
x - x location of the sound
y - y location of the sound
z - z location of the sound
cutoff_distance - the distance in which sound will be cut off

soundPlay

public void soundPlay(java.lang.String soundFile)
Play a sound file without position.

Parameters:
soundFile -

soundLoop

public void soundLoop(java.lang.String soundFile)
Loop a sound file. This method is meant for background music and it streams the sound from the source.

Parameters:
soundFile -

soundStop

public void soundStop(java.lang.String soundFile)
Stop a sound file.

Parameters:
soundFile -

soundLoad

public void soundLoad(java.lang.String soundFile)
Load sound into memory

Parameters:
soundFile - the file to load

getPick

public java.lang.Object getPick(int x,
                                int y)
Get the closest object that is under the current mouse position. Use the getMousePicList() method to return the entire list of objects under the mouse, as well as the 3D position of each intersection.

Returns:
the first object directly under the mouse position, null if no object is picked

getPickList

public java.util.List<EnvPickResult> getPickList(int x,
                                                 int y)

getPickRay

public EnvRay getPickRay(int x,
                         int y)

enableLighting

public void enableLighting()
Enable the lighting effect. The light is a directional light that comes from the camera


disableLighting

public void disableLighting()
Disable light effect


isLightingEnabled

public boolean isLightingEnabled()
Check if lighting is enabled or not

Returns:
true if lighting is currently enabled, false otherwise.

getRootNode

public com.jme3.scene.Node getRootNode()
Returns the root node of the underlying scene graph.

Returns:

getNiftyGUI

public de.lessvoid.nifty.Nifty getNiftyGUI()
Returns the nifty gui object for GUI programming

Returns:

exit

public void exit()
Exit the program cleanly.


start

public void start(com.jme3.system.JmeContext.Type contextType)
Overrides:
start in class com.jme3.app.Application

initialize

public void initialize()
Specified by:
initialize in interface com.jme3.system.SystemListener
Overrides:
initialize in class com.jme3.app.Application

update

public void update()
Specified by:
update in interface com.jme3.system.SystemListener
Overrides:
update in class com.jme3.app.Application

destroy

public void destroy()
Specified by:
destroy in interface com.jme3.system.SystemListener
Overrides:
destroy in class com.jme3.app.Application