1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.shapes;
\r
13 import com.jme.renderer.ColorRGBA;
\r
14 import com.jme.renderer.Renderer;
\r
15 import com.jme.scene.Geometry;
\r
16 import com.jme.scene.Line;
\r
17 import com.jme.scene.state.MaterialState;
\r
18 import com.jme.util.geom.BufferUtils;
\r
20 public class GridShape {
\r
23 public static Geometry getShape(Renderer renderer, int lineCount, float delta) {
\r
25 float[] coords = new float[lineCount*lineCount*2*3];
\r
26 float size = delta * lineCount;
\r
27 float halfSize = size * 0.5f;
\r
29 for (int i = 0 ; i <= lineCount; i++) {
\r
31 coords[index++] = -halfSize + i * delta;
\r
32 coords[index++] = 0.f;
\r
33 coords[index++] = -halfSize;
\r
34 coords[index++] = -halfSize + i * delta;
\r
35 coords[index++] = 0.f;
\r
36 coords[index++] = +halfSize;
\r
38 for (int i = 0 ; i <= lineCount; i++) {
\r
39 int index = (i + lineCount + 1)*3*2;
\r
40 coords[index++] = -halfSize;
\r
41 coords[index++] = 0.f;
\r
42 coords[index++] = -halfSize + i * delta;
\r
43 coords[index++] = +halfSize;
\r
44 coords[index++] = 0.f;
\r
45 coords[index++] = -halfSize + i * delta;
\r
48 Line shape = new Line("",BufferUtils.createFloatBuffer(coords),null,null,null);
\r
49 MaterialState ms = renderer.createMaterialState();
\r
50 ms.setEmissive(new ColorRGBA(1.f,1.f,1.f,0.f));
\r
51 shape.setRenderState(ms);
\r
52 shape.setCullMode(Geometry.CULL_NEVER);
\r