-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
Ports from 1.7.10 FM+
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.flansmod.client.model; | ||
|
||
import java.util.ArrayList; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
import com.flansmod.common.vector.Vector3f; | ||
|
||
|
||
public class AnimTankTrack { | ||
|
||
public ArrayList<Vector3f> points = new ArrayList<Vector3f>(); | ||
public float trackLinkLength = 0; | ||
|
||
public AnimTankTrack (ArrayList<Vector3f> trackPoints, float linkLength) | ||
{ | ||
points = trackPoints; | ||
trackLinkLength = linkLength; | ||
} | ||
|
||
public void setLinkLength(float length) | ||
{ | ||
trackLinkLength = length; | ||
} | ||
|
||
public float distBetweenPoints(Vector3f p1, Vector3f p2) | ||
{ | ||
float distance; | ||
|
||
float x = p1.x - p2.x; | ||
float y = p1.y - p2.y; | ||
distance = (float)Math.sqrt((x*x) + (y*y)); | ||
|
||
return distance; | ||
} | ||
|
||
public float getTrackLength() | ||
{ | ||
float length = 0; | ||
for(int i = 0; i < points.size(); i++) | ||
{ | ||
length += distBetweenPoints(points.get(i), points.get((i == 0)? points.size()-1:i-1)); | ||
} | ||
return length; | ||
} | ||
|
||
public int getTrackPart(float distance) | ||
{ | ||
float length = 0; | ||
for(int i = 0; i < points.size(); i++) | ||
{ | ||
if(length >= distance) | ||
{ | ||
return i; | ||
} else { | ||
length += distBetweenPoints(points.get(i), points.get((i == (points.size()-1))? 0:i+1)); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
public float getProgressAlongTrackPart(float distance, int trackPart) | ||
{ | ||
float length = 0; | ||
float lastLength = 0; | ||
for(int i = 0; i < trackPart + 1; i++) | ||
{ | ||
if(i != 0) | ||
{ | ||
length += distBetweenPoints(points.get(i-1), points.get(i)); | ||
} | ||
} | ||
return length; | ||
} | ||
|
||
public Vector3f getPositionOnTrack(float distance) | ||
{ | ||
|
||
int trackPart = getTrackPart(distance); | ||
Vector3f p2 = points.get((trackPart == 0)? points.size()-1:trackPart-1); | ||
Vector3f p1 = points.get(trackPart); | ||
|
||
float partLength = distBetweenPoints(p2, p1); | ||
float prog = distance - (getProgressAlongTrackPart(distance,(trackPart == 0)? points.size()-1:trackPart-1)); | ||
float progress = prog/partLength; | ||
Vector3f finalPos = new Vector3f(lerp(p2.x, p1.x, progress),lerp(p2.y, p1.y, progress), lerp(p2.z, p1.z, progress)); | ||
|
||
return finalPos; | ||
} | ||
|
||
public float lerp(float a, float b, float f) | ||
{ | ||
float result = (a+ f*(b - a)); | ||
|
||
return result; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.flansmod.client.model; | ||
|
||
import com.flansmod.common.RotatedAxes; | ||
import com.flansmod.common.vector.Vector3f; | ||
|
||
public class AnimTrackLink { | ||
|
||
public Vector3f position; | ||
public Vector3f prevPosition; | ||
public float zRot = 0; | ||
public float prevZRot; | ||
public float progress = 0; | ||
public RotatedAxes rot; | ||
|
||
public AnimTrackLink(float prog) | ||
{ | ||
progress = prog; | ||
} | ||
} |
3 comments
on commit 254fa35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format source to use tab indents. There's a lot of inconsistency in this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, "Semi Functional Barrels"? Semi-functional in what way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, "Semi Functional Barrels"? Semi-functional in what way?
Well, currently the barrels don't 'recoil back' but the positioning for them is in place. Keep in mind I wasn't the one who ported this code. It was from my friend.
There shouldn't be an empty space behind the curly bracket