📄 builderobject.java.svn-base
字号:
package gui;import interfaces.*;import base.*;import java.awt.*;import java.util.*;public class BuilderObject extends WorldObject { public double angle = 0, width = 0, height = 0; private ArrayList<WorldVector> originalVertices; public BuilderObject() { super(); } public BuilderObject(String name, GuiObject guiObject, WorldObjectState objectState) { super(name, objectState, guiObject); } public BuilderObject(String name, GuiObject guiObject, WorldObjectState objectState, double width, double height) { super(name, objectState, guiObject); this.width = width; this.height = height; } public void setName(String name) { this.name = name; } public void setBGColor(Color bgColor) { ((GuiObject) this.guiObject).bgColor = bgColor; } public void setTexture(String img) { ((GuiObject) this.guiObject).setTexture(img); } public void setPosition(Point p) { this.objectState.position.x = p.x; this.objectState.position.y = p.y; } public void setVertices(ArrayList<WorldVector> vertices) { this.objectState.vertices = vertices; } public void setangularPosition(WorldVector angularPosition) { this.objectState.angularPosition = angularPosition; } public void rotateVertices() { //calculate the new vertices based on the object's angle of rotation //theta = angle //t = 90 - theta //c1 = a4 - hcos(t) //d1 = a4 - hsin(t) //c3 = (a4 + w) - hcos(t) //d3 = d4 - wsin(theta) //c2 = c3 - hsin(theta) //d2 = d3 - hcos(theta) double theta = Math.toRadians(angle), tau = Math.toRadians(90 - angle); if(originalVertices == null) { originalVertices = (ArrayList<WorldVector>) objectState.vertices; } WorldVector position = objectState.position; ArrayList<WorldVector> coordinates = new ArrayList<WorldVector>(); for(int i = 0; i < originalVertices.size(); i++) { coordinates.add(new WorldVector(position.x + originalVertices.get(i).x, position.y + originalVertices.get(i).y, position.z + originalVertices.get(i).z ) ); } coordinates.set(0, new WorldVector(coordinates.get(3).x - (height * Math.cos(tau)), coordinates.get(3).y - (height * Math.sin(tau)), 0)); coordinates.set(1, new WorldVector(coordinates.get(2).x - (height * Math.sin(theta)), coordinates.get(2).y - (height * Math.cos(theta)), 0)); coordinates.set(2, new WorldVector(coordinates.get(2).y - (height * Math.cos(tau)), coordinates.get(3).y - (width * Math.sin(theta)), 0)); ArrayList<WorldVector> vertices = new ArrayList<WorldVector>(); for(int i = 0; i < coordinates.size(); i++) { vertices.add(i, new WorldVector(coordinates.get(i).x - position.x, coordinates.get(i).y - position.y, 0) ); } setVertices(vertices); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -