Skip to content

Instantly share code, notes, and snippets.

View erlend-sh's full-sized avatar
🐠
Working on Fish Folk

Erlend Sogge Heggen erlend-sh

🐠
Working on Fish Folk
View GitHub Profile
@erlend-sh
erlend-sh / jmonkeyengine hub css
Created September 23, 2015 11:46
jmonkeyengine hub css
//overrides all fonts
@import url(http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,300,400,800,700);
html * {
font-family: "Open Sans", Helvetica, arial,sans-serif;
}
//code font for this text area
.ace_scroller{
font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace;
}
@erlend-sh
erlend-sh / jme-head-footer
Created September 23, 2015 11:47
jmonkeyengine head and footer
@erlend-sh
erlend-sh / Timer or delay
Created December 4, 2012 13:38
jMonkeyEngine: Simple timer or delay using Timer.getTimeInSeconds()
/**
* Several forum topics in the past have asked about how to implement
* a timer or delay without using an Appstate or Control or an extra
* thread, which may be overkill for simple purposes such as delaying
* input into an Analog Listener (say, holding down a button to increment
* an integer value). I use getTimeInSeconds() here because getTime()
* returns ticks, and so you get unexpected behaviour like the timer
* counting 9.8 -> 9.9 -> 1.0 -> 1.1 etc.
*/
@erlend-sh
erlend-sh / LittleLevelState
Created December 4, 2012 13:42
jMonkeyEngine: LittleLevelState
class LittleLevelState  implements Savable{
    private WorldNode littleWorld1;
    private WorldNode littleWorld2;
 
 
 
    public LittleLevelState(WorldNode littleWorld1, WorldNode littleWorld2) {      
        this.littleWorld1 = littleWorld1;
        this.littleWorld2 = littleWorld2;
         
@erlend-sh
erlend-sh / Pong
Created December 4, 2012 13:45
jMonkeyEngine: Pong - Something to collide with
public class Main extends SimpleApplication {
     
    public ArrayList<BaseEntity> entities = new ArrayList<BaseEntity>();
    public ArrayList<Spatial> blocks = new ArrayList<Spatial>();
     
    public Player player;
     
    public static void main(String[] args) {
        AppSettings settings= new AppSettings(true);
        settings.setTitle("jMonkey Pong 3D");
@erlend-sh
erlend-sh / Standard RGB To OpenGL conversion
Created December 4, 2012 13:46
jMonkeyEngine: Standard RGB To OpenGL conversion - Those two functions will convert RGB values in 0-255 format to OpenGL format (0-1.0 floats).
public static float[] RGBToOpenGL(int r1, int g1, int b1) {
    float[] tmp = new float[3];
    tmp[0] = r1/255f;
    tmp[1] = g1/255f;
    tmp[2] = b1/255f;
    return tmp;
}
public static float[] RGBAToOpenGL(int r1, int g1, int b1, int a1) {
    float[] tmp = new float[4];
    tmp[0] = r1/255f;
@erlend-sh
erlend-sh / WorldNode relevant code
Created December 4, 2012 13:42
jMonkeyEngine: WorldNode relevant code
public class WorldNode extends Node {
 
    @Override
    public void read(JmeImporter e) throws IOException {
        super.read(e);
        InputCapsule capsule=e.getCapsule(this);
        enemies=(Node) capsule.readSavable("Enemies", new Node());
        staticObjects=(Node) capsule.readSavable("StaticObjects", new Node());
        powerUps=(Node) capsule.readSavable("PowerUps", new Node());
        sky=(Geometry) capsule.readSavable("Sky", new Geometry());
@erlend-sh
erlend-sh / Falling Vehicles
Created December 10, 2012 18:20
jMonkeyEngine: Falling Vehicles - SimpleApp with two falling vehicles and a falling cube. Illustrates tunneling through the terrain with ray cast vehicle.
public class Main extends SimpleApplication {
    static final float START_Y = 150f ;
 
    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }
 
    @Override
    public void simpleInitApp() {
@erlend-sh
erlend-sh / Create a static accessor for the Application
Created December 10, 2012 18:27
jMonkeyEngine: Create a static accessor for your SimpleApplication so that it can be accessed globally. Use MySimpleApplication.getApplication() from anywhere to access.
public class MySimpleApplication extends SimpleApplication{
    private static MySimpleApplication staticApplication;
 
    public MySimpleApplication(){
        staticApplication = this;
    }
 
    public static MySimpleApplication getApplication(){
        return staticApplication;
    }
@erlend-sh
erlend-sh / Load a model and get a sub-item
Created December 10, 2012 18:31
Loads a model and gets a sub-item to perform operations on it.
Node model=(Node)assetManager.loadModel("Models/myModel.j3o");
Geometry geom=(Geometry)model.getChild("myGeometry");
geom.setMaterial(myMaterial);