Behaviour change: ship clipping distance now takes flasher radius into account.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2473 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2009-09-11 15:06:00 +00:00
parent 3b1f0e97df
commit d2d7bf66bc
7 changed files with 66 additions and 15 deletions

View File

@ -24,7 +24,7 @@ MA 02110-1301, USA.
*/
#import "OOSelfDrawingEntity.h"
#import "Entity.h"
#define DUST_SCALE 2000
#define DUST_N_PARTICLES 600

View File

@ -78,6 +78,12 @@ MA 02110-1301, USA.
}
- (double)findCollisionRadius
{
return 0; // FIXME: something sensible. Where does plume length come from anyway?
}
- (void) update:(OOTimeDelta) delta_t
{
OOTimeAbsolute now = [UNIVERSE getTime];
@ -108,7 +114,7 @@ MA 02110-1301, USA.
GLfloat flare_factor = flare_length * ex_emissive[3] * hyper_fade;
GLfloat red_factor = flare_length * ex_emissive[0] * (ranrot_rand() % 11) * 0.1; // random fluctuations
GLfloat green_factor = flare_length * ex_emissive[1] * hyper_fade;
if (flare_length > 1.0) // afterburner!
{
red_factor = 1.5;
@ -121,7 +127,7 @@ MA 02110-1301, USA.
green_factor = 0.0;
if ((int)(ranrot_rand() % 25) < dam - 75)
flare_factor = 0.0;
if (flare_length < 0.1) { flare_length = 0.1;}
Vector currentPos = ship->position;
Vector vfwd = vector_forward_from_quaternion(shipQrotation);

View File

@ -140,6 +140,13 @@ MA 02110-1301, USA.
return YES;
}
- (double)findCollisionRadius
{
NSSize size = [self size];
return fmax(size.width, size.height);
}
@end

View File

@ -40,6 +40,8 @@ MA 02110-1301, USA.
- (id) initWithSize:(NSSize)size;
- (NSSize) size;
/* For subclasses that don't want the default blur texture.
NOTE: such subclasses must deal with the OOGraphicsResetManager.
*/

View File

@ -62,6 +62,12 @@ static OOTexture *sBlobTexture = nil;
}
- (NSSize) size
{
return _size;
}
- (void) drawSubEntity:(BOOL)immediate :(BOOL)translucent
{
if (!translucent) return;

View File

@ -305,6 +305,8 @@ MA 02110-1301, USA.
OOShipGroup *_escortGroup;
uint8_t _maxEscortCount;
uint8_t _pendingEscortCount;
GLfloat _profileRadius;
}
// ship brains
@ -344,6 +346,9 @@ MA 02110-1301, USA.
- (void) clearSubEntities; // Releases and clears subentity array, after making sure subentities don't think ship is owner.
- (Octree *) octree;
- (float) volume;
// octree collision hunting
- (GLfloat)doesHitLine:(Vector) v0: (Vector) v1;
- (GLfloat)doesHitLine:(Vector) v0: (Vector) v1 :(ShipEntity**) hitEntity;
@ -615,8 +620,6 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q
- (Triangle) absoluteIJKForSubentity;
- (void) addSolidSubentityToCollisionRadius:(ShipEntity *)subent;
ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
- (NSComparisonResult) compareBeaconCodeWith:(ShipEntity *)other;

View File

@ -102,6 +102,8 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
- (void) addSubEntity:(Entity *) subent;
- (void) addSubentityToCollisionRadius:(Entity*) subent;
@end
@ -433,6 +435,8 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
unsigned int i;
NSArray *plumes = [shipDict oo_arrayForKey:@"exhaust"];
_profileRadius = collision_radius;
for (i = 0; i < [plumes count]; i++)
{
NSArray *definition = ScanTokensFromString([plumes oo_stringAtIndex:i]);
@ -446,6 +450,9 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
{
[self setUpOneSubentity:[subs oo_dictionaryAtIndex:i]];
}
no_draw_distance = _profileRadius * _profileRadius * NO_DRAW_DISTANCE_FACTOR * NO_DRAW_DISTANCE_FACTOR * 2.0;
return YES;
}
@ -530,8 +537,6 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
[subentity setStatus:STATUS_INACTIVE];
}
[self addSolidSubentityToCollisionRadius:subentity];
[self addSubEntity:subentity];
[subentity release];
@ -757,6 +762,18 @@ static NSString * const kOOLogEntityBehaviourChanged = @"entity.behaviour.change
#endif
- (Octree *) octree
{
return octree;
}
- (float) volume
{
return [octree volume];
}
- (GLfloat)doesHitLine:(Vector)v0: (Vector)v1;
{
Vector u0 = vector_between(position, v0); // relative to origin of model / octree
@ -1263,16 +1280,24 @@ ShipEntity* doOctreesCollide(ShipEntity* prime, ShipEntity* other)
}
- (void) addSolidSubentityToCollisionRadius:(ShipEntity*) subent
- (void) addSubentityToCollisionRadius:(Entity*)subent
{
if (!subent)
return;
double distance = sqrt(magnitude2(subent->position)) + [subent findCollisionRadius];
if (distance > collision_radius)
collision_radius = distance;
if (!subent) return;
mass += 20.0 * [subent->octree volume];
double distance = magnitude([subent position]) + [subent findCollisionRadius];
if ([subent isKindOfClass:[ShipEntity class]]) // Solid subentity
{
if (distance > collision_radius)
{
collision_radius = distance;
}
mass += 20.0 * [(ShipEntity *)subent volume];
}
if (distance > _profileRadius)
{
_profileRadius = distance;
}
}
@ -3323,6 +3348,8 @@ static GLfloat mascem_color2[4] = { 0.4, 0.1, 0.4, 1.0}; // purple
// Order matters - need consistent state in setOwner:. -- Ahruman 2008-04-20
[subEntities addObject:sub];
[sub setOwner:self];
[self addSubentityToCollisionRadius:sub];
}