Skip to content

Commit

Permalink
Merge branch 'issue_150'
Browse files Browse the repository at this point in the history
  • Loading branch information
kanthoney committed May 24, 2015
2 parents 81cd600 + 1bfc0ba commit a3b98dd
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Core/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ enum OOScanClass

- (BOOL) canCollide;
- (GLfloat) collisionRadius;
- (GLfloat) frustumRadius;
- (void) setCollisionRadius:(GLfloat)amount;
- (NSMutableArray *)collisionArray;

Expand Down
10 changes: 8 additions & 2 deletions src/Core/Entities/Entity.m
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,12 @@ - (Vector) cameraRelativePosition

- (GLfloat) cameraRangeFront
{
return magnitude(cameraRelativePosition) - [self collisionRadius];
return magnitude(cameraRelativePosition) - [self frustumRadius];
}

- (GLfloat) cameraRangeBack
{
return magnitude(cameraRelativePosition) + [self collisionRadius];
return magnitude(cameraRelativePosition) + [self frustumRadius];
}


Expand Down Expand Up @@ -899,6 +899,12 @@ - (GLfloat) collisionRadius
}


- (GLfloat) frustumRadius
{
return collision_radius;
}


- (void) setCollisionRadius:(GLfloat) amount
{
collision_radius = amount;
Expand Down
81 changes: 65 additions & 16 deletions src/Core/Entities/OOExhaustPlumeEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (BOOL)isExhaust

- (double)findCollisionRadius
{
return 0; // FIXME: something sensible. Where does plume length come from anyway?
return collision_radius;
}


Expand All @@ -131,6 +131,9 @@ - (void) update:(OOTimeDelta) delta_t
}

//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];
[[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};
Expand Down Expand Up @@ -218,9 +221,11 @@ - (void) update:(OOTimeDelta) delta_t
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[0] = red_factor; // diminish red part towards rear of exhaust
_vertices[iv++] = f01.position.x + b01.x;// + zero.k.x * flare_factor * 4.0;
_vertices[iv++] = f01.position.y + b01.y;// + zero.k.y * flare_factor * 4.0;
_vertices[iv++] = f01.position.z + b01.z;// + zero.k.z * flare_factor * 4.0;
vertex = vector_add(HPVectorToVector(f01.position), b01);
collision_radius = magnitude(vector_subtract(vertex, HPVectorToVector(currentPos)));
_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[1];
_exhaustBaseColors[ci++] = ex_emissive[2];
Expand All @@ -234,9 +239,18 @@ - (void) update:(OOTimeDelta) delta_t

for (i = 0; i < 8; i++)
{
_vertices[iv++] = f01.position.x + b01.x + s1[i] * i1.x + c1[i] * j1.x;
_vertices[iv++] = f01.position.y + b01.y + s1[i] * i1.y + c1[i] * j1.y;
_vertices[iv++] = f01.position.z + b01.z + s1[i] * i1.z + c1[i] * j1.z;
vertex = vector_add(HPVectorToVector(f01.position),
vector_add(b01,
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[1];
_exhaustBaseColors[ci++] = ex_emissive[2];
Expand All @@ -253,9 +267,19 @@ - (void) update:(OOTimeDelta) delta_t
for (i = 0; i < 8; i++)
{
r1 = randf();
_vertices[iv++] = f03.position.x + b03.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
_vertices[iv++] = f03.position.y + b03.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
_vertices[iv++] = f03.position.z + b03.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
vertex = vector_add(HPVectorToVector(f03.position),
vector_add(b03,
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[1];
_exhaustBaseColors[ci++] = ex_emissive[2];
Expand All @@ -272,9 +296,19 @@ - (void) update:(OOTimeDelta) delta_t
for (i = 0; i < 8; i++)
{
r1 = randf();
_vertices[iv++] = f06.position.x + b06.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
_vertices[iv++] = f06.position.y + b06.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
_vertices[iv++] = f06.position.z + b06.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
vertex = vector_add(HPVectorToVector(f06.position),
vector_add(b06,
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[1];
_exhaustBaseColors[ci++] = ex_emissive[2];
Expand All @@ -290,9 +324,19 @@ - (void) update:(OOTimeDelta) delta_t
for (i = 0; i < 8; i++)
{
r1 = randf();
_vertices[iv++] = f08.position.x + b08.x + s1[i] * i1.x + c1[i] * j1.x + r1 * k1.x;
_vertices[iv++] = f08.position.y + b08.y + s1[i] * i1.y + c1[i] * j1.y + r1 * k1.y;
_vertices[iv++] = f08.position.z + b08.z + s1[i] * i1.z + c1[i] * j1.z + r1 * k1.z;
vertex = vector_add(HPVectorToVector(f08.position),
vector_add(b08,
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[1];
_exhaustBaseColors[ci++] = ex_emissive[2];
Expand All @@ -302,6 +346,11 @@ - (void) update:(OOTimeDelta) delta_t
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[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.y;
_vertices[iv++] = f10.position.z;
Expand Down
12 changes: 11 additions & 1 deletion src/Core/Entities/ShipEntity.m
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,17 @@ - (BOOL) setUpSubEntities

- (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;
}


Expand Down

0 comments on commit a3b98dd

Please sign in to comment.