Added getDeltaPositionFromRotation; Bolt not rendering yet. Continue tonight.

This commit is contained in:
Calclavia 2013-08-02 09:30:59 -04:00
parent 3bebb340c2
commit 58831fff7c
2 changed files with 33 additions and 22 deletions

View file

@ -189,9 +189,22 @@ public class Vector3
return axis.getRotationMatrix(angle); return axis.getRotationMatrix(angle);
} }
public static Vector3 getDeltaPositionFromRotation(float rotationYaw, float rotationPitch)
{
rotationYaw = rotationYaw + 90;
rotationPitch = -rotationPitch;
return new Vector3(Math.cos(Math.toRadians(rotationYaw)), Math.sin(Math.toRadians(rotationPitch)), Math.sin(Math.toRadians(rotationYaw)));
}
@Override @Override
public Vector3 clone() public Vector3 clone()
{ {
return new Vector3(this.x, this.y, this.z); return new Vector3(this.x, this.y, this.z);
} }
@Override
public String toString()
{
return "Vector3 [" + this.x + "," + this.y + "," + this.z + "]";
}
} }

View file

@ -89,9 +89,9 @@ public class FXElectricBolt extends EntityFX
this.recalculate(); this.recalculate();
Collections.sort(this.segments, new Comparator() Collections.sort(this.segments, new Comparator()
{ {
public int compare(BoltSegment o1, BoltSegment o2) public int compare(BoltSegment bolt1, BoltSegment bolt2)
{ {
return Float.compare(o2.weight, o1.weight); return Float.compare(bolt2.alpha, bolt1.alpha);
} }
@Override @Override
@ -127,7 +127,7 @@ public class FXElectricBolt extends EntityFX
for (int i = 1; i < splitAmount; i++) for (int i = 1; i < splitAmount; i++)
{ {
BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.weight, segment.id * splitAmount + i, segment.splitID); BoltSegment next = new BoltSegment(newPoints[i], newPoints[(i + 1)], segment.alpha, segment.id * splitAmount + i, segment.splitID);
next.prev = prev; next.prev = prev;
if (prev != null) if (prev != null)
@ -135,16 +135,14 @@ public class FXElectricBolt extends EntityFX
prev.next = next; prev.next = next;
} }
if (i != 0) Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 360.0F, next.difference);
{ Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * angle, splitrot).scale(length);
Vector3 splitrot = next.difference.xCrossProduct().rotate(this.rand.nextFloat() * 360.0F, next.difference); this.parentIDMap.put(this.maxSplitID, next.splitID);
Vector3 diff = next.difference.clone().rotate((this.rand.nextFloat() * 0.66F + 0.33F) * angle, splitrot).scale(length); // Loose transparency per split.
this.parentIDMap.put(this.maxSplitID, next.splitID); BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().translate(diff)), segment.alpha / 2f, next.id, this.maxSplitID);
BoltSegment split = new BoltSegment(newPoints[i], new BoltPoint(newPoints[(i + 1)].base, newPoints[(i + 1)].offset.clone().translate(diff)), segment.weight / 2.0F, next.id, this.maxSplitID); split.prev = prev;
split.prev = prev; this.maxSplitID++;
this.maxSplitID++; this.segments.add(split);
this.segments.add(split);
}
prev = next; prev = next;
this.segments.add(next); this.segments.add(next);
@ -252,13 +250,13 @@ public class FXElectricBolt extends EntityFX
for (BoltSegment segment : this.segments) for (BoltSegment segment : this.segments)
{ {
double width = this.width * ((new Vector3(player).distance(segment.start) / 5 + 1) * (1.0F + segment.weight) * 0.5f); double width = this.width * ((new Vector3(player).distance(segment.start) / 5 + 1) * (1.0F + segment.alpha) * 0.5f);
Vector3 prevDiff = playerVector.crossProduct(segment.prevDiff).scale(this.width); Vector3 prevDiff = playerVector.crossProduct(segment.prevDiff).scale(this.width);
Vector3 nextDiff = playerVector.crossProduct(segment.nextDiff).scale(this.width); Vector3 nextDiff = playerVector.crossProduct(segment.nextDiff).scale(this.width);
Vector3 renderStart = segment.start; Vector3 renderStart = segment.start;
Vector3 renderEnd = segment.end; Vector3 renderEnd = segment.end;
tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha); tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, segment.alpha);
float rx1 = (float) (renderStart.x - interpPosX); float rx1 = (float) (renderStart.x - interpPosX);
float ry1 = (float) (renderStart.y - interpPosY); float ry1 = (float) (renderStart.y - interpPosY);
@ -336,7 +334,7 @@ public class FXElectricBolt extends EntityFX
public BoltPoint end; public BoltPoint end;
public BoltSegment prev; public BoltSegment prev;
public BoltSegment next; public BoltSegment next;
public float weight; public float alpha;
public int id; public int id;
public int splitID; public int splitID;
@ -349,17 +347,17 @@ public class FXElectricBolt extends EntityFX
public BoltSegment(BoltPoint start, BoltPoint end) public BoltSegment(BoltPoint start, BoltPoint end)
{ {
this.start = start; this(start, end, 1, 0, 0);
this.end = end;
this.recalculate();
} }
public BoltSegment(BoltPoint start, BoltPoint end, float weight, int id, int splitID) public BoltSegment(BoltPoint start, BoltPoint end, float alpha, int id, int splitID)
{ {
this(start, end); this.start = start;
this.weight = weight; this.end = end;
this.alpha = alpha;
this.id = id; this.id = id;
this.splitID = splitID; this.splitID = splitID;
this.recalculate();
} }
public void recalculate() public void recalculate()