Main repository of MikuMikuStudio
Revision | 9a2dcc7050969c1b4902c11c0e632519fd4d86f0 (tree) |
---|---|
Time | 2004-01-07 00:19:39 |
Author | mojomonkey <mojomonkey@75d0...> |
Commiter | mojomonkey |
complete bezier curve system
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@204 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -0,0 +1,88 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or without | |
6 | + * modification, are permitted provided that the following conditions are met: | |
7 | + * | |
8 | + * Redistributions of source code must retain the above copyright notice, this | |
9 | + * list of conditions and the following disclaimer. | |
10 | + * | |
11 | + * Redistributions in binary form must reproduce the above copyright notice, | |
12 | + * this list of conditions and the following disclaimer in the documentation | |
13 | + * and/or other materials provided with the distribution. | |
14 | + * | |
15 | + * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the | |
16 | + * names of its contributors may be used to endorse or promote products derived | |
17 | + * from this software without specific prior written permission. | |
18 | + * | |
19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
23 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | + * POSSIBILITY OF SUCH DAMAGE. | |
30 | + * | |
31 | + */ | |
32 | +package com.jme.curve; | |
33 | + | |
34 | +import com.jme.math.Vector3f; | |
35 | + | |
36 | +/** | |
37 | + * <code>BezierCurve</code> | |
38 | + * @author Mark Powell | |
39 | + * @version | |
40 | + */ | |
41 | +public class BezierCurve extends Curve { | |
42 | + | |
43 | + public BezierCurve() { | |
44 | + super(); | |
45 | + } | |
46 | + | |
47 | + public BezierCurve(Vector3f[] controlPoints) { | |
48 | + super(controlPoints); | |
49 | + } | |
50 | + | |
51 | + /* (non-Javadoc) | |
52 | + * @see com.jme.curve.Curve#getPoint(float) | |
53 | + */ | |
54 | + public Vector3f getPoint(float time) { | |
55 | + Vector3f point = new Vector3f(); | |
56 | + | |
57 | + float muk = 1; | |
58 | + float munk = (float)Math.pow(1-time, controlPoints.length-1); | |
59 | + | |
60 | + for(int i = 0; i < controlPoints.length; i++) { | |
61 | + int count = controlPoints.length-1; | |
62 | + int iCount = i; | |
63 | + int diff = count - iCount; | |
64 | + float blend = muk * munk; | |
65 | + muk *= time; | |
66 | + munk /= (1 - time); | |
67 | + while(count >= 1) { | |
68 | + blend *= count; | |
69 | + count--; | |
70 | + if(iCount > 1) { | |
71 | + blend /= iCount; | |
72 | + iCount--; | |
73 | + } | |
74 | + | |
75 | + if(diff > 1) { | |
76 | + blend /= diff; | |
77 | + diff--; | |
78 | + } | |
79 | + } | |
80 | + point.x += controlPoints[i].x * blend; | |
81 | + point.y += controlPoints[i].y * blend; | |
82 | + point.z += controlPoints[i].z * blend; | |
83 | + } | |
84 | + | |
85 | + return point; | |
86 | + } | |
87 | + | |
88 | +} |
@@ -0,0 +1,79 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2003, jMonkeyEngine - Mojo Monkey Coding | |
3 | + * All rights reserved. | |
4 | + * | |
5 | + * Redistribution and use in source and binary forms, with or without | |
6 | + * modification, are permitted provided that the following conditions are met: | |
7 | + * | |
8 | + * Redistributions of source code must retain the above copyright notice, this | |
9 | + * list of conditions and the following disclaimer. | |
10 | + * | |
11 | + * Redistributions in binary form must reproduce the above copyright notice, | |
12 | + * this list of conditions and the following disclaimer in the documentation | |
13 | + * and/or other materials provided with the distribution. | |
14 | + * | |
15 | + * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the | |
16 | + * names of its contributors may be used to endorse or promote products derived | |
17 | + * from this software without specific prior written permission. | |
18 | + * | |
19 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
23 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | + * POSSIBILITY OF SUCH DAMAGE. | |
30 | + * | |
31 | + */ | |
32 | +package com.jme.curve; | |
33 | + | |
34 | +import com.jme.math.Vector3f; | |
35 | +import com.jme.system.JmeException; | |
36 | + | |
37 | +/** | |
38 | + * <code>Curve</code> | |
39 | + * @author Mark Powell | |
40 | + * @version $Id: Curve.java,v 1.3 2004-01-06 15:19:39 mojomonkey Exp $ | |
41 | + */ | |
42 | +public abstract class Curve { | |
43 | + | |
44 | + protected Vector3f[] controlPoints; | |
45 | + | |
46 | + public Curve() { | |
47 | + controlPoints = new Vector3f[0]; | |
48 | + } | |
49 | + | |
50 | + public Curve(Vector3f[] controlPoints) { | |
51 | + if (null == controlPoints) { | |
52 | + throw new JmeException("Control Points may not be null."); | |
53 | + } | |
54 | + | |
55 | + if (controlPoints.length < 2) { | |
56 | + throw new JmeException("There must be at least two control points."); | |
57 | + } | |
58 | + | |
59 | + this.controlPoints = controlPoints; | |
60 | + } | |
61 | + | |
62 | + public void setControlPoints(Vector3f[] controlPoints) { | |
63 | + if (null == controlPoints) { | |
64 | + throw new JmeException("Control Points may not be null."); | |
65 | + } | |
66 | + | |
67 | + if (controlPoints.length < 2) { | |
68 | + throw new JmeException("There must be at least two control points."); | |
69 | + } | |
70 | + | |
71 | + this.controlPoints = controlPoints; | |
72 | + } | |
73 | + | |
74 | + public Vector3f[] getControlPoints() { | |
75 | + return controlPoints; | |
76 | + } | |
77 | + | |
78 | + public abstract Vector3f getPoint(float time); | |
79 | +} |