Merge branch 'issue_150'

This commit is contained in:
Kevin Anthoney 2015-05-24 13:54:45 +01:00
commit a3b98ddcfa
4 changed files with 85 additions and 19 deletions

View File

@ -258,6 +258,7 @@ enum OOScanClass
- (BOOL) canCollide; - (BOOL) canCollide;
- (GLfloat) collisionRadius; - (GLfloat) collisionRadius;
- (GLfloat) frustumRadius;
- (void) setCollisionRadius:(GLfloat)amount; - (void) setCollisionRadius:(GLfloat)amount;
- (NSMutableArray *)collisionArray; - (NSMutableArray *)collisionArray;

View File

@ -612,12 +612,12 @@ static NSString * const kOOLogEntityVerificationError = @"entity.linkedList.ver
- (GLfloat) cameraRangeFront - (GLfloat) cameraRangeFront
{ {
return magnitude(cameraRelativePosition) - [self collisionRadius]; return magnitude(cameraRelativePosition) - [self frustumRadius];
} }
- (GLfloat) cameraRangeBack - (GLfloat) cameraRangeBack
{ {
return magnitude(cameraRelativePosition) + [self collisionRadius]; return magnitude(cameraRelativePosition) + [self frustumRadius];
} }
@ -899,6 +899,12 @@ static NSString * const kOOLogEntityVerificationError = @"entity.linkedList.ver
} }
- (GLfloat) frustumRadius
{
return collision_radius;
}
- (void) setCollisionRadius:(GLfloat) amount - (void) setCollisionRadius:(GLfloat) amount
{ {
collision_radius = amount; collision_radius = amount;

View File

@ -110,7 +110,7 @@ static OOTexture *sPlumeTexture = nil;
- (double)findCollisionRadius - (double)findCollisionRadius
{ {
return 0; // FIXME: something sensible. Where does plume length come from anyway? return collision_radius;
} }
@ -131,6 +131,9 @@ static OOTexture *sPlumeTexture = nil;
} }
//GLfloat ex_emissive[4] = {0.7f, 0.9, 1.0f, 0.9f * kOverallAlpha}; // pale blue - old definition //GLfloat ex_emissive[4] = {0.7f, 0.9, 1.0f, 0.9f * kOverallAlpha}; // pale blue - old definition
collision_radius = 0;
GLfloat length;
Vector vertex;
GLfloat ex_emissive[4]; GLfloat ex_emissive[4];
[[ship exhaustEmissiveColor] getRed:&ex_emissive[0] green:&ex_emissive[1] blue:&ex_emissive[2] alpha:&ex_emissive[3]]; [[ship exhaustEmissiveColor] getRed:&ex_emissive[0] green:&ex_emissive[1] blue:&ex_emissive[2] alpha:&ex_emissive[3]];
const GLfloat s1[8] = { 0.0, M_SQRT1_2, 1.0, M_SQRT1_2, 0.0, -M_SQRT1_2, -1.0, -M_SQRT1_2}; const GLfloat s1[8] = { 0.0, M_SQRT1_2, 1.0, M_SQRT1_2, 0.0, -M_SQRT1_2, -1.0, -M_SQRT1_2};
@ -218,9 +221,11 @@ static OOTexture *sPlumeTexture = nil;
ex_emissive[3] = flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust ex_emissive[3] = flare_factor * kOverallAlpha; // fade alpha towards rear of exhaust
ex_emissive[1] = green_factor; // diminish green part towards rear of exhaust ex_emissive[1] = green_factor; // diminish green part towards rear of exhaust
ex_emissive[0] = red_factor; // diminish red part towards rear of exhaust ex_emissive[0] = red_factor; // diminish red part towards rear of exhaust
_vertices[iv++] = f01.position.x + b01.x;// + zero.k.x * flare_factor * 4.0; vertex = vector_add(HPVectorToVector(f01.position), b01);
_vertices[iv++] = f01.position.y + b01.y;// + zero.k.y * flare_factor * 4.0; collision_radius = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
_vertices[iv++] = f01.position.z + b01.z;// + zero.k.z * flare_factor * 4.0; _vertices[iv++] = vertex.x;// + zero.k.x * flare_factor * 4.0;
_vertices[iv++] = vertex.y;// + zero.k.y * flare_factor * 4.0;
_vertices[iv++] = vertex.z;// + zero.k.z * flare_factor * 4.0;
_exhaustBaseColors[ci++] = ex_emissive[0]; _exhaustBaseColors[ci++] = ex_emissive[0];
_exhaustBaseColors[ci++] = ex_emissive[1]; _exhaustBaseColors[ci++] = ex_emissive[1];
_exhaustBaseColors[ci++] = ex_emissive[2]; _exhaustBaseColors[ci++] = ex_emissive[2];
@ -234,9 +239,18 @@ static OOTexture *sPlumeTexture = nil;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
_vertices[iv++] = f01.position.x + b01.x + s1[i] * i1.x + c1[i] * j1.x; vertex = vector_add(HPVectorToVector(f01.position),
_vertices[iv++] = f01.position.y + b01.y + s1[i] * i1.y + c1[i] * j1.y; vector_add(b01,
_vertices[iv++] = f01.position.z + b01.z + s1[i] * i1.z + c1[i] * j1.z; vector_add(vector_multiply_scalar(i1,s1[i]),
vector_multiply_scalar(j1,c1[i]))));
length = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
if (length > collision_radius)
{
collision_radius = length;
}
_vertices[iv++] = vertex.x;
_vertices[iv++] = vertex.y;
_vertices[iv++] = vertex.z;
_exhaustBaseColors[ci++] = ex_emissive[0]; _exhaustBaseColors[ci++] = ex_emissive[0];
_exhaustBaseColors[ci++] = ex_emissive[1]; _exhaustBaseColors[ci++] = ex_emissive[1];
_exhaustBaseColors[ci++] = ex_emissive[2]; _exhaustBaseColors[ci++] = ex_emissive[2];
@ -253,9 +267,19 @@ static OOTexture *sPlumeTexture = nil;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
_vertices[iv++] = f03.position.x + b03.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; vertex = vector_add(HPVectorToVector(f03.position),
_vertices[iv++] = f03.position.y + b03.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; vector_add(b03,
_vertices[iv++] = f03.position.z + b03.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; vector_add(vector_multiply_scalar(i1,s1[i]),
vector_add(vector_multiply_scalar(j1,c1[i]),
vector_multiply_scalar(k1,r1)))));
length = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
if (length > collision_radius)
{
collision_radius = length;
}
_vertices[iv++] = vertex.x;
_vertices[iv++] = vertex.y;
_vertices[iv++] = vertex.z;
_exhaustBaseColors[ci++] = ex_emissive[0]; _exhaustBaseColors[ci++] = ex_emissive[0];
_exhaustBaseColors[ci++] = ex_emissive[1]; _exhaustBaseColors[ci++] = ex_emissive[1];
_exhaustBaseColors[ci++] = ex_emissive[2]; _exhaustBaseColors[ci++] = ex_emissive[2];
@ -272,9 +296,19 @@ static OOTexture *sPlumeTexture = nil;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
_vertices[iv++] = f06.position.x + b06.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; vertex = vector_add(HPVectorToVector(f06.position),
_vertices[iv++] = f06.position.y + b06.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; vector_add(b06,
_vertices[iv++] = f06.position.z + b06.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; vector_add(vector_multiply_scalar(i1,s1[i]),
vector_add(vector_multiply_scalar(j1,c1[i]),
vector_multiply_scalar(k1,r1)))));
length = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
if (length > collision_radius)
{
collision_radius = length;
}
_vertices[iv++] = vertex.x;
_vertices[iv++] = vertex.y;
_vertices[iv++] = vertex.z;
_exhaustBaseColors[ci++] = ex_emissive[0]; _exhaustBaseColors[ci++] = ex_emissive[0];
_exhaustBaseColors[ci++] = ex_emissive[1]; _exhaustBaseColors[ci++] = ex_emissive[1];
_exhaustBaseColors[ci++] = ex_emissive[2]; _exhaustBaseColors[ci++] = ex_emissive[2];
@ -290,9 +324,19 @@ static OOTexture *sPlumeTexture = nil;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
r1 = randf(); r1 = randf();
_vertices[iv++] = f08.position.x + b08.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x; vertex = vector_add(HPVectorToVector(f08.position),
_vertices[iv++] = f08.position.y + b08.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y; vector_add(b08,
_vertices[iv++] = f08.position.z + b08.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z; vector_add(vector_multiply_scalar(i1,s1[i]),
vector_add(vector_multiply_scalar(j1,c1[i]),
vector_multiply_scalar(k1,r1)))));
length = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
if (length > collision_radius)
{
collision_radius = length;
}
_vertices[iv++] = vertex.x;
_vertices[iv++] = vertex.y;
_vertices[iv++] = vertex.z;
_exhaustBaseColors[ci++] = ex_emissive[0]; _exhaustBaseColors[ci++] = ex_emissive[0];
_exhaustBaseColors[ci++] = ex_emissive[1]; _exhaustBaseColors[ci++] = ex_emissive[1];
_exhaustBaseColors[ci++] = ex_emissive[2]; _exhaustBaseColors[ci++] = ex_emissive[2];
@ -302,6 +346,11 @@ static OOTexture *sPlumeTexture = nil;
ex_emissive[3] = 0.0; // fade alpha towards rear of exhaust ex_emissive[3] = 0.0; // fade alpha towards rear of exhaust
ex_emissive[1] = 0.0; // diminish green part towards rear of exhaust ex_emissive[1] = 0.0; // diminish green part towards rear of exhaust
ex_emissive[0] = 0.0; // diminish red part towards rear of exhaust ex_emissive[0] = 0.0; // diminish red part towards rear of exhaust
length = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
if (length > collision_radius)
{
collision_radius = length;
}
_vertices[iv++] = f10.position.x; _vertices[iv++] = f10.position.x;
_vertices[iv++] = f10.position.y; _vertices[iv++] = f10.position.y;
_vertices[iv++] = f10.position.z; _vertices[iv++] = f10.position.z;

View File

@ -860,7 +860,17 @@ static ShipEntity *doOctreesCollide(ShipEntity *prime, ShipEntity *other);
- (GLfloat) frustumRadius - (GLfloat) frustumRadius
{ {
return _profileRadius; OOScalar exhaust_length = 0;
NSEnumerator *exEnum = nil;
OOExhaustPlumeEntity *exEnt = nil;
for (exEnum = [self exhaustEnumerator]; (exEnt = [exEnum nextObject]); )
{
if ([exEnt findCollisionRadius] > exhaust_length)
{
exhaust_length = [exEnt findCollisionRadius];
}
}
return _profileRadius + exhaust_length;
} }