mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-28 23:39:45 +01:00
neue modelle + fixing
This commit is contained in:
parent
b8cd71120f
commit
a6fec62fa0
@ -7,22 +7,26 @@
|
|||||||
|
|
||||||
package pp.battleship.client.gui;
|
package pp.battleship.client.gui;
|
||||||
|
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.material.RenderState.BlendMode;
|
import com.jme3.material.RenderState.BlendMode;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
import com.jme3.scene.Node;
|
import com.jme3.scene.Node;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
import com.jme3.scene.shape.Box;
|
import com.jme3.scene.shape.Box;
|
||||||
import com.jme3.scene.shape.Cylinder;
|
import com.jme3.scene.shape.Cylinder;
|
||||||
|
|
||||||
import pp.battleship.client.BattleshipApp;
|
import pp.battleship.client.BattleshipApp;
|
||||||
import pp.battleship.model.Battleship;
|
import pp.battleship.model.Battleship;
|
||||||
import pp.battleship.model.Rotation;
|
import pp.battleship.model.Rotation;
|
||||||
import pp.battleship.model.ShipMap;
|
import pp.battleship.model.ShipMap;
|
||||||
import pp.battleship.model.Shot;
|
import pp.battleship.model.Shot;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull;
|
|
||||||
import static pp.util.FloatMath.HALF_PI;
|
import static pp.util.FloatMath.HALF_PI;
|
||||||
import static pp.util.FloatMath.PI;
|
import static pp.util.FloatMath.PI;
|
||||||
|
|
||||||
@ -34,7 +38,12 @@ import static pp.util.FloatMath.PI;
|
|||||||
*/
|
*/
|
||||||
class SeaSynchronizer extends ShipMapSynchronizer {
|
class SeaSynchronizer extends ShipMapSynchronizer {
|
||||||
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
private static final String UNSHADED = "Common/MatDefs/Misc/Unshaded.j3md"; //NON-NLS
|
||||||
private static final String KING_GEORGE_V_MODEL = "Models/KingGeorgeV/KingGeorgeV.j3o"; //NON-NLS
|
private static final String KING_GEORGE_V_MODEL = "Models/Transporter/cr90.j3o"; //NON-NLS
|
||||||
|
private static final String TIE_FIGHTER = "Models/TieFighter/TieFighter.j3o"; //NON-NLS
|
||||||
|
private static final String TRANSPORTER = "Models/KingGeorgeV/KingGeorge.j3o"; //NON-NLS
|
||||||
|
//private static final String VENATOR = "Models/Venator/Venator.j3o"; //NON-NLS
|
||||||
|
private static final String WING = "Models/Wing/Wing.j3o"; //NON-NLS
|
||||||
|
|
||||||
private static final String COLOR = "Color"; //NON-NLS
|
private static final String COLOR = "Color"; //NON-NLS
|
||||||
private static final String SHIP = "ship"; //NON-NLS
|
private static final String SHIP = "ship"; //NON-NLS
|
||||||
private static final String SHOT = "shot"; //NON-NLS
|
private static final String SHOT = "shot"; //NON-NLS
|
||||||
@ -107,8 +116,9 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
|
|
||||||
geometry.setMaterial(createColoredMaterial(color));
|
geometry.setMaterial(createColoredMaterial(color));
|
||||||
geometry.rotate(HALF_PI, 0f, 0f);
|
geometry.rotate(HALF_PI, 0f, 0f);
|
||||||
// compute the center of the shot in world coordinates
|
|
||||||
geometry.setLocalTranslation(shot.getY() + 0.5f, 0f, shot.getX() + 0.5f);
|
// compute the center of the shot in world coordinates, with an additional 2f height
|
||||||
|
geometry.setLocalTranslation(shot.getY() + 0.5f, 2f + height / 2, shot.getX() + 0.5f);
|
||||||
|
|
||||||
return geometry;
|
return geometry;
|
||||||
}
|
}
|
||||||
@ -141,9 +151,21 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
* @return the spatial representing the battleship
|
* @return the spatial representing the battleship
|
||||||
*/
|
*/
|
||||||
private Spatial createShip(Battleship ship) {
|
private Spatial createShip(Battleship ship) {
|
||||||
return ship.getLength() == 4 ? createBattleship(ship) : createBox(ship);
|
if (ship.getLength() == 1) {
|
||||||
|
return createTie_Fighter(ship);
|
||||||
|
} else if (ship.getLength() == 2) {
|
||||||
|
return createWing(ship);
|
||||||
|
} else if (ship.getLength() == 3) {
|
||||||
|
return createTransporter(ship);
|
||||||
|
} else if (ship.getLength() == 4) {
|
||||||
|
return createBattleship(ship);
|
||||||
|
} else {
|
||||||
|
return createBox(ship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a simple box to represent a battleship that is not of the "King George V" type.
|
* Creates a simple box to represent a battleship that is not of the "King George V" type.
|
||||||
*
|
*
|
||||||
@ -181,7 +203,7 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a detailed 3D model to represent a "King George V" battleship.
|
* Creates a detailed 3D model to represent all battleships.
|
||||||
*
|
*
|
||||||
* @param ship the battleship to be represented
|
* @param ship the battleship to be represented
|
||||||
* @return the spatial representing the "King George V" battleship
|
* @return the spatial representing the "King George V" battleship
|
||||||
@ -189,12 +211,91 @@ class SeaSynchronizer extends ShipMapSynchronizer {
|
|||||||
private Spatial createBattleship(Battleship ship) {
|
private Spatial createBattleship(Battleship ship) {
|
||||||
final Spatial model = app.getAssetManager().loadModel(KING_GEORGE_V_MODEL);
|
final Spatial model = app.getAssetManager().loadModel(KING_GEORGE_V_MODEL);
|
||||||
|
|
||||||
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot()), 0f);
|
|
||||||
model.scale(1.48f);
|
// Berechne den Rotationswinkel
|
||||||
|
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||||
|
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||||
|
model.rotate(0f, rotationAngle, -HALF_PI);
|
||||||
|
model.scale(1.2f);
|
||||||
model.setShadowMode(ShadowMode.CastAndReceive);
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|
||||||
|
// Bestimme die Verschiebung basierend auf der Rotation
|
||||||
|
Vector3f translation = model.getLocalTranslation();
|
||||||
|
|
||||||
|
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||||
|
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||||
|
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||||
|
translation = translation.subtract(0,0,1); // Nach hinten auf der Z-Achse, und um 2f nach oben
|
||||||
|
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||||
|
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||||
|
translation = translation.subtract(1,0,0); // Nach hinten auf der X-Achse, und um 2f nach oben
|
||||||
|
}
|
||||||
|
|
||||||
|
model.setLocalTranslation(translation);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
private Spatial createTransporter(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(TRANSPORTER);
|
||||||
|
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||||
|
|
||||||
|
model.rotate(-HALF_PI, calculateRotationAngle(ship.getRot())+ PI, 0f);
|
||||||
|
model.scale(0.008f);
|
||||||
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||||
|
Vector3f translation = model.getLocalTranslation();
|
||||||
|
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||||
|
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||||
|
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||||
|
translation = translation.add(0,0,1f); // Nach hinten auf der Z-Achse, und um 2f nach oben
|
||||||
|
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||||
|
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||||
|
translation = translation.add(1f,0,0); // Nach hinten auf der X-Achse, und um 2f nach oben
|
||||||
|
}
|
||||||
|
|
||||||
|
model.setLocalTranslation(translation);
|
||||||
|
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
private Spatial createWing(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(WING);
|
||||||
|
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||||
|
|
||||||
|
// Berechne den Rotationswinkel
|
||||||
|
float rotationAngle = calculateRotationAngle(ship.getRot())+HALF_PI;
|
||||||
|
model.rotate(0f, rotationAngle, 0f);
|
||||||
|
model.scale(0.0008f);
|
||||||
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
|
||||||
|
// Bestimme die Verschiebung basierend auf der Rotation
|
||||||
|
Vector3f translation = model.getLocalTranslation();
|
||||||
|
|
||||||
|
// Bei 0 oder 180 Grad wird auf der Z-Achse verschoben, bei 90 oder 270 Grad auf der X-Achse
|
||||||
|
if (rotationAngle == 0 || rotationAngle == FastMath.PI) {
|
||||||
|
// Verschiebe auf der Z-Achse und um 2f nach oben
|
||||||
|
translation = translation.add(0,0,0); // Nach hinten auf der Z-Achse, und um 2f nach oben
|
||||||
|
} else if (rotationAngle == FastMath.HALF_PI || rotationAngle == 3 * FastMath.HALF_PI) {
|
||||||
|
// Verschiebe auf der X-Achse und um 2f nach oben
|
||||||
|
translation = translation.add(0,0,0); // Nach hinten auf der X-Achse, und um 2f nach oben
|
||||||
|
}
|
||||||
|
|
||||||
|
model.setLocalTranslation(translation);
|
||||||
|
|
||||||
|
return model;
|
||||||
|
|
||||||
|
}
|
||||||
|
private Spatial createTie_Fighter(Battleship ship) {
|
||||||
|
final Spatial model = app.getAssetManager().loadModel(TIE_FIGHTER);
|
||||||
|
|
||||||
|
model.rotate(-0f, calculateRotationAngle(ship.getRot()), 0f);
|
||||||
|
model.scale(0.07f);
|
||||||
|
model.setShadowMode(ShadowMode.CastAndReceive);
|
||||||
|
model.setLocalTranslation(new Vector3f(model.getLocalTranslation().x, 2f, model.getLocalTranslation().z));
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the rotation angle for the specified rotation.
|
* Calculates the rotation angle for the specified rotation.
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 354 KiB |
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
Binary file not shown.
After Width: | Height: | Size: 220 KiB |
@ -34,11 +34,11 @@ public class ModelExporter extends SimpleApplication {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
// export("Models/KingGeorgeV/King_George_V.obj", "KingGeorgeV.j3o");//NON-NLS
|
export("Models/KingGeorge.obj", "KingGeorge.j3o");//NON-NLS passt
|
||||||
// export("Models/TieFighter/Tie_Fighter.obj", "Tie_Fighter.j3o");
|
//export("Models/Wing.obj", "Wing.j3o");
|
||||||
// export("Models/Transporter/Transporter.obj", "Transporter.j3o"); //NON-NLS
|
// export("Models/Transporter/Transporter.obj", "Transporter.j3o"); //NON-NLS passt
|
||||||
//export("Models/X_Wing/X_Wing.obj", "X_Wing.j3o"); //NON-NLS
|
// export("Models/TieFighter.obj", "TieFighter.j3o"); //NON-NLS
|
||||||
export("Models/Venator/Venator.obj", "Venator.j3o"); //NON-NLS
|
// export("Models/Venator/Venator.obj", "Venator.j3o"); //NON-NLS kickt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
16605
Projekte/battleship/converter/src/main/resources/Models/KingGeorge.obj
Normal file
16605
Projekte/battleship/converter/src/main/resources/Models/KingGeorge.obj
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
31138
Projekte/battleship/converter/src/main/resources/Models/TieFighter.obj
Normal file
31138
Projekte/battleship/converter/src/main/resources/Models/TieFighter.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Projekte/battleship/converter/src/main/resources/Models/Wing.j3o
Normal file
BIN
Projekte/battleship/converter/src/main/resources/Models/Wing.j3o
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user