?? graphicparallelogram.java
字號:
/*
Netwar
Copyright (C) 2002 Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
This file is part of Netwar.
Netwar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Netwar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Netwar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package netwar.utils.vectorgraphics;
import netwar.utils.*;
import java.awt.Color;
import netwar.game.GameViewer;
/** Primitive GraphicThing.
* This represents a parallelogram to be drawn filling the space between
* four points in a particular color.
* No warranty is made for the correctness of the results if the class is
* improperly used: The points should be provided to the constructor in
* adjacent order (i.e. two consecutive arguments are consecutive vertices).
* It is the responsibility of the creating class and any other classes that
* call this to keep the points in a Parallelogram shape.
*/
public class GraphicParallelogram extends GraphicThing {
private SelfConvertingPoint a;
private SelfConvertingPoint b;
private SelfConvertingPoint c;
private SelfConvertingPoint d;
private Color col;
/** Create a GraphicParallelogram without external point control.
* The object can only be moved by calling translate and rotate.
* @param A One initial endpoint.
* @param B Another initial endpoint.
* @param C Another initial endpoint.
* @param D Yet another initial endpoint.
* @param COL The color of the line segment.
*/
public GraphicParallelogram(Point3D A, Point3D B, Point3D C, Point3D D, Color COL) {
a = new SelfConvertingPoint(A);
b = new SelfConvertingPoint(B);
c = new SelfConvertingPoint(C);
d = new SelfConvertingPoint(D);
col = COL;
}
/** Create a GraphicParallelogram with external point control.
* The object can be manipulated by changing A, B, C and D outside the class.
* @param A One endpoint.
* @param B Another endpoint.
* @param C Another endpoint.
* @param D Yet another endpoint.
* @param COL The color of the line segment.
*/
public GraphicParallelogram(SelfConvertingPoint A, SelfConvertingPoint B, SelfConvertingPoint C, SelfConvertingPoint D, Color COL) {
a = A;
b = B;
c = C;
d = D;
col = COL;
}
public float getZ(Transform t) {
Point3D pt = new Point3D(a);
float Z;
Z = a.getScreenPoint(t).z;
Z += b.getScreenPoint(t).z;
Z += c.getScreenPoint(t).z;
Z += d.getScreenPoint(t).z;
Z /= 4;
return Z;
}
public void draw(GameViewer v) {
if(!isOnScreen(v.getTransform()))
return;
v.setColor(col);
v.drawTriangle(a,b,c);
v.drawTriangle(a,d,c);
}
public GraphicThing rotate(Point3D axisPt, Point3D axisDir, int angle)
{
a.doRotate(axisPt, axisDir, angle);
b.doRotate(axisPt, axisDir, angle);
c.doRotate(axisPt, axisDir, angle);
d.doRotate(axisPt, axisDir, angle);
update();
return this;
}
public GraphicThing translate(Point3D offset)
{
a.doSum(offset);
b.doSum(offset);
c.doSum(offset);
d.doSum(offset);
update();
return this;
}
public boolean isOnScreen(Transform t) {
return (a.isOnScreen(t) || b.isOnScreen(t) || c.isOnScreen(t) || d.isOnScreen(t));
}
public void explode(Point3D epicenter) {
//This is a case where the parallelogram shape is needed for correctness of function.
kill();
unlink();
Point3D center = getCenter();
Point3D velocity = center.getDifference(epicenter);
netwar.game.Projectile.newProjectile(new netwar.game.projectile.DebrisFragment(this), center, velocity, 0, 0, 100, null, null);
}
Point3D getCenter() {
return a.getSum(c).doProduct(0.5f);
}
void unlink() {
a = new SelfConvertingPoint(a);
b = new SelfConvertingPoint(b);
c = new SelfConvertingPoint(c);
d = new SelfConvertingPoint(d);
}
public GraphicThing copy() {
GraphicParallelogram gp = new GraphicParallelogram(a,b,c,d,col);
gp.unlink();
return gp;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -