use of com.jme3.math.Vector4f in project jmonkeyengine by jMonkeyEngine.
the class Camera method setClipPlane.
/**
* Sets a clipPlane for this camera.
* The clipPlane is used to recompute the
* projectionMatrix using the plane as the near plane
* This technique is known as the oblique near-plane clipping method introduced by Eric Lengyel
* more info here
* <ul>
* <li><a href="http://www.terathon.com/code/oblique.html">http://www.terathon.com/code/oblique.html</a>
* <li><a href="http://aras-p.info/texts/obliqueortho.html">http://aras-p.info/texts/obliqueortho.html</a>
* <li><a href="http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html">http://hacksoflife.blogspot.com/2008/12/every-now-and-then-i-come-across.html</a>
* </ul>
*
* Note that this will work properly only if it's called on each update, and be aware that it won't work properly with the sky bucket.
* if you want to handle the sky bucket, look at how it's done in SimpleWaterProcessor.java
* @param clipPlane the plane
* @param side the side the camera stands from the plane
*/
public void setClipPlane(Plane clipPlane, Plane.Side side) {
float sideFactor = 1;
if (side == Plane.Side.Negative) {
sideFactor = -1;
}
//we are on the other side of the plane no need to clip anymore.
if (clipPlane.whichSide(location) == side) {
return;
}
TempVars vars = TempVars.get();
try {
Matrix4f p = projectionMatrixOverride.set(projectionMatrix);
Matrix4f ivm = viewMatrix;
Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant(), vars.vect1);
Vector3f pp = ivm.mult(point, vars.vect2);
Vector3f pn = ivm.multNormal(clipPlane.getNormal(), vars.vect3);
Vector4f clipPlaneV = vars.vect4f1.set(pn.x * sideFactor, pn.y * sideFactor, pn.z * sideFactor, -(pp.dot(pn)) * sideFactor);
Vector4f v = vars.vect4f2.set(0, 0, 0, 0);
v.x = (Math.signum(clipPlaneV.x) + p.m02) / p.m00;
v.y = (Math.signum(clipPlaneV.y) + p.m12) / p.m11;
v.z = -1.0f;
v.w = (1.0f + p.m22) / p.m23;
//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w;
float dot = clipPlaneV.dot(v);
Vector4f c = clipPlaneV.multLocal(2.0f / dot);
p.m20 = c.x - p.m30;
p.m21 = c.y - p.m31;
p.m22 = c.z - p.m32;
p.m23 = c.w - p.m33;
setProjectionMatrix(p);
} finally {
vars.release();
}
}
use of com.jme3.math.Vector4f in project jmonkeyengine by jMonkeyEngine.
the class J3MOutputCapsule method formatMatParam.
private String formatMatParam(MatParam param) {
VarType type = param.getVarType();
Object val = param.getValue();
switch(type) {
case Boolean:
case Float:
case Int:
return val.toString();
case Vector2:
Vector2f v2 = (Vector2f) val;
return v2.getX() + " " + v2.getY();
case Vector3:
Vector3f v3 = (Vector3f) val;
return v3.getX() + " " + v3.getY() + " " + v3.getZ();
case Vector4:
// can be either ColorRGBA, Vector4f or Quaternion
if (val instanceof Vector4f) {
Vector4f v4 = (Vector4f) val;
return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
} else if (val instanceof ColorRGBA) {
ColorRGBA color = (ColorRGBA) val;
return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
} else if (val instanceof Quaternion) {
Quaternion quat = (Quaternion) val;
return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
} else {
throw new UnsupportedOperationException("Unexpected Vector4 type: " + val);
}
default:
// parameter type not supported in J3M
return null;
}
}
Aggregations