// Decompiled by Jad v1.5.7b. Copyright 1997-99 Pavel Kouznetsov.
|
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
|
// Decompiler options: packimports(3)
|
// Source File Name: Camera.java
|
|
class Camera extends Object3D
|
{
|
static final long serialVersionUID = 4754289789178680517L;
|
|
/*static*/ float DECAL = 12; // 3;
|
/*static*/ float SCALE = 1; // 0.5f;
|
|
float shaper_fovy = 25.0f;
|
float shaper_zNear = 0.01f;
|
float shaper_zFar = 1E5f; // 500.0f;
|
|
Camera()
|
{
|
super("Camera");
|
//<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6>
|
// location = LA.newVector(2,0.7,-2);
|
// lookAt = new cVector(0.6,0.3,-0.6);
|
location = LA.newVector(6,2,4);
|
lookAt = new cVector(0.0,0.5,0);
|
direction = new cVector();
|
toParent = LA.newMatrix();
|
fromParent = LA.newMatrix();
|
toScreen = //toParent; // may 2013
|
LA.newMatrix();
|
fromScreen = //fromParent; // may 2013
|
LA.newMatrix();
|
initCamera();
|
perspective = true;
|
}
|
|
Camera(int viewCode)
|
{
|
super("Camera" + CameraPane.Name(viewCode));
|
this.viewCode = viewCode;
|
lookAt = new cVector();
|
direction = new cVector();
|
toParent = LA.newMatrix();
|
fromParent = LA.newMatrix();
|
toScreen = //toParent; // may 2013
|
LA.newMatrix();
|
fromScreen = //fromParent; // may 2013
|
LA.newMatrix();
|
switch (viewCode)
|
{
|
case 0:
|
location = LA.newVector(0, 0, 20);
|
perspective = true;
|
break;
|
case 1: // '\001'
|
location = LA.newVector(0, 0, 4); // Needed for translation direction
|
perspective = false;
|
break;
|
case 2: // '\002'
|
location = LA.newVector(0, 4, 0);
|
//UP = LA.newVector(1, 0, 0);
|
perspective = false;
|
//LA.matXRotate(toScreen, LA.toRadians(-90));
|
//LA.matXRotate(fromScreen, LA.toRadians(90));
|
break;
|
case 3: // '\003'
|
location = LA.newVector(4, 0, 0); // Needed for translation direction
|
//LA.matZRotate(toScreen, LA.toRadians(-90));
|
//LA.matXRotate(toScreen, LA.toRadians(-90));
|
//LA.matXRotate(fromScreen, LA.toRadians(90));
|
//LA.matZRotate(fromScreen, LA.toRadians(90));
|
perspective = false;
|
break;
|
case 4: // Default light
|
location = LA.newVector(-5, 15, 10);
|
perspective = false;
|
break;
|
}
|
|
computeTransform();
|
initCamera();
|
}
|
|
Camera(cVector from)
|
{
|
super("Camera" + 0);
|
viewCode = 0;
|
location = new cVector();
|
lookAt = new cVector();
|
direction = new cVector();
|
toParent = LA.newMatrix();
|
fromParent = LA.newMatrix();
|
toScreen = //toParent; // may 2013
|
LA.newMatrix();
|
fromScreen = //fromParent; // may 2013
|
LA.newMatrix();
|
setLocation(from);
|
computeTransform();
|
initCamera();
|
perspective = true;
|
}
|
|
private void initCamera()
|
{
|
focalLength = 1;
|
setAspect(4, 3);
|
background = LA.newVector(0.8, 0.8, 0.8);
|
}
|
|
void CreateMaterial(boolean multiply)
|
{
|
super.CreateMaterial(multiply);
|
|
material.shift = 90;
|
material.cameralight = 0.2f;
|
material.shadowbias = 10;
|
}
|
|
void setAspect(int width, int height)
|
{
|
//hAspect = width;
|
//vAspect = height;
|
aspect = (double)width / (double)height;
|
}
|
|
void setLocation(cVector from)
|
{
|
//setAim(from, lookAt);
|
LA.vecCopy(from, location);
|
//computeTransform();
|
}
|
|
void setFocus(cVector focus)
|
{
|
//setAim(location, focus);
|
LA.vecCopy(focus, lookAt);
|
//computeTransform();
|
}
|
|
cVector UP = LA.newVector(0, 1, 0);
|
cVector UP2 = LA.newVector(1, 0, 0);
|
|
// actual dynamic up vector
|
cVector up = new cVector();
|
|
cVector away = new cVector();
|
cVector right = new cVector();
|
|
double temp[][] = LA.newMatrix();
|
|
void setAim(cVector from, cVector towards)
|
{
|
LA.vecCopy(from, location);
|
LA.vecCopy(towards, lookAt);
|
|
// refresh toScreen matrix
|
computeTransform();
|
}
|
|
void RotatePosition(float dx, float dy)
|
{
|
if(hAspect != 0) return;
|
|
if (CameraPane.IMAGEFLIP)
|
{
|
dx = -dx;
|
}
|
|
if (CameraPane.ROTATECAMERA)
|
{
|
float t = dx;
|
dx = dy;
|
dy = -t;
|
}
|
|
cStatic.point1.set(location);
|
cStatic.point2.set(lookAt);
|
LA.vecSub(location, lookAt, location);
|
|
// avril 2014
|
// TransformToLocal(location);
|
|
double angle = -dx / 200.0;
|
quat.set(UP, angle);
|
quat.rotate(location);
|
|
angle = -dy / 200.0;
|
quat.set(right, angle);
|
quat.rotate(location);
|
|
// avril 2014
|
// TransformToWorld(location);
|
|
LA.vecAdd(location, lookAt, location);
|
|
tempvec.set(right);
|
|
computeTransform();
|
|
if (tempvec.dot(right) < 0)
|
{
|
UP.mul(-1);
|
computeTransform();
|
}
|
|
if(hAspect != 0)
|
{
|
location.set(cStatic.point1);
|
lookAt.set(cStatic.point2);
|
}
|
}
|
|
cVector tempvec = new cVector();
|
cQuat quat = new cQuat();
|
|
public double Distance()
|
{
|
LA.vecSub(location, lookAt, tempvec);
|
return tempvec.length();
|
}
|
|
void Translate(float dx, float dy, float scale)
|
{
|
if(hAspect != 0) return;
|
|
if (CameraPane.IMAGEFLIP)
|
{
|
dx = -dx;
|
}
|
|
if (CameraPane.ROTATECAMERA)
|
{
|
float t = dx;
|
dx = dy;
|
dy = -t;
|
}
|
|
cStatic.point1.set(location);
|
cStatic.point2.set(lookAt);
|
|
double dist = Distance();
|
double factor = 1;
|
|
scale /= shaper_fovy/60;
|
|
//if (perspective)
|
factor = dist;
|
|
LA.vecCopy(up, tempvec);
|
tempvec.x *= factor*dy/scale;
|
tempvec.y *= factor*dy/scale;
|
tempvec.z *= factor*dy/scale;
|
|
LA.vecAdd(location, tempvec, location);
|
LA.vecAdd(lookAt, tempvec, lookAt);
|
|
dx *= -1;
|
|
LA.vecCopy(right, tempvec);
|
tempvec.x *= factor*dx/scale;
|
tempvec.y *= factor*dx/scale;
|
tempvec.z *= factor*dx/scale;
|
|
LA.vecAdd(location, tempvec, location);
|
LA.vecAdd(lookAt, tempvec, lookAt);
|
|
computeTransform();
|
if(hAspect != 0)
|
{
|
location.set(cStatic.point1);
|
lookAt.set(cStatic.point2);
|
}
|
}
|
|
void BackForth(float dx, float dy, float scale)
|
{
|
if(hAspect != 0) return;
|
cStatic.point1.set(location);
|
cStatic.point2.set(lookAt);
|
if (!perspective)
|
{
|
//zoom *= Math.exp(dy);
|
|
//return;
|
}
|
|
if (scale == 0)
|
{
|
// Zoom
|
double factor = Math.exp(-dy/300.0); // (1 + dy/100);
|
|
LA.vecSub(location, lookAt, location);
|
|
cVector p = location;
|
|
p.x *= factor;
|
p.y *= factor;
|
p.z *= factor;
|
|
LA.vecAdd(location, lookAt, location);
|
}
|
else
|
{
|
LA.vecSub(location, lookAt, direction);
|
|
//scale /= Distance();
|
// scale /= shaper_fovy/20;
|
|
location.x -= dy * direction.x / scale;
|
//location.y -= dy * direction.y / scale;
|
location.z -= dy * direction.z / scale;
|
lookAt.x -= dy * direction.x / scale;
|
//lookAt.y -= dy * direction.y / scale;
|
lookAt.z -= dy * direction.z / scale;
|
}
|
|
computeTransform();
|
if(hAspect != 0)
|
{
|
// Doesn't work
|
location.set(cStatic.point1);
|
lookAt.set(cStatic.point2);
|
}
|
}
|
|
void RotateInterest(float dx, float dy)
|
{
|
right.mul(-1);
|
|
cStatic.point1.set(location);
|
location.set(lookAt);
|
lookAt.set(cStatic.point1);
|
|
if (viewCode == 0 && locationBuf != null)
|
{
|
cStatic.point1.set(locationBuf);
|
locationBuf.set(lookAtBuf);
|
lookAtBuf.set(cStatic.point1);
|
}
|
// UP.mul(-1);
|
|
RotatePosition(dx,-dy);
|
|
// UP.mul(-1);
|
right.mul(-1);
|
|
cStatic.point1.set(location);
|
location.set(lookAt);
|
lookAt.set(cStatic.point1);
|
|
if (viewCode == 0 && locationBuf != null)
|
{
|
cStatic.point1.set(locationBuf);
|
locationBuf.set(lookAtBuf);
|
lookAtBuf.set(cStatic.point1);
|
}
|
|
computeTransform();
|
}
|
|
//synchronized // june 2014
|
void computeTransform()
|
{
|
//new Exception().printStackTrace();
|
if (toScreen == toParent) // dec 2013
|
{
|
toScreen = LA.newMatrix();
|
fromScreen = LA.newMatrix();
|
}
|
|
if (locationBuf == null)
|
{
|
locationBuf = new cVector();
|
locationBuf.set(location);
|
lookAtBuf = new cVector();
|
lookAtBuf.set(lookAt);
|
upBuf = new cVector();
|
upBuf.set(UP);
|
// up2Buf = new cVector();
|
// up2Buf.set(UP2);
|
}
|
else
|
{
|
double K = 0.25;
|
|
if (!CameraPane.capsLocked || CameraPane.ambientOcclusion)
|
K = 1;
|
|
locationBuf.y = location.y * K + locationBuf.y * (1 - K);
|
lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K);
|
|
if (CameraPane.capsLocked && !CameraPane.ambientOcclusion)
|
K = 0.1;
|
|
upBuf.x = UP.x * K + upBuf.x * (1 - K);
|
upBuf.y = UP.y * K + upBuf.y * (1 - K);
|
upBuf.z = UP.z * K + upBuf.z * (1 - K);
|
upBuf.normalize();
|
// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K);
|
// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K);
|
// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K);
|
|
K = 1;
|
|
locationBuf.x = location.x * K + locationBuf.x * (1 - K);
|
locationBuf.z = location.z * K + locationBuf.z * (1 - K);
|
lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K);
|
lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K);
|
}
|
|
cVector up2 = up;
|
cVector right2 = right;
|
|
up2.x = upBuf.x;
|
up2.y = upBuf.y;
|
up2.z = upBuf.z;
|
LA.vecSub(lookAtBuf, locationBuf, away);
|
LA.vecNormalize(away);
|
LA.vecCross(away, up2, right2);
|
if (right2.length2() < 0.0001)
|
{
|
//System.out.println("right2.length2() < 0.0001");
|
// UP failed
|
up2.x = UP2.x;
|
up2.y = UP2.y;
|
up2.z = UP2.z;
|
LA.vecCross(away, up2, right2);
|
if (!(right2.length2() > 0))
|
{
|
System.out.println("NO UP VECTOR: " + up2);
|
System.out.println("lookAtBuf: " + lookAtBuf);
|
System.out.println("locationBuf: " + locationBuf);
|
System.exit(0);
|
|
// old problem...
|
assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever
|
up2.x = UP.x = 0;
|
up2.y = UP.y = 1;
|
up2.z = UP.z = 0;
|
LA.vecCross(away, up2, right2);
|
}
|
}
|
LA.vecNormalize(right2);
|
LA.vecCross(right2, away, up2);
|
if (LA.vecLen2(up2) != 0)
|
{
|
LA.vecNormalize(up2);
|
LA.matIdentity(toScreen);
|
LA.matIdentity(fromScreen);
|
for (int i=0; i < 3; i++)
|
{
|
toScreen[i][0] = right2.get(i);
|
toScreen[i][1] = up2.get(i);
|
toScreen[i][2] = -away.get(i);
|
fromScreen[0][i] = right2.get(i);
|
fromScreen[1][i] = up2.get(i);
|
fromScreen[2][i] = -away.get(i);
|
}
|
}
|
|
for (int i=0; i < 3; i++)
|
fromScreen[3][i] = locationBuf.get(i);
|
|
for (int i=0; i < 3; i++)
|
temp[3][i] = -locationBuf.get(i);
|
|
LA.matConcat(temp, toScreen, toScreen);
|
|
if (CameraPane.ROTATECAMERA)
|
{
|
double[][] rotate = { { 0,1,0,0 }, { -1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
|
//double[][] rotate_1 = { { 0,-1,0,0 }, { 1,0,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
|
|
LA.matConcat(fromScreen, rotate, fromScreen);
|
//LA.matConcat(toScreen, rotate_1, toScreen);
|
}
|
|
if (CameraPane.IMAGEFLIP)
|
{
|
double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } };
|
|
LA.matConcat(fromScreen, flip, fromScreen);
|
}
|
|
//if (this == CameraPane.lightCamera)
|
//CameraPane.lighttouched = true;
|
LA.matInvert(fromScreen, toScreen);
|
}
|
|
// void Draw(CameraPane display, Object3D /*Composite*/ root, boolean selected)
|
// {
|
// // don't draw anything aout 2013
|
// }
|
|
public void generatePOV(StringBuffer buf, int width, int height)
|
{
|
double imageAspect = (double)width / (double)height;
|
if (imageAspect > aspect)
|
width = (int)((double)height * aspect);
|
else
|
height = (int)((double)width / aspect);
|
double right = width;
|
double up = height;
|
if (perspective)
|
{
|
right = aspect;
|
up = 1;
|
}
|
buf.append("// ");
|
buf.append(perspective ? "perspective" : "orthographic");
|
buf.append(": aspect ");
|
buf.append(hAspect);
|
buf.append(" wide by ");
|
buf.append(vAspect);
|
buf.append(" high\n");
|
buf.append("camera {\n");
|
if (!perspective)
|
buf.append(" orthographic\n");
|
buf.append(" location ");
|
LA.toPOVRay(location, buf);
|
buf.append("\n sky <0,0,1>\n");
|
if (perspective)
|
{
|
buf.append(" right <");
|
buf.append(hAspect);
|
buf.append("/");
|
buf.append(vAspect);
|
buf.append(",0,0>\n up <0,0,1>\n");
|
} else
|
{
|
buf.append(" right <");
|
buf.append(width);
|
buf.append(",0,0>\n up <0,0,");
|
buf.append(height);
|
buf.append(">\n");
|
}
|
buf.append(" direction <0,");
|
buf.append(focalLength);
|
buf.append(",0>\n look_at ");
|
LA.toPOVRay(lookAt, buf);
|
buf.append("\n}\n");
|
buf.append("light_source { ");
|
LA.toPOVRay(location, buf);
|
buf.append(" color rgb <1,1,1> }\n");
|
buf.append("light_source { <0,0,500> color rgb <1,1,1> }\n\n");
|
}
|
|
static final int viewTop = 1;
|
static final int viewFront = 2;
|
static final int viewSide = 3;
|
int viewCode;
|
|
cVector location;
|
cVector lookAt;
|
|
transient cVector locationBuf;
|
transient cVector lookAtBuf;
|
transient cVector upBuf;
|
//transient cVector up2Buf;
|
|
cVector direction;
|
|
double[][] toScreen;
|
double[][] fromScreen;
|
|
boolean perspective;
|
int hAspect = 0; // Free camera
|
int vAspect;
|
double aspect;
|
double focalLength;
|
cVector background;
|
}
|