I am having a bit of difficulty understanding what the purpose of this code might be. I put an applet into a Java decompiler and this is the code. Specifically, the line where it is setting the viewCenter is confusing. I am not sure what the purpose of this.scale might be.
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
public class SeekFlee extends Applet implements Runnable {
private Thread update;
Seeker seeker;
Seeker fleer;
float scale = 15.0F;
Vector3 viewCenter;
int framesSinceTouch;
Image canvasimage;
Graphics canvasG;
Graphics myG;
int wxsize;
int wysize;
public void init() {
super.init();
this.wxsize = (getSize()).width;
this.wysize = (getSize()).height;
resize(this.wxsize, this.wysize);
this.canvasimage = createImage(this.wxsize, this.wysize);
this.canvasG = this.canvasimage.getGraphics();
this.myG = getGraphics();
this.viewCenter = new Vector3(this.wxsize / 2.0F * this.scale, this.wysize / 2.0F * this.scale, 0.0F);
this.seeker = new Seeker();
this.fleer = new Seeker();
resetSeekers();
}
public boolean handleEvent(Event event) {
boolean returnValue = false;
return returnValue;
}
public static void main(String[] args) {
Frame f = new Frame();
SeekFlee app = new SeekFlee();
app.init();
app.start();
f.add("Center", app);
f.resize(515, 300);
f.show();
}
public void start() {
if (this.update == null) {
this.update = new Thread(this);
this.update.start();
}
}
public void stop() {
if (this.update != null && this.update.isAlive())
this.update.stop();
this.update = null;
}
public void run() {
while (true) {
repaint();
try {
Thread.sleep(33L);
} catch (InterruptedException interruptedException) {}
}
}
private void showbuffer() {
this.myG.drawImage(this.canvasimage, 0, 0, this);
}
static final Color bgColor = new Color(0.9F, 0.9F, 0.6F);
public void paint(Graphics g) {
this.canvasG.setColor(bgColor);
this.canvasG.fillRect(0, 0, this.wxsize, this.wysize);
updateSeekers();
this.canvasG.setColor(Color.black);
this.canvasG.drawRect(0, 0, this.wxsize - 1, this.wysize - 1);
showbuffer();
}
public void updateSeekers() {
this.seeker.update();
this.seeker.draw(this.canvasG, this.scale);
this.fleer.update();
this.fleer.draw(this.canvasG, this.scale);
this.fleer.touch = this.seeker.touch;
this.framesSinceTouch = this.seeker.touch ? (this.framesSinceTouch + 1) : 0;
if (this.framesSinceTouch > 15)
resetSeekers();
}
public void resetSeekers() {
this.seeker.position.setUnitRandom();
this.seeker.position.setScale(17.0F, this.seeker.position);
this.seeker.position.setSum(this.viewCenter, this.seeker.position);
this.seeker.position.z = 0.0F;
this.seeker.velocity.setUnitRandom();
this.seeker.velocity.setScale(this.seeker.maxSpeed, this.seeker.velocity);
this.seeker.velocity.z = 0.0F;
this.seeker.target.set(this.viewCenter);
this.seeker.touch = false;
this.fleer.seek = false;
this.fleer.position.set(this.seeker.position);
this.fleer.velocity.set(this.seeker.velocity);
this.fleer.target.set(this.viewCenter);
this.fleer.touch = false;
}
public void update(Graphics g) {
paint(g);
}
}
Vector3 is a class representing a 3D vector.
import java.util.Random;
public class Vector3 {
public float x;
public float y;
public float z;
public static final Vector3 zero = new Vector3();
public Vector3() {
setZero();
}
public Vector3(float x, float y, float z) {
set(x, y, z);
}
public void set(Vector3 that) {
this.x = that.x;
this.y = that.y;
this.z = that.z;
}
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
public void setZero() {
set(0.0F, 0.0F, 0.0F);
}
public boolean equals(Vector3 that) {
if (this.x != that.x ||
this.y != that.y ||
this.z != that.z)
return false;
return true;
}
public boolean equalsZero() {
return !(this.x != 0.0F || this.y != 0.0F || this.z != 0.0F);
}
public float magnitude() {
return (float)Math.sqrt(magnitudeSquared());
}
public float magnitudeSquared() {
return this.x * this.x +
this.y * this.y +
this.z * this.z;
}
public float dot(Vector3 that) {
return this.x * that.x +
this.y * that.y +
this.z * that.z;
}
static Random generator = new Random();
public void setUnitRandom() {
do {
this.x = generator.nextFloat() * 2.0F - 1.0F;
this.y = generator.nextFloat() * 2.0F - 1.0F;
this.z = generator.nextFloat() * 2.0F - 1.0F;
} while (magnitudeSquared() > 1.0F);
}
public float approximateLength() {
float a = this.x;
if (a < 0.0F)
a = -a;
float b = this.y;
if (b < 0.0F)
b = -b;
float c = this.z;
if (c < 0.0F)
c = -c;
if (a < b) {
float t = a;
a = b;
b = t;
}
if (a < c) {
float t = a;
a = c;
c = t;
}
return a * 0.9375F + (b + c) * 0.375F;
}
private static Vector3 distTemp = new Vector3();
public float distance(Vector3 v) {
synchronized (distTemp) {
distTemp.setDiff(this, v);
return distTemp.magnitude();
}
}
public float approximateDistance(Vector3 v) {
synchronized (distTemp) {
distTemp.setDiff(this, v);
return distTemp.approximateLength();
}
}
public void setSum(Vector3 a, Vector3 b) {
a.x += b.x;
a.y += b.y;
a.z += b.z;
}
public void setDiff(Vector3 a, Vector3 b) {
a.x -= b.x;
a.y -= b.y;
a.z -= b.z;
}
public void setScale(float a, Vector3 b) {
this.x = a * b.x;
this.y = a * b.y;
this.z = a * b.z;
}
public void setCross(Vector3 a, Vector3 b) {
set(a.y * b.z - a.z * b.y,
a.z * b.x - a.x * b.z,
a.x * b.y - a.y * b.x);
}
public void setInterp(float blend, Vector3 v0, Vector3 v1) {
v0.x += blend * (v1.x - v0.x);
v0.y += blend * (v1.y - v0.y);
v0.z += blend * (v1.z - v0.z);
}
public void setNormalize() {
float m = magnitude();
if (m != 0.0F)
setScale(1.0F / m, this);
}
public void setApproximateNormalize() {
float m = approximateLength();
if (m != 0.0F)
setScale(1.0F / m, this);
}
public void setApproximateTruncate(float threshold) {
float length = approximateLength();
if (length > threshold)
setScale(threshold / length, this);
}
}
edited to provide more details
lang-java
Vector3? You should provide more details and explain what you are trying to achieve. Edit the question to add details.thisis).scalemay come from a scaling value associated with some preset size of the overall UI. That having been said... I'm only guessing. If you provided more code, you might get a more definitive answer, as opposed to speculation in a comment.