Coordinate System

Hello,

i want to visualize the coordinate axes. Is there a texture somewhere or a method that does that ?

Hi,

i made up alittle work-around using line primitives. Heres the code:

[java]

import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Line;



public class CoordinateSystem extends SimpleApplication {



Line x_axis_line;

Line y_axis_line;

Line z_axis_line;

Geometry g_x;

Geometry g_y;

Geometry g_z;

Material m_x;

Material m_y;

Material m_z;

Node cs_node;



@Override

public void simpleInitApp() {

//Zeichne Koordinaten-System

cs_node = new Node("coordinate_system");

x_axis_line = new Line(new Vector3f(-10000,0,0),new Vector3f(+10000, 0, 0));

y_axis_line = new Line(new Vector3f(0,-10000,0),new Vector3f(0, +10000, 0));

z_axis_line = new Line(new Vector3f(0,0,-10000),new Vector3f(0, 0, 10000));

g_x = new Geometry("x_axis", x_axis_line);

g_y = new Geometry("y_axis", y_axis_line);

g_z = new Geometry("z_axis", z_axis_line);

m_x = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

m_x.setColor("Color", ColorRGBA.Red);

m_y = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

m_y.setColor("Color", ColorRGBA.Green);

m_z = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

m_z.setColor("Color", ColorRGBA.Blue);

g_x.setMaterial(m_x);

g_y.setMaterial(m_y);

g_z.setMaterial(m_z);

cs_node.attachChild(g_x);

cs_node.attachChild(g_y);

cs_node.attachChild(g_z);



//Kamera-Setup

cam.setLocation(new Vector3f(10, 10, 10));



rootNode.attachChild(cs_node);

}



public static void main(String[] args) {

CoordinateSystem cs = new CoordinateSystem();

cs.start();

}

}

[/java]



Problem solved

Hey this is my grid and axis implementation. The returned node can easily be attached or detached to show or hide the grid:

[java]

/**

  • @author Xeratos
  •     Creates one arrow for each axis colored in x=red, y=green, z=blue<br />
    
  •     and one grid plane for each plane colored xz=red, xy=green, yz=blue.<br />
    
  •     The returned node is being optimized before return.<br />
    
  • @param size
  •        - int - The size of the arrows and grids<br />
    
  • @param segSize
  •        - int - The segment size of the grids.<br />
    
  • @return Node - A node with 3 direction arrows for x, y, z axis and 3 coordination
  •     grid planes for xz, xy, yz planes.<br />
    

*/

public Node createCoordinationNode(int size, int segSize) {

Node coordNode = new Node("Coodination helper node");

float offset = size / 2;



Material mat;



Geometry xAxis;

Geometry yAxis;

Geometry zAxis;

Geometry xzGrid;

Geometry xyGrid;

Geometry yzGrid;



// create x-axis

Arrow arrowX = new Arrow(new Vector3f(size, 0.0f, 0.0f));

xAxis = new Geometry("X-Axis", arrowX);

mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Red);

xAxis.setMaterial(mat);



// create xz-grid

Grid xzPlane = new Grid(size, size, segSize);

xzGrid = new Geometry("XZ-Plane", xzPlane);

xzGrid.setMaterial(mat);

xzGrid.rotateUpTo(new Vector3f(0.0f, 1.0f, 0.0f));

xzGrid.setLocalTranslation(new Vector3f(-offset, 0.0f, -offset));



// create y-axis

Arrow arrowY = new Arrow(new Vector3f(0.0f, size, 0.0f));

yAxis = new Geometry("Y-Axis", arrowY);

mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Green);

yAxis.setMaterial(mat);



// create xy-grid

Grid xyPlane = new Grid(size, size, segSize);

xyGrid = new Geometry("XY-Plane", xyPlane);

xyGrid.setMaterial(mat);

xyGrid.rotateUpTo(new Vector3f(0.0f, 0.0f, 1.0f));

xyGrid.setLocalTranslation(new Vector3f(-offset, offset, 0.0f));



// create z-axis

Arrow arrowZ = new Arrow(new Vector3f(0.0f, 0.0f, size));

zAxis = new Geometry("Z-Axis", arrowZ);

mat = new Material(game.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

mat.setColor("Color", ColorRGBA.Blue);

zAxis.setMaterial(mat);



// create yz-grid

Grid yzPlane = new Grid(size, size, segSize);

yzGrid = new Geometry("YZ-Plane", yzPlane);

yzGrid.setMaterial(mat);

yzGrid.rotateUpTo(new Vector3f(1.0f, 0.0f, 0.0f));

yzGrid.setLocalTranslation(new Vector3f(0.0f, offset, -offset));



// attach arrows to coordination node

coordNode.attachChild(xAxis);

coordNode.attachChild(yAxis);

coordNode.attachChild(zAxis);



// attach grids to coordination node

coordNode.attachChild(xyGrid);

coordNode.attachChild(xzGrid);

coordNode.attachChild(yzGrid);



// optimize coordNode

GeometryBatchFactory.optimize(coordNode);



return coordNode;

}

[/java]