forked from Jeddic/particlemonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jeddic#6 Add a builder for the curve class that allows it to be speci…
…fied as a series of anchor and control points
- Loading branch information
1 parent
3633263
commit 3287009
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/epaga/particles/valuetypes/curvebuilder/CurveBuilderAtAnchor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.epaga.particles.valuetypes.curvebuilder; | ||
|
||
import com.epaga.particles.valuetypes.Curve; | ||
import com.jme3.math.Vector2f; | ||
|
||
public class CurveBuilderAtAnchor{ | ||
|
||
Curve curveBeingBuilt; | ||
Vector2f controlPointIn; | ||
Vector2f currentAnchor; | ||
|
||
public CurveBuilderAtAnchor(Curve curveBeingBuilt, Vector2f controlPointIn, Vector2f currentAnchor){ | ||
this.curveBeingBuilt = curveBeingBuilt; | ||
this.controlPointIn = controlPointIn; | ||
this.currentAnchor = currentAnchor; | ||
} | ||
|
||
/** | ||
* Adds a point that the curve will attempt to move towards but may not actually touch. | ||
* | ||
* The 2 control points are used to define a cubic Bézier curve between 2 anchors | ||
* @param nextControlPoint the control point | ||
* @return a CurveBuilderAtControlPoint1 a part of the curve builder system | ||
*/ | ||
public CurveBuilderAtControlPoint1 controlPoint1( Vector2f nextControlPoint ){ | ||
return new CurveBuilderAtControlPoint1(curveBeingBuilt, controlPointIn, currentAnchor, nextControlPoint); | ||
} | ||
|
||
/** | ||
* Produces a straight line between 2 anchor points | ||
* @param nextAnchor the next anchor point | ||
* @return a CurveBuilderAtAnchor a part of the curve builder system | ||
*/ | ||
public CurveBuilderAtAnchor anchorPoint(Vector2f nextAnchor ){ | ||
//simulate a straight line using a Bézier curve | ||
Vector2f midOne = currentAnchor.mult(2f/3).add(nextAnchor.mult(1f/3)); | ||
Vector2f midTwo = currentAnchor.mult(1f/3).add(nextAnchor.mult(2f/3)); | ||
return controlPoint1(midOne).controlPoint2(midTwo).nextAnchor(nextAnchor); | ||
} | ||
|
||
public Curve end(){ | ||
curveBeingBuilt.addControlPoint(controlPointIn, currentAnchor, null); | ||
return curveBeingBuilt; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/epaga/particles/valuetypes/curvebuilder/CurveBuilderAtControlPoint1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.epaga.particles.valuetypes.curvebuilder; | ||
|
||
import com.epaga.particles.valuetypes.Curve; | ||
import com.jme3.math.Vector2f; | ||
|
||
public class CurveBuilderAtControlPoint1{ | ||
|
||
Curve curveBeingBuilt; | ||
|
||
public CurveBuilderAtControlPoint1(Curve curveBeingBuilt, Vector2f controlPointIn, Vector2f currentAnchor, Vector2f controlPointOut){ | ||
this.curveBeingBuilt = curveBeingBuilt; | ||
this.curveBeingBuilt.addControlPoint(controlPointIn, currentAnchor, controlPointOut); | ||
} | ||
|
||
/** | ||
* Adds a point that the curve will attempt to move towards but may not actually touch. | ||
* | ||
* The 2 control points are used to define a cubic Bézier curve between 2 anchors | ||
* @param nextControlPoint the control point | ||
* @return a CurveBuilderAtControlPoint1 a part of the curve builder system | ||
*/ | ||
public CurveBuilderAtControlPoint2 controlPoint2( Vector2f nextControlPoint ){ | ||
return new CurveBuilderAtControlPoint2(curveBeingBuilt, nextControlPoint); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/epaga/particles/valuetypes/curvebuilder/CurveBuilderAtControlPoint2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.epaga.particles.valuetypes.curvebuilder; | ||
|
||
import com.epaga.particles.valuetypes.Curve; | ||
import com.jme3.math.Vector2f; | ||
|
||
public class CurveBuilderAtControlPoint2{ | ||
|
||
Curve curveBeingBuilt; | ||
Vector2f inControlPoint; | ||
|
||
public CurveBuilderAtControlPoint2(Curve curveBeingBuilt, Vector2f inControlPoint){ | ||
this.curveBeingBuilt = curveBeingBuilt; | ||
this.inControlPoint = inControlPoint; | ||
} | ||
|
||
/** | ||
* Adds a point that the curve go through. | ||
* | ||
* Anchors are the starts and ends of cubic Bézier curves | ||
* @param nextAnchor the anchor point | ||
* @return a CurveBuilderAtAnchor a part of the curve builder system | ||
*/ | ||
public CurveBuilderAtAnchor anchorPoint(Vector2f nextAnchor ){ | ||
return new CurveBuilderAtAnchor(curveBeingBuilt, inControlPoint, nextAnchor); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/epaga/particles/valuetypes/curvebuilder/CurveBuilderStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.epaga.particles.valuetypes.curvebuilder; | ||
|
||
import com.epaga.particles.valuetypes.Curve; | ||
import com.jme3.math.Vector2f; | ||
import com.jme3.math.Vector3f; | ||
|
||
public class CurveBuilderStart{ | ||
|
||
Curve curveBeingBuilt = new Curve(); | ||
|
||
/** | ||
* Adds the first anchor point, where the line will start | ||
* @return CurveBuilderAtAnchor a part of the curve builder system | ||
*/ | ||
public CurveBuilderAtAnchor anchorPoint(Vector2f start){ | ||
return new CurveBuilderAtAnchor(curveBeingBuilt, null, start); | ||
} | ||
|
||
} |