Java Code Examples for com.jme3.math.Vector3f#UNIT_XYZ

The following examples show how to use com.jme3.math.Vector3f#UNIT_XYZ . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhysicsCollisionObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a visual debug shape of the current collision shape of this physics object<br/>
 * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
 * @param manager AssetManager to load the default wireframe material for the debug shape
 */
protected Spatial attachDebugShape(AssetManager manager) {
    debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
    debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
    debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
    debugMaterialGreen.setColor("Color", ColorRGBA.Green);
    debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialRed.getAdditionalRenderState().setWireframe(true);
    debugMaterialRed.setColor("Color", ColorRGBA.Red);
    debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
    debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
    debugArrow = new Arrow(Vector3f.UNIT_XYZ);
    debugArrowGeom = new Geometry("DebugArrow", debugArrow);
    debugArrowGeom.setMaterial(debugMaterialGreen);
    return attachDebugShape();
}
 
Example 2
Source File: PhysicsCollisionObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a visual debug shape of the current collision shape of this physics object<br/>
 * <b>Does not work with detached physics, please switch to PARALLEL or SEQUENTIAL for debugging</b>
 * @param manager AssetManager to load the default wireframe material for the debug shape
 */
protected Spatial attachDebugShape(AssetManager manager) {
    debugMaterialBlue = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialBlue.getAdditionalRenderState().setWireframe(true);
    debugMaterialBlue.setColor("Color", ColorRGBA.Blue);
    debugMaterialGreen = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialGreen.getAdditionalRenderState().setWireframe(true);
    debugMaterialGreen.setColor("Color", ColorRGBA.Green);
    debugMaterialRed = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialRed.getAdditionalRenderState().setWireframe(true);
    debugMaterialRed.setColor("Color", ColorRGBA.Red);
    debugMaterialYellow = new Material(manager, "Common/MatDefs/Misc/Unshaded.j3md");
    debugMaterialYellow.getAdditionalRenderState().setWireframe(true);
    debugMaterialYellow.setColor("Color", ColorRGBA.Yellow);
    debugArrow = new Arrow(Vector3f.UNIT_XYZ);
    debugArrowGeom = new Geometry("DebugArrow", debugArrow);
    debugArrowGeom.setMaterial(debugMaterialGreen);
    return attachDebugShape();
}
 
Example 3
Source File: TestIssue889.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);

    BulletAppState bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(true);
    bulletAppState.setSpeed(0f);
    stateManager.attach(bulletAppState);
    PhysicsSpace space = bulletAppState.getPhysicsSpace();

    float radius = 1f;
    CollisionShape sphere = new SphereCollisionShape(radius);
    CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ);

    RigidBodyControl rbc = new RigidBodyControl(box);
    rbc.setEnabled(false);
    rbc.setPhysicsSpace(space);
    rootNode.addControl(rbc);

    BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f);
    bcc.setEnabled(false);
    bcc.setPhysicsSpace(space);
    rootNode.addControl(bcc);

    GhostControl gc = new GhostControl(sphere);
    gc.setEnabled(false);
    gc.setPhysicsSpace(space);
    rootNode.addControl(gc);
}
 
Example 4
Source File: DebugTools.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Render all the debug geometries to the specified view port.
 *
 * @param rm the render manager (not null)
 * @param vp the view port (not null)
 */
public void show(RenderManager rm, ViewPort vp) {
    if (!Vector3f.UNIT_X.equals(UNIT_X_CHECK) || !Vector3f.UNIT_Y.equals(UNIT_Y_CHECK) || !Vector3f.UNIT_Z.equals(UNIT_Z_CHECK)
            || !Vector3f.UNIT_XYZ.equals(UNIT_XYZ_CHECK) || !Vector3f.ZERO.equals(ZERO_CHECK)) {
        throw new IllegalStateException("Unit vectors compromised!"
                + "\nX: " + Vector3f.UNIT_X
                + "\nY: " + Vector3f.UNIT_Y
                + "\nZ: " + Vector3f.UNIT_Z
                + "\nXYZ: " + Vector3f.UNIT_XYZ
                + "\nZERO: " + Vector3f.ZERO);
    }
    debugNode.updateLogicalState(0);
    debugNode.updateGeometricState();
    rm.renderScene(debugNode, vp);
}
 
Example 5
Source File: PhysicsCollisionObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Spatial attachDebugShape(Material material) {
    debugMaterialBlue = material;
    debugMaterialGreen = material;
    debugMaterialRed = material;
    debugMaterialYellow = material;
    debugArrow = new Arrow(Vector3f.UNIT_XYZ);
    debugArrowGeom = new Geometry("DebugArrow", debugArrow);
    debugArrowGeom.setMaterial(debugMaterialGreen);
    return attachDebugShape();
}
 
