JMECanvasImpl

Hi all,



I have seen and worked with SimpleCanvasImpl (shown in SceneEditorDemo.java) and found it really useful with my application… though I found it was only extended from JMECanvasImplementor, and I'd like to create a new implementation where my Canvas would support MultiThreading / GameStates…



Could anyone here show me how to do this?.. I mean, how can I configure JMECanvasImplementor to be ready for GameStateManager…

heya there sbook… could you tell me how to do that? cause my InputHandler doesn't behave exactly as the one I've experienced in SimpleGame

Hey mhelz,



We were using StandardGame + JMECanvasImplementor for a few months for the Betaville project but eventually got away from it and went the OpenGL GUI route (not an easy task either with StandardGame).



What we used was/is known as StandardCanvasGame.  It definitely worked, but people were drawn to the allure of transparent windows sitting on top of the scene, so the canvas implementation went buh-bye :wink:

well I haven't been allured yet by the fascination towards those transparent windows :D… since I've been working with a simple Swing Project for my thesis… I don't need that much of a fuss… I'll be looking at this StandardCanvas today… thank you very much sbook for directing me to this link :smiley:

is it just me or StandardCanvas's FirstPersonHandler is different than of other Canvas?.. I mean when you point the mouse to the left… the camera does not turn left but rotates left instead



edit:



okay, I get it



looks like this statement in the stateUpdate(float tpf) method messes up things



input.update(tpf);



how do I implement an inputhandler in my gamestate without going through that mess?

:smiley: ok another "my bad"… it seems I just had to add



cam.update();



in my stateUpdate(float tpf) method...
mhelz0001 said:

:D ok another "my bad"... it seems I just had to add


cam.update();



in my stateUpdate(float tpf) method...


I usually use a controller attached to a node and that's where I have my InputHandler's....  It should operate identically to using SimpleGame

Hey,



Sorry for not getting back to you sooner, I haven't had a free minute all day to do much of anything.  Ironically, most of the time was spent talking about jME… its a shame I couldn't pop on the forum :stuck_out_tongue:





Anyway, here's a simple controller which you would add to a node in your scene, like rootNode, with (I know you like StandardGame, so this example creates the controller inside of a GameState):


// Inside of your GameState
MyController controller = new MyController(this);
rootNode.addController(controller);




I just ripped this out of Eclipse and edited in the webpage, so there's a bunch of imports that you won't need.  I stripped it down to the bare essentials of what it means to be a controller :)


/**
 * Copyright 2008-2010 Brooklyn eXperimental Media Center
 * Betaville Project by Brooklyn eXperimental Media Center at NYU-Poly
 * http://bxmc.poly.edu
 */
package edu.poly.bxmc.betaville.jme.controllers;

import static com.jme.input.KeyInput.*;

import java.util.logging.Logger;

import com.jme.bounding.BoundingBox;
import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.MouseInput;
import com.jme.input.controls.GameControlManager;
import com.jme.input.controls.binding.KeyAndMouseButtonBinding;
import com.jme.input.controls.binding.KeyboardBinding;
import com.jme.input.controls.binding.MouseButtonBinding;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Arrow;
import com.jme.scene.shape.Box;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.WireframeState;
import com.jme.scene.state.ZBufferState;
import com.jme.scene.state.RenderState.StateType;
import com.jme.system.DisplaySystem;
import com.jmex.game.state.GameStateManager;

import edu.poly.bxmc.betaville.jme.gamestates.SceneGameState;
import edu.poly.bxmc.betaville.jme.gamestates.SoundGameState;
import edu.poly.bxmc.betaville.jme.intersections.MousePicking;
import edu.poly.bxmc.betaville.jme.map.DecimalDegreeConverter;
import edu.poly.bxmc.betaville.jme.map.Scale;
import edu.poly.bxmc.betaville.model.GPSCoordinate;

/**
 * The controller used to modify SceneGameState
 * through user interaction and environmental
 * changes.
 * @author Skye Book
 *
 */
public class SceneController extends Controller {

   private float moveSpeed = 750

   private float turnSpeed = 1.5f;

   private FirstPersonHandler firstPersonHandler;


   private Node selectedNode;
   private GameState gameState;

   /**
    *
    */
   public SceneController(GameState sceneGameState) {
      this.gameState = sceneGameState;
      // set up the basic movement controls
      firstPersonHandler = new FirstPersonHandler(
            DisplaySystem.getDisplaySystem().getRenderer().getCamera(),
            moveSpeed,
            turnSpeed);
      firstPersonHandler.setButtonPressRequired(true);
      firstPersonHandler.getMouseLookHandler().getMouseLook().setMouseButtonForRequired(2);
         }
   


   /**
    * @param moveSpeed the moveSpeed to set
    */
   public void setMoveSpeed(float moveSpeed) {
      this.moveSpeed = moveSpeed;
   }

   /**
    * @return the turnSpeed
    */
   public float getTurnSpeed() {
      return turnSpeed;
   }

   /**
    * @param turnSpeed the turnSpeed to set
    */
   public void setTurnSpeed(float turnSpeed){
      this.turnSpeed = turnSpeed;
   }

   @Override
   public void update(float time){
      firstPersonHandler.update(time);
      
   }
}

bumpy dumpy :smiley: :smiley: :smiley:

hi sbook… I've used your code and successfully implemented controllers to my gamestate



the keyboardlook handler seems ok… but the mouselookhandler acts crazy…



I haven't changed anything in your code other than


firstPersonHandler.getMouseLookHandler().getMouseLook().setMouseButtonForRequired(0);



to set it on the left mouse click....other than that nothing has changed...

Yeah, having the turn speed set to 1.5f is probably a bit crazy :D  Play with that value a bit to get something more manageable… try in the area of .5f

yes, that helped a bit on the craziness… but it doesn't act like the one on SimpleGame… anyway, while I was browsing the jme package… I learned that the behavior on my mouselook right now is somewhat the same as with the one using MouseOffsetBinding… and I tried to tweak through the code of TestMouseOffsetBinding.java and replaced the MouseOffsetBinding to MouseAxisBinding… and that works just like the one in SimpleGame… come to think of it… if I could only add that to my controller…