Added two new methods to convert ColorRGBA to Vector3f and Vector4f. These should be very useful when using shaders.
Formatting. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8155 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
7042720106
commit
03c22a1dee
@ -1,13 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* *
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
@ -17,19 +15,18 @@
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.jme3.math;
|
||||
|
||||
import com.jme3.export.InputCapsule;
|
||||
@ -39,25 +36,24 @@ import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.export.Savable;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* <code>ColorRGBA</code> defines a color made from a collection of
|
||||
* red, green and blue values. An alpha value determines is transparency.
|
||||
* All values must be between 0 and 1. If any value is set higher or lower
|
||||
* than these constraints they are clamped to the min or max. That is, if
|
||||
* a value smaller than zero is set the value clamps to zero. If a value
|
||||
* higher than 1 is passed, that value is clamped to 1. However, because the
|
||||
* attributes r, g, b, a are public for efficiency reasons, they can be
|
||||
* directly modified with invalid values. The client should take care when
|
||||
* directly addressing the values. A call to clamp will assure that the values
|
||||
* are within the constraints.
|
||||
* <code>ColorRGBA</code> defines a color made from a collection of red, green
|
||||
* and blue values. An alpha value determines is transparency. All values must
|
||||
* be between 0 and 1. If any value is set higher or lower than these
|
||||
* constraints they are clamped to the min or max. That is, if a value smaller
|
||||
* than zero is set the value clamps to zero. If a value higher than 1 is
|
||||
* passed, that value is clamped to 1. However, because the attributes r, g, b,
|
||||
* a are public for efficiency reasons, they can be directly modified with
|
||||
* invalid values. The client should take care when directly addressing the
|
||||
* values. A call to clamp will assure that the values are within the
|
||||
* constraints.
|
||||
*
|
||||
* @author Mark Powell
|
||||
* @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $
|
||||
*/
|
||||
public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable {
|
||||
|
||||
static final long serialVersionUID = 1;
|
||||
|
||||
/**
|
||||
* the color black (0,0,0).
|
||||
*/
|
||||
@ -114,12 +110,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
|
||||
* the color pink (1, 0.68, 0.68).
|
||||
*/
|
||||
public static final ColorRGBA Pink = new ColorRGBA(1f, 0.68f, 0.68f, 1f);
|
||||
|
||||
/**
|
||||
* the black color with no alpha (0, 0, 0, 0);
|
||||
*/
|
||||
public static final ColorRGBA BlackNoAlpha = new ColorRGBA(0f, 0f, 0f, 0f);
|
||||
|
||||
/**
|
||||
* The red component of the color.
|
||||
*/
|
||||
@ -442,10 +436,18 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
|
||||
}
|
||||
|
||||
ColorRGBA comp = (ColorRGBA) o;
|
||||
if (Float.compare(r, comp.r) != 0) return false;
|
||||
if (Float.compare(g, comp.g) != 0) return false;
|
||||
if (Float.compare(b, comp.b) != 0) return false;
|
||||
if (Float.compare(a, comp.a) != 0) return false;
|
||||
if (Float.compare(r, comp.r) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Float.compare(g, comp.g) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Float.compare(b, comp.b) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Float.compare(a, comp.a) != 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -464,7 +466,6 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
public void write(JmeExporter e) throws IOException {
|
||||
OutputCapsule capsule = e.getCapsule(this);
|
||||
capsule.write(r, "r", 0);
|
||||
@ -527,4 +528,26 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
|
||||
b = ((byte) (color >> 8) & 0xFF) / 255f;
|
||||
a = ((byte) (color) & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the current ColorRGBA to a Vector3f using
|
||||
* x = r, y = g, z = b. The Alpha value is not used.
|
||||
*
|
||||
* This method is useful to use for shaders assignment.
|
||||
* @return A Vector3f containing the RGB value of current color definition.
|
||||
*/
|
||||
public Vector3f toVector3f() {
|
||||
return new Vector3f(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the current ColorRGBA to a Vector4f using
|
||||
* x = r, y = g, z = b, w = a.
|
||||
*
|
||||
* This method is useful to use for shaders assignment.
|
||||
* @return A Vector4f containing the RGBA value of current color definition.
|
||||
*/
|
||||
public Vector4f toVector4f() {
|
||||
return new Vector4f(r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user