本文整理汇总了Java中org.sunflow.math.Vector3.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3.normalize方法的具体用法?Java Vector3.normalize怎么用?Java Vector3.normalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.sunflow.math.Vector3
的用法示例。
在下文中一共展示了Vector3.normalize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSkyRGB
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
private Color getSkyRGB(Vector3 dir) {
if (dir.z < 0 && !groundExtendSky)
return groundColor;
if (dir.z < 0.001f)
dir.z = 0.001f;
dir.normalize();
double theta = Math.acos(MathUtils.clamp(dir.z, -1, 1));
double gamma = Math.acos(MathUtils.clamp(Vector3.dot(dir, sunDir), -1, 1));
double x = perezFunction(perezx, theta, gamma, zenithx);
double y = perezFunction(perezy, theta, gamma, zenithy);
double Y = perezFunction(perezY, theta, gamma, zenithY) * 1e-4;
XYZColor c = ChromaticitySpectrum.get((float) x, (float) y);
// XYZColor c = new ChromaticitySpectrum((float) x, (float) y).toXYZ();
float X = (float) (c.getX() * Y / c.getY());
float Z = (float) (c.getZ() * Y / c.getY());
return RGBSpace.SRGB.convertXYZtoRGB(X, (float) Y, Z);
}
示例2: modify
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public void modify(ShadingState state) {
Point3 p = state.transformWorldToObject(state.getPoint());
p.x *= size;
p.y *= size;
p.z *= size;
Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
double f0 = f(p.x, p.y, p.z);
double fx = f(p.x + .0001, p.y, p.z);
double fy = f(p.x, p.y + .0001, p.z);
double fz = f(p.x, p.y, p.z + .0001);
normal.x -= scale * (fx - f0) / .0001;
normal.y -= scale * (fy - f0) / .0001;
normal.z -= scale * (fz - f0) / .0001;
normal.normalize();
state.getNormal().set(state.transformNormalObjectToWorld(normal));
state.getNormal().normalize();
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
示例3: getRadiance
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public Color getRadiance(ShadingState state) {
// don't use these - gather lights for sphere of directions
// gather lights
state.initLightSamples();
state.initCausticSamples();
Vector3 v = state.getRay().getDirection();
v.negate();
Vector3 h = new Vector3();
Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0));
Color diff = Color.black();
Color spec = Color.black();
for (LightSample ls : state) {
Vector3 l = ls.getShadowRay().getDirection();
float dotTL = Vector3.dot(t, l);
float sinTL = (float) Math.sqrt(1 - dotTL * dotTL);
// float dotVL = Vector3.dot(v, l);
diff.madd(sinTL, ls.getDiffuseRadiance());
Vector3.add(v, l, h);
h.normalize();
float dotTH = Vector3.dot(t, h);
float sinTH = (float) Math.sqrt(1 - dotTH * dotTH);
float s = (float) Math.pow(sinTH, 10.0f);
spec.madd(s, ls.getSpecularRadiance());
}
Color c = Color.add(diff, spec, new Color());
// transparency
return Color.blend(c, state.traceTransparency(), state.getV(), new Color());
}
示例4: DirectionalSpotlight
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
public DirectionalSpotlight() {
src = new Point3(0, 0, 0);
dir = new Vector3(0, 0, -1);
dir.normalize();
basis = OrthoNormalBasis.makeFromW(dir);
r = 1;
r2 = r * r;
radiance = Color.WHITE;
}
示例5: generate
import org.sunflow.math.Vector3; //导入方法依赖的package包/类
private TriangleMesh generate(int[] tris, float[] verts, boolean smoothNormals) {
ParameterList pl = new ParameterList();
pl.addIntegerArray("triangles", tris);
pl.addPoints("points", InterpolationType.VERTEX, verts);
if (smoothNormals) {
float[] normals = new float[verts.length]; // filled with 0's
Point3 p0 = new Point3();
Point3 p1 = new Point3();
Point3 p2 = new Point3();
Vector3 n = new Vector3();
for (int i3 = 0; i3 < tris.length; i3 += 3) {
int v0 = tris[i3 + 0];
int v1 = tris[i3 + 1];
int v2 = tris[i3 + 2];
p0.set(verts[3 * v0 + 0], verts[3 * v0 + 1], verts[3 * v0 + 2]);
p1.set(verts[3 * v1 + 0], verts[3 * v1 + 1], verts[3 * v1 + 2]);
p2.set(verts[3 * v2 + 0], verts[3 * v2 + 1], verts[3 * v2 + 2]);
Point3.normal(p0, p1, p2, n); // compute normal
// add face normal to each vertex
// note that these are not normalized so this in fact weights
// each normal by the area of the triangle
normals[3 * v0 + 0] += n.x;
normals[3 * v0 + 1] += n.y;
normals[3 * v0 + 2] += n.z;
normals[3 * v1 + 0] += n.x;
normals[3 * v1 + 1] += n.y;
normals[3 * v1 + 2] += n.z;
normals[3 * v2 + 0] += n.x;
normals[3 * v2 + 1] += n.y;
normals[3 * v2 + 2] += n.z;
}
// normalize all the vectors
for (int i3 = 0; i3 < normals.length; i3 += 3) {
n.set(normals[i3 + 0], normals[i3 + 1], normals[i3 + 2]);
n.normalize();
normals[i3 + 0] = n.x;
normals[i3 + 1] = n.y;
normals[i3 + 2] = n.z;
}
pl.addVectors("normals", InterpolationType.VERTEX, normals);
}
TriangleMesh m = new TriangleMesh();
if (m.update(pl, null))
return m;
// something failed in creating the mesh, the error message will be
// printed by the mesh itself - no need to repeat it here
return null;
}