Example 6
Source File: PhysicsCollisionObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected Spatial attachDebugShape(Material material) {
    debugMaterialBlue = material;
    debugMaterialGreen = material;
    debugMaterialRed = material;
    debugMaterialYellow = material;
    debugArrow = new Arrow(Vector3f.UNIT_XYZ);
    debugArrowGeom = new Geometry("DebugArrow", debugArrow);
    debugArrowGeom.setMaterial(debugMaterialGreen);
    return attachDebugShape();
}
 
Example 7
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public boolean doCheckVehicle(Node rootNode) {
    VehicleControl control = rootNode.getControl(VehicleControl.class);
    if (control == null) {
        vehicleControl = new VehicleControl(new BoxCollisionShape(Vector3f.UNIT_XYZ), 200);
        vehicleControl.createDebugShape(SceneApplication.getApplication().getAssetManager());
        rootNode.addControl(vehicleControl);
        return true;
    } else {
        vehicleControl = control;
        vehicleControl.createDebugShape(SceneApplication.getApplication().getAssetManager());
        return false;
    }
}
 
Example 8
Source File: TerrainGrid.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public TerrainGrid(String name, int patchSize, int maxVisibleSize, TerrainGridTileLoader terrainQuadGrid) {
    this(name, patchSize, maxVisibleSize, Vector3f.UNIT_XYZ, terrainQuadGrid);
}
 
Example 9
Source File: TestSpatialAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {

    AmbientLight al = new AmbientLight();
    rootNode.addLight(al);

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(Vector3f.UNIT_XYZ.negate());
    rootNode.addLight(dl);

    // Create model
    Box box = new Box(1, 1, 1);
    Geometry geom = new Geometry("box", box);
    geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
    Node model = new Node("model");
    model.attachChild(geom);

    Box child = new Box(0.5f, 0.5f, 0.5f);
    Geometry childGeom = new Geometry("box", child);
    childGeom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
    Node childModel = new Node("childmodel");
    childModel.setLocalTranslation(2, 2, 2);
    childModel.attachChild(childGeom);
    model.attachChild(childModel);
    
    //animation parameters
    float animTime = 5;
    int fps = 25;
    float totalXLength = 10;
    
    //calculating frames
    int totalFrames = (int) (fps * animTime);
    float dT = animTime / totalFrames, t = 0;
    float dX = totalXLength / totalFrames, x = 0;
    float[] times = new float[totalFrames];
    Vector3f[] translations = new Vector3f[totalFrames];
    Quaternion[] rotations = new Quaternion[totalFrames];
    Vector3f[] scales = new Vector3f[totalFrames];
    for (int i = 0; i < totalFrames; ++i) {
            times[i] = t;
            t += dT;
            translations[i] = new Vector3f(x, 0, 0);
            x += dX;
            rotations[i] = Quaternion.IDENTITY;
            scales[i] = Vector3f.UNIT_XYZ;
    }
    TransformTrack transformTrack = new TransformTrack(geom, times, translations, rotations, scales);
    TransformTrack transformTrackChild = new TransformTrack(childGeom, times, translations, rotations, scales);
    // creating the animation
    AnimClip animClip = new AnimClip("anim");
    animClip.setTracks(new AnimTrack[] { transformTrack, transformTrackChild });

    // create spatial animation control
    AnimComposer animComposer = new AnimComposer();
    animComposer.addAnimClip(animClip);

    model.addControl(animComposer);
    rootNode.attachChild(model);

    // run animation
    model.getControl(AnimComposer.class).setCurrentAction("anim");
}
 
Example 10
Source File: TerrainGrid.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public TerrainGrid(String name, int patchSize, int maxVisibleSize, TerrainGridTileLoader terrainQuadGrid) {
    this(name, patchSize, maxVisibleSize, Vector3f.UNIT_XYZ, terrainQuadGrid);
}
 
