• 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

Revisiona665c38af3c05dc02b7451662c6edf9094b447e4 (tree)
Time2004-01-08 08:00:47
Authormojomonkey <mojomonkey@75d0...>
Commitermojomonkey

Log Message

controller for curves.

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

Change Summary

Incremental Difference

--- /dev/null
+++ b/src/com/jme/curve/CurveController.java
@@ -0,0 +1,178 @@
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.scene.Controller;
36+import com.jme.scene.Spatial;
37+
38+/**
39+ * <code>CurveController</code> defines a controller that moves a supplied
40+ * <code>Spatial</code> object along a curve. Attributes of the curve are set
41+ * such as the up vector (if not set, the spacial object will roll along the
42+ * curve), the orientation precision defines how accurate the orientation of the
43+ * spatial will be.
44+ * @author Mark Powell
45+ * @version $Id: CurveController.java,v 1.1 2004-01-07 23:00:47 mojomonkey Exp $
46+ */
47+public class CurveController extends Controller {
48+ private Spatial mover;
49+ private Curve curve;
50+ private Vector3f up;
51+ private float orientationPrecision = 0.1f;
52+ private float currentTime = 0.0f;
53+ private float deltaTime = 0.0f;
54+
55+ private boolean cycleForward = true;
56+
57+ /**
58+ * Constructor instantiates a new <code>CurveController</code> object.
59+ * The curve object that the controller operates on and the spatial object
60+ * that is moved is specified during construction.
61+ * @param curve the curve to operate on.
62+ * @param mover the spatial to move.
63+ */
64+ public CurveController(Curve curve, Spatial mover) {
65+ this.curve = curve;
66+ this.mover = mover;
67+ setMinTime(0);
68+ setMaxTime(Float.MAX_VALUE);
69+ setRepeatType(Controller.RT_CLAMP);
70+ }
71+
72+ /**
73+ * Constructor instantiates a new <code>CurveController</code> object.
74+ * The curve object that the controller operates on and the spatial object
75+ * that is moved is specified during construction. The game time to
76+ * start and the game time to finish is also supplied.
77+ * @param curve the curve to operate on.
78+ * @param mover the spatial to move.
79+ * @param minTime the time to start the controller.
80+ * @param maxTime the time to end the controller.
81+ */
82+ public CurveController(
83+ Curve curve,
84+ Spatial mover,
85+ float minTime,
86+ float maxTime) {
87+ this.curve = curve;
88+ this.mover = mover;
89+ setMinTime(minTime);
90+ setMaxTime(maxTime);
91+ setRepeatType(Controller.RT_CLAMP);
92+ }
93+
94+ /**
95+ *
96+ * <code>setUpVector</code> sets the locking vector for the spatials up
97+ * vector. This prevents rolling along the curve and allows for a better
98+ * tracking.
99+ * @param up the vector to lock as the spatials up vector.
100+ */
101+ public void setUpVector(Vector3f up) {
102+ this.up = up;
103+ }
104+
105+ /**
106+ *
107+ * <code>setOrientationPrecision</code> sets a precision value for the
108+ * spatials orientation. The smaller the number the higher the precision.
109+ * By default 0.1 is used, and typically does not require changing.
110+ * @param value the precision value of the spatial's orientation.
111+ */
112+ public void setOrientationPrecision(float value) {
113+ orientationPrecision = value;
114+ }
115+
116+ /**
117+ * <code>update</code> moves a spatial along the given curve for along a
118+ * time period.
119+ * @see com.jme.scene.Controller#update(float)
120+ */
121+ public void update(float time) {
122+ if (isActive()) {
123+ currentTime += time;
124+
125+ if (currentTime >= getMinTime() && currentTime <= getMaxTime()) {
126+
127+ if (getRepeatType() == RT_CLAMP) {
128+ deltaTime = currentTime - getMinTime();
129+ mover.setLocalTranslation(curve.getPoint(deltaTime));
130+ mover.setLocalRotation(
131+ curve.getOrientation(
132+ deltaTime,
133+ orientationPrecision,
134+ up));
135+ } else if (getRepeatType() == RT_WRAP) {
136+ deltaTime = (currentTime - getMinTime()) % 1.0f;
137+ if (deltaTime > 1) {
138+ currentTime = 0;
139+ deltaTime = 0;
140+ }
141+ mover.setLocalTranslation(curve.getPoint(deltaTime));
142+ mover.setLocalRotation(
143+ curve.getOrientation(
144+ deltaTime,
145+ orientationPrecision,
146+ up));
147+ } else if (getRepeatType() == RT_CYCLE) {
148+ float prevTime = deltaTime;
149+ deltaTime = (currentTime - getMinTime()) % 1.0f;
150+ if (prevTime > deltaTime) {
151+ cycleForward = !cycleForward;
152+ }
153+ if (cycleForward) {
154+
155+ mover.setLocalTranslation(curve.getPoint(deltaTime));
156+ mover.setLocalRotation(
157+ curve.getOrientation(
158+ deltaTime,
159+ orientationPrecision,
160+ up));
161+ } else {
162+ mover.setLocalTranslation(
163+ curve.getPoint(1.0f - deltaTime));
164+ mover.setLocalRotation(
165+ curve.getOrientation(
166+ 1.0f - deltaTime,
167+ orientationPrecision,
168+ up));
169+ }
170+ } else {
171+ return;
172+ }
173+ }
174+ }
175+
176+ }
177+
178+}