本文整理汇总了Java中org.sunflow.math.Vector3类的典型用法代码示例。如果您正苦于以下问题:Java Vector3类的具体用法?Java Vector3怎么用?Java Vector3使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Vector3类属于org.sunflow.math包,在下文中一共展示了Vector3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseCameraMatrix
import org.sunflow.math.Vector3; //导入依赖的package包/类
private void parseCameraMatrix(int index, SunflowAPIInterface api) throws IOException, ParserException {
String offset = index < 0 ? "" : String.format("[%d]", index);
if (p.peekNextToken("transform")) {
// advanced camera
api.parameter(String.format("transform%s", offset), parseMatrix());
} else {
if (index >= 0)
p.checkNextToken("{");
// regular camera specification
p.checkNextToken("eye");
Point3 eye = parsePoint();
p.checkNextToken("target");
Point3 target = parsePoint();
p.checkNextToken("up");
Vector3 up = parseVector();
api.parameter(String.format("transform%s", offset), Matrix4.lookAt(eye, target, up));
if (index >= 0)
p.checkNextToken("}");
}
}
示例2: scatterPhoton
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void scatterPhoton(ShadingState state, Color power) {
Color diffuse;
// make sure we are on the right side of the material
if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0) {
state.getNormal().negate();
state.getGeoNormal().negate();
}
diffuse = getDiffuse(state);
state.storePhoton(state.getRay().getDirection(), power, diffuse);
float avg = diffuse.getAverage();
double rnd = state.getRandom(0, 0, 1);
if (rnd < avg) {
// photon is scattered
power.mul(diffuse).mul(1.0f / avg);
OrthoNormalBasis onb = state.getBasis();
double u = 2 * Math.PI * rnd / avg;
double v = state.getRandom(0, 1, 1);
float s = (float) Math.sqrt(v);
float s1 = (float) Math.sqrt(1.0 - v);
Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
w = onb.transform(w, new Vector3());
state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
}
}
示例3: brdf
import org.sunflow.math.Vector3; //导入依赖的package包/类
private float brdf(Vector3 i, Vector3 o, OrthoNormalBasis basis) {
float fr = 4 * (float) Math.PI * alphaX * alphaY;
float p = basis.untransformZ(i) * basis.untransformZ(o);
if (p > 0)
fr *= (float) Math.sqrt(p);
else
fr = 0;
Vector3 h = Vector3.add(i, o, new Vector3());
basis.untransform(h);
float hx = h.x / alphaX;
hx *= hx;
float hy = h.y / alphaY;
hy *= hy;
float hn = h.z * h.z;
if (fr > 0)
fr = (float) Math.exp(-(hx + hy) / hn) / fr;
return fr;
}
示例4: scatterPhoton
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void scatterPhoton(ShadingState state, Color power) {
Color diffuse;
// make sure we are on the right side of the material
if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0) {
state.getNormal().negate();
state.getGeoNormal().negate();
}
diffuse = Color.GRAY;
state.storePhoton(state.getRay().getDirection(), power, diffuse);
float avg = diffuse.getAverage();
double rnd = state.getRandom(0, 0, 1);
if (rnd < avg) {
// photon is scattered
power.mul(diffuse).mul(1.0f / avg);
OrthoNormalBasis onb = state.getBasis();
double u = 2 * Math.PI * rnd / avg;
double v = state.getRandom(0, 1, 1);
float s = (float) Math.sqrt(v);
float s1 = (float) Math.sqrt(1.0 - v);
Vector3 w = new Vector3((float) Math.cos(u) * s, (float) Math.sin(u) * s, s1);
w = onb.transform(w, new Vector3());
state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
}
}
示例5: getRadiance
import org.sunflow.math.Vector3; //导入依赖的package包/类
public Color getRadiance(ShadingState state) {
if (!state.includeSpecular())
return Color.BLACK;
state.faceforward();
float cos = state.getCosND();
float dn = 2 * cos;
Vector3 refDir = new Vector3();
refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
Ray refRay = new Ray(state.getPoint(), refDir);
// compute Fresnel term
cos = 1 - cos;
float cos2 = cos * cos;
float cos5 = cos2 * cos2 * cos;
Color ret = Color.white();
ret.sub(color);
ret.mul(cos5);
ret.add(color);
return ret.mul(state.traceReflection(refRay, 0));
}
示例6: scatterPhoton
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void scatterPhoton(ShadingState state, Color power) {
float avg = color.getAverage();
double rnd = state.getRandom(0, 0, 1);
if (rnd >= avg)
return;
state.faceforward();
float cos = state.getCosND();
power.mul(color).mul(1.0f / avg);
// photon is reflected
float dn = 2 * cos;
Vector3 dir = new Vector3();
dir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
dir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
dir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
state.traceReflectionPhoton(new Ray(state.getPoint(), dir), power);
}
示例7: prepareShadingState
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void prepareShadingState(ShadingState state) {
state.init();
Instance i = state.getInstance();
state.getRay().getPoint(state.getPoint());
Ray r = state.getRay();
Shader s = i.getShader(0);
state.setShader(s != null ? s : this);
int primID = state.getPrimitiveID();
int hair = primID / numSegments;
int line = primID % numSegments;
int vRoot = hair * 3 * (numSegments + 1);
int v0 = vRoot + line * 3;
// tangent vector
Vector3 v = getTangent(line, v0, state.getV());
v = state.transformVectorObjectToWorld(v);
state.setBasis(OrthoNormalBasis.makeFromWV(v, new Vector3(-r.dx, -r.dy, -r.dz)));
state.getBasis().swapVW();
// normal
state.getNormal().set(0, 0, 1);
state.getBasis().transform(state.getNormal());
state.getGeoNormal().set(state.getNormal());
state.getUV().set(0, (line + state.getV()) / numSegments);
}
示例8: prepareShadingState
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void prepareShadingState(ShadingState state) {
state.init();
state.getRay().getPoint(state.getPoint());
Point3 localPoint = state.transformWorldToObject(state.getPoint());
localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
localPoint.z -= particles[3 * state.getPrimitiveID() + 2];
state.getNormal().set(localPoint.x, localPoint.y, localPoint.z);
state.getNormal().normalize();
state.setShader(state.getInstance().getShader(0));
state.setModifier(state.getInstance().getModifier(0));
// into object space
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
state.getNormal().set(worldNormal);
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
示例9: prepareShadingState
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void prepareShadingState(ShadingState state) {
state.init();
state.getRay().getPoint(state.getPoint());
Instance parent = state.getInstance();
Point3 n = state.transformWorldToObject(state.getPoint());
state.getNormal().set(n.x * (2 * n.x * n.x - 1), n.y * (2 * n.y * n.y - 1), n.z * (2 * n.z * n.z - 1));
state.getNormal().normalize();
state.setShader(parent.getShader(0));
state.setModifier(parent.getModifier(0));
// into world space
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
state.getNormal().set(worldNormal);
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
// create basis in world space
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
}
示例10: prepareShadingState
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void prepareShadingState(ShadingState state) {
state.init();
state.getRay().getPoint(state.getPoint());
Instance parent = state.getInstance();
Point3 localPoint = state.transformWorldToObject(state.getPoint());
state.getNormal().set(localPoint.x, localPoint.y, 0);
state.getNormal().normalize();
float phi = (float) Math.atan2(state.getNormal().y, state.getNormal().x);
if (phi < 0)
phi += 2 * Math.PI;
state.getUV().x = phi / (float) (2 * Math.PI);
state.getUV().y = (localPoint.z + 1) * 0.5f;
state.setShader(parent.getShader(0));
state.setModifier(parent.getModifier(0));
// into world space
Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
Vector3 v = state.transformVectorObjectToWorld(new Vector3(0, 0, 1));
state.getNormal().set(worldNormal);
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
// compute basis in world space
state.setBasis(OrthoNormalBasis.makeFromWV(state.getNormal(), v));
}
示例11: getIrradiance
import org.sunflow.math.Vector3; //导入依赖的package包/类
public Color getIrradiance(ShadingState state, Color diffuseReflectance) {
OrthoNormalBasis onb = state.getBasis();
Vector3 w = new Vector3();
Color result = Color.black();
for (int i = 0; i < samples; i++) {
float xi = (float) state.getRandom(i, 0, samples);
float xj = (float) state.getRandom(i, 1, samples);
float phi = (float) (2 * Math.PI * xi);
float cosPhi = (float) Math.cos(phi);
float sinPhi = (float) Math.sin(phi);
float sinTheta = (float) Math.sqrt(xj);
float cosTheta = (float) Math.sqrt(1.0f - xj);
w.x = cosPhi * sinTheta;
w.y = sinPhi * sinTheta;
w.z = cosTheta;
onb.transform(w);
Ray r = new Ray(state.getPoint(), w);
r.setMax(maxDist);
result.add(Color.blend(bright, dark, state.traceShadow(r)));
}
return result.mul((float) Math.PI / samples);
}
示例12: getGlobalRadiance
import org.sunflow.math.Vector3; //导入依赖的package包/类
public Color getGlobalRadiance(ShadingState state) {
Point3 p = state.getPoint();
Vector3 n = state.getNormal();
int set = (int) (state.getRandom(0, 1, 1) * numSets);
float maxAvgPow = 0;
float minDist = 1;
Color pow = null;
for (PointLight vpl : virtualLights[set]) {
maxAvgPow = Math.max(maxAvgPow, vpl.power.getAverage());
if (Vector3.dot(n, vpl.n) > 0.9f) {
float d = vpl.p.distanceToSquared(p);
if (d < minDist) {
pow = vpl.power;
minDist = d;
}
}
}
return pow == null ? Color.BLACK : pow.copy().mul(1.0f / maxAvgPow);
}
示例13: insert
import org.sunflow.math.Vector3; //导入依赖的package包/类
private void insert(Point3 p, Vector3 n, float r0, Color irr) {
if (tolerance <= 0)
return;
Node node = root;
r0 = MathUtils.clamp(r0 * tolerance, minSpacing, maxSpacing) * invTolerance;
if (root.isInside(p)) {
while (node.sideLength >= (4.0 * r0 * tolerance)) {
int k = 0;
k |= (p.x > node.center.x) ? 1 : 0;
k |= (p.y > node.center.y) ? 2 : 0;
k |= (p.z > node.center.z) ? 4 : 0;
if (node.children[k] == null) {
Point3 c = new Point3(node.center);
c.x += ((k & 1) == 0) ? -node.quadSideLength : node.quadSideLength;
c.y += ((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength;
c.z += ((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength;
node.children[k] = new Node(c, node.halfSideLength);
}
node = node.children[k];
}
}
Sample s = new Sample(p, n, r0, irr);
s.next = node.first;
node.first = s;
}
示例14: update
import org.sunflow.math.Vector3; //导入依赖的package包/类
@Override
public boolean update(ParameterList pl, SunflowAPI api) {
radiance = pl.getColor("radiance", radiance);
numSamples = pl.getInt("samples", numSamples);
if (super.update(pl, api)) {
// precompute triangle areas and normals
areas = new float[getNumPrimitives()];
ngs = new Vector3[getNumPrimitives()];
totalArea = 0;
for (int tri3 = 0, i = 0; tri3 < triangles.length; tri3 += 3, i++) {
int a = triangles[tri3 + 0];
int b = triangles[tri3 + 1];
int c = triangles[tri3 + 2];
Point3 v0p = getPoint(a);
Point3 v1p = getPoint(b);
Point3 v2p = getPoint(c);
ngs[i] = Point3.normal(v0p, v1p, v2p);
areas[i] = 0.5f * ngs[i].length();
ngs[i].normalize();
totalArea += areas[i];
}
} else
return false;
return true;
}
示例15: getPhoton
import org.sunflow.math.Vector3; //导入依赖的package包/类
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power) {
float z = (float) (1 - 2 * randX2);
float r = (float) Math.sqrt(Math.max(0, 1 - z * z));
float phi = (float) (2 * Math.PI * randY2);
float x = r * (float) Math.cos(phi);
float y = r * (float) Math.sin(phi);
p.x = center.x + x * radius;
p.y = center.y + y * radius;
p.z = center.z + z * radius;
OrthoNormalBasis basis = OrthoNormalBasis.makeFromW(new Vector3(x, y, z));
phi = (float) (2 * Math.PI * randX1);
float cosPhi = (float) Math.cos(phi);
float sinPhi = (float) Math.sin(phi);
float sinTheta = (float) Math.sqrt(randY1);
float cosTheta = (float) Math.sqrt(1 - randY1);
dir.x = cosPhi * sinTheta;
dir.y = sinPhi * sinTheta;
dir.z = cosTheta;
basis.transform(dir);
power.set(radiance);
power.mul((float) (Math.PI * Math.PI * 4 * r2));
}