Example 11
Source File: TestSpatialAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
  public void simpleInitApp() {

      AmbientLight al = new AmbientLight();
      rootNode.addLight(al);

      DirectionalLight dl = new DirectionalLight();
      dl.setDirection(Vector3f.UNIT_XYZ.negate());
      rootNode.addLight(dl);

      // Create model
      Box box = new Box(1, 1, 1);
      Geometry geom = new Geometry("box", box);
      geom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
      Node model = new Node("model");
      model.attachChild(geom);

      Box child = new Box(0.5f, 0.5f, 0.5f);
      Geometry childGeom = new Geometry("box", child);
      childGeom.setMaterial(assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m"));
      Node childModel = new Node("childmodel");
      childModel.setLocalTranslation(2, 2, 2);
      childModel.attachChild(childGeom);
      model.attachChild(childModel);
      
      //animation parameters
      float animTime = 5;
      int fps = 25;
      float totalXLength = 10;
      
      //calculating frames
      int totalFrames = (int) (fps * animTime);
      float dT = animTime / totalFrames, t = 0;
      float dX = totalXLength / totalFrames, x = 0;
      float[] times = new float[totalFrames];
      Vector3f[] translations = new Vector3f[totalFrames];
      Quaternion[] rotations = new Quaternion[totalFrames];
      Vector3f[] scales = new Vector3f[totalFrames];
for (int i = 0; i < totalFrames; ++i) {
      	times[i] = t;
      	t += dT;
      	translations[i] = new Vector3f(x, 0, 0);
      	x += dX;
      	rotations[i] = Quaternion.IDENTITY;
      	scales[i] = Vector3f.UNIT_XYZ;
      }
      SpatialTrack spatialTrack = new SpatialTrack(times, translations, rotations, scales);
      
      //creating the animation
      Animation spatialAnimation = new Animation("anim", animTime);
      spatialAnimation.setTracks(new SpatialTrack[] { spatialTrack });
      
      //create spatial animation control
      AnimControl control = new AnimControl();
      HashMap<String, Animation> animations = new HashMap<String, Animation>();
      animations.put("anim", spatialAnimation);
      control.setAnimations(animations);
      model.addControl(control);

      rootNode.attachChild(model);
      
      //run animation
      control.createChannel().setAnim("anim");
  }
 
Example 12
Source File: TerrainQuad.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Creates a terrain with:
 * <ul>
 * <li>the total, real-world, size of the terrain</li>
 * <li>the patchSize, or the size of each geometry tile of the terrain</li>
 * <li>the heightmap that defines the height of the terrain</li>
 * </ul>
 * <p>
 * A TerrainQuad of totalSize 513x513 will be 513 units wide and 513 units long.
 * PatchSize is just used to subdivide the terrain into tiles that can be culled.
 * </p>
 * @param name the name of the scene element. This is required for
 * identification and comparison purposes.
 * @param patchSize size of the individual patches (geometry). Power of 2 plus 1,
 * must be smaller than totalSize. (eg. 33, 65...)
 * @param totalSize the size of this entire terrain (on one side). Power of 2 plus 1
 * (eg. 513, 1025, 2049...)
 * @param heightMap The height map to generate the terrain from (a flat
 * height map will be generated if this is null). The size of one side of the heightmap
 * must match the totalSize. So a 513x513 heightmap is needed for a terrain with totalSize of 513.
 */
public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap) {
    this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap);

    affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);
    fixNormalEdges(affectedAreaBBox);
    addControl(new NormalRecalcControl(this));
}
 
Example 13
Source File: TerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates a terrain with:
 * <ul>
 * <li>the total, real-world, size of the terrain</li>
 * <li>the patchSize, or the size of each geometry tile of the terrain</li>
 * <li>the heightmap that defines the height of the terrain</li>
 * </ul>
 * <p>
 * A TerrainQuad of totalSize 513x513 will be 513 units wide and 513 units long.
 * PatchSize is just used to subdivide the terrain into tiles that can be culled.
 * </p>
 * @param name the name of the scene element. This is required for
 * identification and comparison purposes.
 * @param patchSize size of the individual patches (geometry). Power of 2 plus 1, 
 * must be smaller than totalSize. (eg. 33, 65...)
 * @param totalSize the size of this entire terrain (on one side). Power of 2 plus 1 
 * (eg. 513, 1025, 2049...)
 * @param heightMap The height map to generate the terrain from (a flat
 * height map will be generated if this is null). The size of one side of the heightmap 
 * must match the totalSize. So a 513x513 heightmap is needed for a terrain with totalSize of 513.
 */
public TerrainQuad(String name, int patchSize, int totalSize, float[] heightMap) {
    this(name, patchSize, totalSize, Vector3f.UNIT_XYZ, heightMap);
            
    affectedAreaBBox = new BoundingBox(new Vector3f(0,0,0), size*2, Float.MAX_VALUE, size*2);
    fixNormalEdges(affectedAreaBBox);
    addControl(new NormalRecalcControl(this));
}
 
Example 14
Source File: TerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * 
 * @param name the name of the scene element. This is required for
 * identification and comparison purposes.
 * @param patchSize size of the individual patches
 * @param quadSize
 * @param totalSize the size of this entire terrain tree (on one side)
 * @param heightMap The height map to generate the terrain from (a flat
 * height map will be generated if this is null)
 */
@Deprecated
public TerrainQuad(String name, int patchSize, int quadSize, int totalSize, float[] heightMap) {
    this(name, patchSize, totalSize, quadSize, Vector3f.UNIT_XYZ, heightMap);
}