2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package com.jme.scene.state;
35 import java.io.IOException;
37 import com.jme.util.export.InputCapsule;
38 import com.jme.util.export.JMEExporter;
39 import com.jme.util.export.JMEImporter;
40 import com.jme.util.export.OutputCapsule;
43 * <code>ClipState</code> specifies a plane to test for clipping of the nodes. This can be used to
44 * take "slices" out of geometric objects. ClipPlane can add an additional (to the normal frustum planes)
45 * six planes to clip against.
46 * @author Joshua Slack
49 public abstract class ClipState extends RenderState {
50 public static final int CLIP_PLANE0 = 0;
52 public static final int CLIP_PLANE1 = 1;
54 public static final int CLIP_PLANE2 = 2;
56 public static final int CLIP_PLANE3 = 3;
58 public static final int CLIP_PLANE4 = 4;
60 public static final int CLIP_PLANE5 = 5;
62 public static final int MAX_CLIP_PLANES = 6;
64 protected boolean[] enabledClipPlanes = new boolean[MAX_CLIP_PLANES];
66 protected double[][] planeEquations = new double[MAX_CLIP_PLANES][4];
69 * <code>getType</code> returns RenderState.RS_CLIP
71 * @return RenderState.RS_CLIP
72 * @see RenderState#getType()
73 * @deprecated As of 2.0, use {@link #getStateType()} instead.
75 public int getType() {
80 * <code>getStateType</code> returns {@link RenderState.StateType#Clip}
82 * @return {@link RenderState.StateType#Clip}
83 * @see RenderState#getStateType()
85 public StateType getStateType() {
87 return StateType.Clip;
91 * Enables/disables a specific clip plane
94 * Plane to enable/disable (CLIP_PLANE0-CLIP_PLANE5)
98 public void setEnableClipPlane(int planeIndex, boolean enabled) {
99 if (planeIndex < 0 || planeIndex >= MAX_CLIP_PLANES) {
103 enabledClipPlanes[planeIndex] = enabled;
104 setNeedsRefresh(true);
108 * Sets plane equation for a specific clip plane
111 * Plane to set equation for (CLIP_PLANE0-CLIP_PLANE5)
121 public void setClipPlaneEquation(int planeIndex, double clipX,
122 double clipY, double clipZ, double clipW) {
123 if (planeIndex < 0 || planeIndex >= MAX_CLIP_PLANES) {
127 planeEquations[planeIndex][0] = clipX;
128 planeEquations[planeIndex][1] = clipY;
129 planeEquations[planeIndex][2] = clipZ;
130 planeEquations[planeIndex][3] = clipW;
131 setNeedsRefresh(true);
135 * @param index plane to check
136 * @return true if given clip plane is enabled
138 public boolean getPlaneEnabled(int index) {
139 return enabledClipPlanes[index];
142 public double getPlaneEq(int plane, int eqIndex) {
143 return planeEquations[plane][eqIndex];
145 public void setPlaneEq(int plane, int eqIndex, double value) {
146 planeEquations[plane][eqIndex] = value;
147 setNeedsRefresh(true);
150 public void write(JMEExporter e) throws IOException {
152 OutputCapsule capsule = e.getCapsule(this);
153 capsule.write(enabledClipPlanes, "enabledClipPlanes", new boolean[MAX_CLIP_PLANES]);
154 capsule.write(planeEquations, "planeEquations", new double[MAX_CLIP_PLANES][4]);
157 public void read(JMEImporter e) throws IOException {
159 InputCapsule capsule = e.getCapsule(this);
160 enabledClipPlanes = capsule.readBooleanArray("enabledClipPlanes", new boolean[MAX_CLIP_PLANES]);
161 planeEquations = capsule.readDoubleArray2D("planeEquations", new double[MAX_CLIP_PLANES][4]);
164 public Class getClassTag() {
165 return ClipState.class;