Java - Animacion cañon

 
Vista:
sin imagen de perfil

Animacion cañon

Publicado por juan jose (25 intervenciones) el 02/04/2017 18:10:01
Buenos días, necesito hacer un programa que es un cañón, solo me dan un angulo, y tengo que calcular la trayectoria del disparo y simular el disparo utilizando hilos alguien me podría ayudar a darme algunas ideas muchas gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 349
Bronce
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Animacion cañon

Publicado por Andrés (340 intervenciones) el 11/04/2017 06:57:47
Ideas para que comiences.

Screenshot-from-2017-04-11-00-03-37

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
 
/**
 *
 * @author andreas
 */
public class SimulaTiro extends JFrame {
 
    private int x1 = 0;
    private int y1 = 0;
    private double theta = 45;
 
    class Point {
 
        private int x;
        private int y;
 
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
 
        public int getX() {
            return x;
        }
 
        public void setX(int x) {
            this.x = x;
        }
 
        public int getY() {
            return y;
        }
 
        public void setY(int y) {
            this.y = y;
        }
 
    }
 
    private List<Point> points = new ArrayList<Point>();
 
    class SimulaTiroThread extends Thread {
 
        public void run() {
 
 
        double gravity = 9.81;
        double v0 = 60;
 
        double sinTheta = Math.sin(Math.toRadians(theta));
        double cosTheta = Math.cos(Math.toRadians(theta));
 
        double t = 2 * v0 * sinTheta / gravity;
 
        double deltaT = t / 1000;
 
        double cnt = 0;
 
        while (cnt < t) {
 
            double x = v0 * cosTheta * cnt;
            double y = v0 * sinTheta * cnt - .5 * gravity * cnt * cnt;
            points.add(new Point(15 + (int) x, 415 - (int) y));
 
            cnt += deltaT;
        }
 
        }
 
    }
 
    public SimulaTiro() {
 
        try {
            SimulaTiroThread simulaTiroThread = new SimulaTiroThread();
            simulaTiroThread.start();
            simulaTiroThread.join();
            setSize(800, 450);
            setLocation(100, 100);
            setVisible(true);
            this.setTitle("Simulacion cañon");
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        } catch (InterruptedException ex) {
            Logger.getLogger(SimulaTiro.class.getName()).log(Level.SEVERE, null, ex);
        }
 
 
    }
 
    public void paint(Graphics g) {
 
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
 
        Dimension d = this.getSize();
 
        super.paintComponents(g);
 
        AffineTransform transform = new AffineTransform();
        transform.rotate(Math.toRadians(-theta), 15, 415);
        AffineTransform old = g2.getTransform();
        g2.transform(transform);
 
        g2.setColor(Color.BLACK);
 
        g2.fillOval(x1, 400, 31, 31);
        Polygon poly = new Polygon();
        poly.addPoint(15, 400);
        poly.addPoint(60, 410);
        poly.addPoint(60, 420);
        poly.addPoint(15, 431);
        g2.setColor(Color.BLACK);
        g2.fillPolygon(poly);
        g2.setColor(Color.RED);
 
        g2.drawLine(15, 415, 100, 415);
 
        g2.setTransform(old);
        g2.setColor(Color.GRAY);
        g2.fill(new Rectangle2D.Double(0, 431, 31, 10));
 
        g2.setColor(Color.WHITE);
 
        g2.drawLine(15, 0, 15, (int) d.getHeight());
        g2.drawLine(0, 415, (int) d.getWidth(), 415);
 
        g2.setColor(Color.BLUE);
 
        for(Point p : points) {
            g2.drawOval(p.getX(), p.getY(), 1, 1);
        }
 
    }
 
    public static void main(String argv[]) {
        SimulaTiro c = new SimulaTiro();
    }
 
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar