first commit

This commit is contained in:
Stefano Rossi 2025-07-10 03:52:16 +02:00
commit 903adef594
Signed by: chadmin
GPG key ID: 9EFA2130646BC893
31 changed files with 2522 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View file

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/proiettile.iml" filepath="$PROJECT_DIR$/proiettile.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

26
LICENSE Normal file
View file

@ -0,0 +1,26 @@
# DON'T BE A DICK PUBLIC LICENSE
> Version 1.1, December 2016
> Copyright (C) 2024 Rossi Stefano
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document.
> DON'T BE A DICK PUBLIC LICENSE
> TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
1. Do whatever you like with the original work, just don't be a dick.
Being a dick includes - but is not limited to - the following instances:
1a. Outright copyright infringement - Don't just copy this and change the name.
1b. Selling the unmodified original with no work done what-so-ever, that's REALLY being a dick.
1c. Modifying the original work to contain hidden harmful content. That would make you a PROPER dick.
2. If you become rich through modifications, related works/services, or supporting the original work,
share the love. Only a dick would make loads off this work and not buy the original work's
creator(s) a pint.
3. Code is provided with no warranty. Using somebody else's code and bitching when it goes wrong makes
you a DONKEY dick. Fix the problem yourself. A non-dick would submit the fix back.

45
README.md Normal file
View file

@ -0,0 +1,45 @@
# Projectile Motion
This is a 2D implementation of the physical formula for projectile motion.
![img.png](img.png)
$$ x(t) = x_0 + \frac{1}{2} a_x t^2 + v_{0x} t $$
Also, during the shock with the ground, the projectile will lose some energy.
This is simulated with a coefficient of restitution.
Then, when not bouncing and only sliding on the ground, the projectile will lose energy due to friction.
## Requirements
- Java (6 to) 8 (max, recommended)
- NetBeans (highly recommended)
Java Applets have been dropped with Java 9. So you need an older versione to run this project.
Java 8 is the preferred version. Until Java 6 should be ok.
Problems running the project are expected, applets are deprecated and not supported by modern browsers.**
This is a NetBeans Project. Using NetBeans isn't mandatory but recommended for the built-in applet runner.
You can run the GrigliaApplet.java class with netbeans.
[NetBeans Instructions](https://netbeans.apache.org/tutorial/main/kb/docs/java/javase-jdk8/)
Alternatively, you can use IntellijJ IDEA with the [Applet runner plugin](https://plugins.jetbrains.com/plugin/16682-applet-runner) (not tested).
## Installation and run
Clone the repo:
```bash
git clone git@gitlab.com:stefanorossiti/projectiles.git
```
Run `AppletProiettile.java` with your preferred IDE (NetBeans is recommended)
using
java 8.
## License
All my work is released under [DBAD](https://www.dbad-license.org/) license.

3
applet.policy Normal file
View file

@ -0,0 +1,3 @@
grant {
permission java.security.AllPermission;
};

73
build.xml Normal file
View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="proiettile" default="default" basedir=".">
<description>Builds, tests, and runs the project proiettile.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="proiettile-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

View file

@ -0,0 +1,28 @@
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<!--
*** GENERATED applet HTML launcher - DO NOT EDIT IN 'BUILD' FOLDER ***
If you need to modify this HTML launcher file (e.g., to add applet parameters),
copy it to where your applet class is found in the SRC folder. If you do this,
the IDE will use it when you run or debug the applet.
Tip: To exclude an HTML launcher from the JAR file, use exclusion filters in
the Packaging page in the Project Properties dialog.
For more information see the online help.
-->
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="proiettile/AppletProiettile.class" width=350 height=200></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>

View file

View file

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 KiB

BIN
build/classes/img/cann.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

3
manifest.mf Normal file
View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1799
nbproject/build-impl.xml Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
build.xml.data.CRC32=e815d6db
build.xml.script.CRC32=8c58e42b
build.xml.stylesheet.CRC32=f85dc8f2@1.111.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=e815d6db
nbproject/build-impl.xml.script.CRC32=62dc778f
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.111.0.48

View file

View file

@ -0,0 +1,8 @@
compile.on.save=true
do.depend=false
do.jar=true
do.jlink=false
javac.debug=true
javadoc.preview=true
jlink.strip=false
user.properties.file=C:\\Users\\Administrator\\AppData\\Roaming\\NetBeans\\22\\build.properties

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/D:/Projects/Archive/proiettile/src/proiettile/AppletProiettile.java</file>
<file>file:/D:/Projects/Archive/proiettile/src/proiettile/ListenerProiettile.java</file>
</group>
</open-files>
</project-private>

View file

@ -0,0 +1,89 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=proiettile
application.vendor=Administrator
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/proiettile.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=1.7
javac.target=1.7
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
jlink.launcher=false
jlink.launcher.name=proiettile
main.class=proiettile.Proiettile
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=Zulu_8.0.412_8
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=-Djava.security.policy=applet.policy
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

16
nbproject/project.xml Normal file
View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>proiettile</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

11
proiettile.iml Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

BIN
src/img/cann.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -0,0 +1,187 @@
package proiettile;
/************************************************************
* Autore: Rossi Stefano
* Nome: AppletProiettile
* Descrizione: simula la fisica del lancio di un proiettile
* tramite i parametri inseriti
************************************************************/
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class AppletProiettile extends Applet implements Runnable, MouseMotionListener, MouseListener, ListenerProiettile{
Thread thAgg = new Thread(this);
Image imgBuff; //dichiarazione oggetti per doppio buffering
Graphics grafBuff;
Point puntaV = new Point(); // punta del vettore velocita
Point piedeV = new Point(); // piede del vettore velocita
Point originAx = new Point(); //origine del diagramma cartesiano
double intV;
double angV;
int heightP; //altezza e larghezza del proiettile
int widthP;
Proiettile[] p = new Proiettile[62]; //max proiettili
int pCNT; //conteggio dei proiettii
double lungCampo, altCampo; //altezza e lunghezza campo in pixel
Image imgCann;
Image imgBgCamp;
public void init(){
this.setSize(1200, 600);
imgBuff = createImage(1200, 600);
grafBuff = imgBuff.getGraphics();
imgCann = getImage(getCodeBase(), "img/cann.png");
imgBgCamp = getImage(getCodeBase(), "img/bgCampo.png");
//System.out.println(getCodeBase());
this.addMouseMotionListener(this);
this.addMouseListener(this);
originAx.setLocation(50, 550);
heightP = 13;
widthP = 13;
resetV();
lungCampo = 1100;
altCampo = 500;
pCNT = 0;
//solo se il repaint e gestito dall applet
//thAgg.start();
}
@Override
public void update(Graphics g){
paint(g);
}
@Override
public void paint(Graphics g){
//cancello tutto in grafbuff
grafBuff.clearRect(0, 0,imgBuff.getWidth(this), imgBuff.getHeight(this));
//disegno un quadrato per i bordi
grafBuff.drawRect((int)originAx.getX(), (int)(originAx.getY() - altCampo), (int)lungCampo, (int) altCampo);
//disegno i proiettili rimanenti in basso
for(int i = 1; i < p.length - pCNT; i++){
grafBuff.fillOval((int)originAx.getX() + 5*(i-1) + widthP*(i-1) + 5,(int)originAx.getY() + 8, widthP, heightP);
}
//disegno l immagine del cannone e dello sfondo del campo
grafBuff.drawImage(imgCann, (int)originAx.getX() - imgCann.getWidth(this), (int)originAx.getY() - imgCann.getHeight(this)/2, this);
grafBuff.drawImage(imgBgCamp, (int)originAx.getX(), (int)(originAx.getY() - altCampo), this);
//disegno i proiettile sparati nel campo
for(int i = 0; i < pCNT && i < p.length && p[i] != null; i++){
grafBuff.fillOval((int)originAx.getX() + p[i].getX() - 5, (int)originAx.getY() - p[i].getY() - heightP, widthP, heightP);
}
//disegno il vettore V con i suoi parametri se possibile
if(piedeV.getX() != -1){
grafBuff.drawLine((int)piedeV.getX(), (int)piedeV.getY(), (int)puntaV.getX(), (int)puntaV.getY());
grafBuff.drawString("|V| = " + String.valueOf(Math.rint(intV*100)/100) + "px/sec", (int)(puntaV.getX()/2 - piedeV.getX()/2 + piedeV.getX()), (int)(puntaV.getY()/2 - piedeV.getY()/2 + piedeV.getY() + 10));
grafBuff.drawString("angV = " + String.valueOf(Math.rint(Math.toDegrees(angV)*100)/100) + "°", (int)(puntaV.getX()/2 - piedeV.getX()/2 + piedeV.getX()), (int)(puntaV.getY()/2 - piedeV.getY()/2 + piedeV.getY() + 25));
}
g.drawImage(imgBuff, 0, 0, this);
}
@Override
public void run(){
while(this.thAgg.isAlive()){
repaint();
System.out.println("repaint");
try{
Thread.sleep(1000);
}catch(Exception e){
System.out.println("thread exception");
}
}
}
//azzero i valori di V
private void resetV(){
piedeV.setLocation(-1,-1);
puntaV.setLocation(-1,-1);
intV = 0;
angV = 0;
}
//in questo metodo calcolo il vettore n coordinate polari di V
private void computeV(){
double vx = puntaV.getX() - piedeV.getX(); //componente orizzontale x di V
double vy = piedeV.getY() - puntaV.getY(); //componente orizzontale y di V x0 e in alto
intV = Math.sqrt(vx*vx + vy*vy);
angV = Math.atan(vy/vx); //radianti
}
@Override
public void mousePressed(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1){
puntaV.setLocation(e.getPoint());
}
}
@Override
public void mouseDragged(MouseEvent e) {
if(e.getButton() == MouseEvent.BUTTON1){
piedeV.setLocation(e.getPoint());
computeV();
repaint();
}
}
@Override
public void mouseReleased(MouseEvent e) {
//istanzio un nuovo proiettile e incremento la conta dei proiettili se possibile
if(pCNT < p.length){
p[pCNT] = new Proiettile(0, 0, widthP, heightP, lungCampo, altCampo, intV, angV, 9.81, 40, 5, this);
pCNT++;
//se ho sparato tutti i proiettili cambio l immagine del cannone con quella vuota
if(pCNT == p.length){
imgCann = getImage(getCodeBase(), "img/cannEmpty.png");
}
}
//reimposto le coordinate dei punti del vettore fuori dal contesto grafico
resetV();
repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseClicked(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseEntered(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void mouseExited(MouseEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void hasMoved(Point newPos) {
//System.out.println("mosso");
repaint();
}
}

View file

@ -0,0 +1,6 @@
package proiettile;
import java.awt.Point;
public interface ListenerProiettile{
public void hasMoved(Point newPos);
}

View file

@ -0,0 +1,182 @@
package proiettile;
import java.awt.Point;
public class Proiettile implements Runnable{
Point position; //posizione del proiettile
int widthP, heightP;
double maxX, maxY; //quanto in alto e in lungo puo andare il priettile prima di rimbalzare
private ListenerProiettile lp;
Thread t;
double intV; //la velocita del priettile in pixel al secondo
double angV; //angolo della velocita del proiettile
double g; //pixel al secondo
double atrTerreno; //attrito dinamico terreno deceleraz pixel/sec
double enrgAssPerc; //percentuale energia cinetica ssorbita dopo l impatto con una parete
public Proiettile(double x, double y, int widthP, int heightP, double maxX, double maxY, double vProj, double angvProj, double gravity, double enrgAssPerc, double atrTerreno, ListenerProiettile lp){
this.lp = lp;
position = new Point((int)x, (int)y);
this.maxX = maxX;
this.maxY = maxY;
this.g = gravity;
this.widthP = widthP;
this.heightP = heightP;
//controllo se la percentuale di energia assorbita e compresa tra 0 e 100 se no la imposto correttamente
if(enrgAssPerc >= 0 && enrgAssPerc <= 100){
this.enrgAssPerc = enrgAssPerc/100; //percentuale in decimale
}else if(enrgAssPerc < 0){
this.enrgAssPerc = 0;
}else{
this.enrgAssPerc = 100;
}
this.atrTerreno = atrTerreno;
t = new Thread(this);
this.intV = vProj/5;
this.angV = angvProj;
t.start();
}
private void newPos(){
//se la veloci del proiettie non e 0 allora calcolo la nuova posizione
if(intV != 0){
double time = 0.1; //ricalcolo la posizione dopo 0.1 dec di secondo
//componente x della velocita
double vx = this.intV * Math.cos(angV);
//componente y della velocita
double vy = this.intV * Math.sin(angV);
//calcolo la nuova posizione
// MRU Sf = si + v*t
double nextX = this.position.getX() + vx * time;
// MRUA
double nextY = this.position.getY() + vy * time - 0.5 * g * time * time;
//System.out.println("vx: " + vx + " vy: " + vy);
//salvo la nuova positione
this.position.setLocation(nextX, nextY);
//calcolo la nuova velocita
vy = vy - g * time; //calcolo di quanto g fa diminuore la velocita verticale
//se la pallina tocca l terra rimbalza
//se il modulo della sua velocita e minore della gravita si ferma in vy
//altrimenti controlla se la pallina tocca il cielo
if(this.position.getY() < 0 || this.position.getY() + heightP > maxY){
vy = invertVY(vy);
//se l intensita della velocita y e min di quanto puo essere decell da g in questo lasso di tempo viene settata a 0 esatto
if(Math.abs(vx) < g * time*time){
vy = 0;
}
}
//se la pallina tocca il muro destro rimbalza
//se il modulo della sua velocita e minore della gravita si ferma in vy
//altrimenti se tocca quello di sx
if(this.position.getX() + widthP > maxX || this.position.getX() < 0){
vx = invertVX(vx);
}
//faccio in modo di rallentare leggermente vx se necessario
vx = slowVX(vx, vy, time);
//System.out.println(vx);
//rivalvolo angolo e intensita con la nuova vy
this.intV = Math.sqrt(vy*vy + vx*vx);
this.angV = Math.atan(vy/vx);
//per imprecisione della trigonometria l angolo perde il segno con la tangente quindi bisogna calcolarlo manualmente
//questo vuol dire invertire il segno o diminuire/aumentare l angolo di PI radianti
if(vx < 0){
this.angV -= Math.PI;
}
if(vx==0 && vy == 0){
this.intV = 0;
this.angV = 0;
}
//System.out.println(vx);
}
}
public int getX(){
return (int)this.position.getX();
}
public int getY(){
return (int)this.position.getY();
}
private double invertVX(double vx){
//se l oggetto sta andando in avanti
if(vx > 0) {
this.position.setLocation(maxX - widthP, this.position.getY());
}else if(vx < 0){
this.position.setLocation(0, this.position.getY());
}
return vx *= (-1 * (1- enrgAssPerc));
}
private double invertVY(double vy){
//sel oggetto sta cadendo
if(vy < 0) {
this.position.setLocation(this.position.getX(), 0);
}
//se l oggetto sta salendo
else if (vy > 0){
this.position.setLocation(this.position.getX(), maxY - heightP);
}
return vy *= (-1 * (1 - enrgAssPerc));
}
private double slowVX(double vx, double vy, double time){
//se il proiettile tocca il bordo alto o basso
if(this.position.getY() == 0 || this.position.getY() - heightP == maxY){
//se la velocita del poiettile e minore di quanto verra decrementata dall attrito allora si ferma
if(Math.abs(vx) < atrTerreno * time){
vx = 0;
}
//se va in aavanti
if(vx > 0){
return vx - atrTerreno * time;
//se va indietro
}else if (vx < 0){
return vx + atrTerreno * time;
//se e fermo
}else{
return 0;
}
}
else{
return vx;
}
}
@Override
public void run(){
boolean flag = true;
while(flag){
try{
Thread.sleep(20); //pausa
newPos(); // calcolo la nuova posizione dopo la pausa
lp.hasMoved(this.position);
//fermo il thread se il poiettile e fermo
if(intV == 0 && angV == 0){
this.t.interrupt();
}
}catch(InterruptedException e){
flag = false;
}
}
//System.out.println("stopped");
}
}