Totally rewroat the code for collision of solid objects. Also added an example applic...
[alterverse.git] / src / org / alterverse / world / Point.java
blob96a2cd66e3a824b1081137dc994961f88337be51
1 package org.alterverse.world;
3 public class Point {
4 public double x;
5 public double y;
6 public double z;
7 public Point() {
8 x=0;
9 y=0;
10 z=0;
13 public Point(double degrees, double speed) {
14 // ignore y
15 x=speed*Math.sin(Math.toRadians(degrees));
16 y = 0;
17 z = -speed*Math.cos(Math.toRadians(degrees));
20 public Point(double x, double y, double z) {
21 this.x = x;
22 this.y = y;
23 this.z = z;
26 public Point trim(double spead) {
27 return new Point(Math.min(x,spead),Math.min(y,spead), Math.min(z,spead));
30 public Point trim(Point p) {
31 return new Point(Math.min(x,p.x), Math.min(y,p.y), Math.min(z,p.z));
34 public Point bound(double min, double max) {
35 double lx = Math.abs(x);
36 double ly = Math.abs(y);
37 double lz = Math.abs(z);
38 double mx,my,mz;
39 if (lx<min)
40 mx=min;
41 else if (lx > max)
42 mx=max;
43 else
44 mx=lx;
45 if (ly<min)
46 my=min;
47 else if (ly > max)
48 my=max;
49 else
50 my=ly;
51 if (lz<min)
52 mz=min;
53 else if (lz > max)
54 mz=max;
55 else
56 mz=lz;
57 Point p=new Point(x,y,z);
58 if (p.x!=0)
59 p.x=p.x/lx*mx;
60 if (p.y!=0)
61 p.y=p.y/ly*my;
62 if (p.z!=0)
63 p.z=p.z/lz*mz;
64 return p;