• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


Commit MetaInfo

Revision022996474e3df0137b28f0cb4cb82bec022f1757 (tree)
Time2004-01-05 10:44:31
Authormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

initial curve classes.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@200 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

Change Summary

Incremental Difference

--- /dev/null
+++ b/src/com/jme/curve/Curve.java
@@ -0,0 +1,273 @@
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>Curve</code>
38+ * @author Mark Powell
39+ * @version $Id: Curve.java,v 1.1 2004-01-05 01:44:31 mojomonkey Exp $
40+ */
41+public abstract class Curve {
42+ protected static final float EPSILON = 0.0000001f;
43+ protected float minTime;
44+ protected float maxTime;
45+
46+ public Curve() {
47+ minTime = 0;
48+ maxTime = 0;
49+ }
50+
51+ public Curve(float minTime, float maxTime) {
52+ this.minTime = minTime;
53+ this.maxTime = maxTime;
54+ }
55+
56+ public void setMinTime(float minTime) {
57+ this.minTime = minTime;
58+ }
59+
60+ public float getMinTime() {
61+ return minTime;
62+ }
63+
64+ public void setMaxTime(float maxTime) {
65+ this.maxTime = maxTime;
66+ }
67+
68+ public float getMaxTime() {
69+ return maxTime;
70+ }
71+
72+ public void setTimeInterval(float minTime, float maxTime) {
73+ this.minTime = minTime;
74+ this.maxTime = maxTime;
75+ }
76+
77+ public abstract Vector3f getPosition(float time);
78+ public abstract Vector3f getFirstDerivative(float time);
79+ public abstract Vector3f getSecondDerivative(float time);
80+ public abstract Vector3f getThirdDerivative(float time);
81+
82+ public float getSpeed(float time) {
83+ Vector3f velocity = getFirstDerivative(time);
84+ return velocity.length();
85+ }
86+
87+ public abstract float getLength(float time0, float time1);
88+
89+ public float getTotalLength() {
90+ return getLength(minTime, maxTime);
91+ }
92+
93+ public Vector3f getTangent(float time) {
94+ Vector3f velocity = getFirstDerivative(time);
95+ return velocity.normalize();
96+ }
97+
98+ public void getFrame(
99+ float time,
100+ Vector3f position,
101+ Vector3f tangent,
102+ Vector3f normal,
103+ Vector3f binormal) {
104+
105+ position = getPosition(time);
106+ Vector3f kVelocity = getFirstDerivative(time);
107+ Vector3f kAcceleration = getSecondDerivative(time);
108+ float fVDotV = kVelocity.dot(kVelocity);
109+ float fVDotA = kVelocity.dot(kAcceleration);
110+ normal = kAcceleration.mult(fVDotV).subtract(kVelocity.mult(fVDotA));
111+ normal.normalize();
112+ tangent = kVelocity;
113+ tangent.normalize();
114+ binormal = tangent.cross(normal);
115+
116+ }
117+
118+ public float getCurvature(float time) {
119+ Vector3f kVelocity = getFirstDerivative(time);
120+ float fSpeedSqr = kVelocity.lengthSquared();
121+
122+ if (fSpeedSqr >= EPSILON) {
123+ Vector3f kAcceleration = getSecondDerivative(time);
124+ Vector3f kCross = kVelocity.cross(kAcceleration);
125+ float fNumer = kCross.length();
126+ float fDenom = (float) Math.pow(fSpeedSqr, 1.5f);
127+ return fNumer / fDenom;
128+ } else {
129+ // curvature is indeterminate, just return 0
130+ return 0;
131+ }
132+ }
133+
134+ public float getTorsion(float time) {
135+ Vector3f kVelocity = getFirstDerivative(time);
136+ Vector3f kAcceleration = getSecondDerivative(time);
137+ Vector3f kCross = kVelocity.cross(kAcceleration);
138+ float fDenom = kCross.lengthSquared();
139+
140+ if (fDenom >= EPSILON) {
141+ Vector3f kJerk = getThirdDerivative(time);
142+ float fNumer = kCross.dot(kJerk);
143+ return fNumer / fDenom;
144+ } else {
145+ // torsion is indeterminate, just return 0
146+ return 0;
147+ }
148+ }
149+
150+ public abstract float getTime(
151+ float length,
152+ int iterations,
153+ float tolerance);
154+
155+ public void subdivideByTime(int numPoints, Vector3f[] point) {
156+ point = new Vector3f[numPoints];
157+
158+ float delta = (maxTime - minTime) / (numPoints - 1);
159+
160+ for (int i = 0; i < numPoints; i++) {
161+ float time = minTime + delta * i;
162+ point[i] = getPosition(time);
163+ }
164+ }
165+
166+ public void subdivideByLength(int numPoints, Vector3f[] point) {
167+
168+ point = new Vector3f[numPoints];
169+
170+ float delta = getTotalLength() / (numPoints - 1);
171+
172+ for (int i = 0; i < numPoints; i++) {
173+ float length = delta * i;
174+ float time = getTime(length, 32, 0.0000001f);
175+ point[i] = getPosition(time);
176+ }
177+ }
178+
179+ public abstract float getVariation(
180+ float time0,
181+ float time1,
182+ Vector3f point0,
183+ Vector3f point1);
184+
185+ protected int subdivideByVariation(
186+ float fT0,
187+ Vector3f rkP0,
188+ float fT1,
189+ Vector3f rkP1,
190+ float fMinVariation,
191+ int uiLevel,
192+ int iNumPoints,
193+ PointList rpkList) {
194+ if (uiLevel > 0
195+ && getVariation(fT0, fT1, rkP0, rkP1) > fMinVariation) {
196+ // too much variation, subdivide interval
197+ uiLevel--;
198+ float fTMid = 0.5f * (fT0 + fT1);
199+ Vector3f kPMid = getPosition(fTMid);
200+
201+ iNumPoints =
202+ subdivideByVariation(
203+ fT0,
204+ rkP0,
205+ fTMid,
206+ kPMid,
207+ fMinVariation,
208+ uiLevel,
209+ iNumPoints,
210+ rpkList);
211+
212+ iNumPoints =
213+ subdivideByVariation(
214+ fTMid,
215+ kPMid,
216+ fT1,
217+ rkP1,
218+ fMinVariation,
219+ uiLevel,
220+ iNumPoints,
221+ rpkList);
222+ } else {
223+ // add right end point, left end point was added by neighbor
224+ rpkList = new PointList(rkP1);
225+ iNumPoints++;
226+ }
227+
228+ return iNumPoints;
229+ }
230+
231+ public void subdivideByVariation(
232+ float fMinVariation,
233+ int uiMaxLevel,
234+ Vector3f[] rakPoint) {
235+
236+ // compute end points of curve
237+ Vector3f kPMin = getPosition(minTime);
238+ Vector3f kPMax = getPosition(maxTime);
239+
240+ // add left end point to list
241+ PointList pkList = new PointList(kPMin);
242+ int iNumPoints = 1;
243+ // binary subdivision, leaf nodes add right end point of subinterval
244+ iNumPoints =
245+ subdivideByVariation(
246+ minTime,
247+ kPMin,
248+ maxTime,
249+ kPMax,
250+ fMinVariation,
251+ uiMaxLevel,
252+ iNumPoints,
253+ pkList.m_kNext);
254+
255+ // repackage points in an array
256+ rakPoint = new Vector3f[iNumPoints];
257+ for (int i = 0; i < rakPoint.length; i++) {
258+ rakPoint[i] = pkList.m_kPoint;
259+ pkList = pkList.m_kNext;
260+ }
261+ }
262+
263+ class PointList {
264+ Vector3f m_kPoint;
265+ PointList m_kNext;
266+ public PointList(Vector3f rkPoint) {
267+ m_kPoint = rkPoint;
268+ m_kNext = null;
269+ }
270+
271+ }
272+
273+}
--- /dev/null
+++ b/src/com/jme/curve/SingleCurve.java
@@ -0,0 +1,56 @@
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+/**
35+ * <code>SingleCurve</code>
36+ * @author Mark Powell
37+ * @version $Id: SingleCurve.java,v 1.1 2004-01-05 01:44:31 mojomonkey Exp $
38+ */
39+public abstract class SingleCurve extends Curve {
40+
41+ /* (non-Javadoc)
42+ * @see com.jme.curve.Curve#getLength(float, float)
43+ */
44+ public float getLength(float time0, float time1) {
45+ // TODO Auto-generated method stub
46+ return 0;
47+ }
48+
49+ /* (non-Javadoc)
50+ * @see com.jme.curve.Curve#getTime(float, int, float)
51+ */
52+ public float getTime(float length, int iterations, float tolerance) {
53+ // TODO Auto-generated method stub
54+ return 0;
55+ }
56+}