Skip to content

Commit 53b96dd

Browse files
committed
Added object type constants.
Added the calculated energy to the Contact class in prep for implementing real contact handling.
1 parent 8bed448 commit 53b96dd

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

sigem/src/main/java/sigem/es/ObjectType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@
4646
* @author Paul Speed
4747
*/
4848
public class ObjectType implements EntityComponent {
49-
49+
50+
public static final String TYPE_SHIP = "ship";
51+
public static final String TYPE_PLANET = "planet";
52+
public static final String TYPE_ASTEROID = "asteroid";
53+
public static final String TYPE_THRUST = "thrust";
54+
public static final String TYPE_MISSILE = "missile";
55+
5056
private int type;
5157

5258
protected ObjectType() {

sigem/src/main/java/sigem/sim/CollisionSystem.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void endFrame( SimTime time ) {
133133
// and one overtakes the other then the speeds will have the
134134
// same signs... and we still need the difference.
135135
double energy = Math.abs(speed2 - speed1);
136+
contact.energy = energy;
136137
//log.info("speed1:" + speed1 + " speed2:" + speed2 + " energy:" + energy);
137138

138139
// We want the collisions to be elastic... if we only
@@ -171,16 +172,17 @@ private Contact checkContact( Body b1, Body b2 ) {
171172
z -= arenaSize.z;
172173
}
173174
double dist = Math.sqrt(x * x + z * z);
174-
if( dist < b1.radius + b2.radius ) {
175-
log.info("contact:" + b1.bodyId + " and:" + b2.bodyId);
176-
Contact c = new Contact(b1, b2);
177-
c.cn = b2.pos.subtract(b1.pos);
178-
c.cn.y = 0; // just in case
179-
c.cn.divideLocal(dist);
180-
c.pen = dist - b1.radius - b2.radius;
181-
return c;
182-
}
183-
return null;
175+
if( dist >= b1.radius + b2.radius ) {
176+
return null;
177+
}
178+
log.info("contact:" + b1.bodyId + " and:" + b2.bodyId);
179+
Contact c = new Contact(b1, b2);
180+
c.cn = b2.pos.subtract(b1.pos);
181+
c.cn.y = 0; // just in case
182+
c.cn.divideLocal(dist);
183+
c.pen = dist - b1.radius - b2.radius;
184+
185+
return c;
184186
}
185187
}
186188

sigem/src/main/java/sigem/sim/Contact.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class Contact {
4949
public double pen;
5050
public Vec3d cp;
5151
public Vec3d cn;
52+
public double energy;
5253

5354
public Contact( Body b1, Body b2 ) {
5455
this.b1 = b1;

sigem/src/main/java/sigem/view/ModelViewState.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,24 @@ protected Spatial createModel( Entity entity ) {
318318
// Else figure out what type to create...
319319
ObjectType type = entity.get(ObjectType.class);
320320
String typeName = type.getTypeName(ed);
321-
if( typeName.equals("ship") ) {
322-
result = createShip(entity);
323-
} else if( typeName.equals("planet") ) {
324-
result = createPlanet(entity);
325-
} else if( typeName.equals("asteroid") ) {
326-
result = createAsteroid(entity);
327-
} else if( typeName.equals("thrust") ) {
328-
result = createThrust(entity);
329-
} else if( typeName.equals("missile") ) {
330-
result = createMissile(entity);
331-
} else {
332-
throw new RuntimeException("Unknown spatial type:" + typeName);
321+
switch( typeName ) {
322+
case ObjectType.TYPE_SHIP:
323+
result = createShip(entity);
324+
break;
325+
case ObjectType.TYPE_PLANET:
326+
result = createPlanet(entity);
327+
break;
328+
case ObjectType.TYPE_ASTEROID:
329+
result = createAsteroid(entity);
330+
break;
331+
case ObjectType.TYPE_THRUST:
332+
result = createThrust(entity);
333+
break;
334+
case ObjectType.TYPE_MISSILE:
335+
result = createMissile(entity);
336+
break;
337+
default:
338+
throw new RuntimeException("Unknown spatial type:" + typeName);
333339
}
334340

335341
// Add it to the index

0 commit comments

Comments
 (0)