1+ /*
2+ * Copyright (c) 2009-2026 jMonkeyEngine
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
7+ * met:
8+ *
9+ * * Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ *
12+ * * Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+ * may be used to endorse or promote products derived from this software
18+ * without specific prior written permission.
19+ *
20+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+ */
32+
33+ package com .jme3 .vectoreffect ;
34+
35+ import com .jme3 .math .EaseFunction ;
36+ import com .jme3 .math .Easing ;
37+ import com .jme3 .math .Vector4f ;
38+
39+ /**
40+ *
41+ * @author yaRnMcDonuts
42+ */
43+ public final class EaseVectorEffect extends AbstractVectorEffect implements VectorEffect {
44+
45+ private VectorGroup targetVectors ;
46+ private VectorGroup startVectors ;
47+
48+ private float duration = 0f ;
49+ private float easeTimer = 0f ;
50+ private float delay = 0f ;
51+ private float delayTimer = 0f ;
52+
53+ private EaseFunction easeFunction = Easing .linear ;
54+
55+ private final Vector4f tempTargetVec = new Vector4f ();
56+ private final Vector4f tempStartVec = new Vector4f ();
57+
58+
59+ public EaseVectorEffect (VectorGroup vectorToModify ) {
60+ super (vectorToModify );
61+ }
62+
63+ public EaseVectorEffect (VectorGroup vectorToModify , VectorGroup targetVector , float duration ) {
64+ this (vectorToModify );
65+ setEaseToValueOverDuration (duration , targetVector );
66+ }
67+
68+ public EaseVectorEffect (VectorGroup vectorToModify , VectorGroup targetVector , float duration ,
69+ float delay ) {
70+ this (vectorToModify );
71+ setEaseToValueOverDuration (duration , targetVector );
72+ setDelayTime (delay );
73+ }
74+
75+ public EaseVectorEffect (VectorGroup vectorToModify , VectorGroup targetVector , float duration ,
76+ EaseFunction easeFunction ) {
77+ this (vectorToModify , targetVector , duration );
78+ setEaseFunction (easeFunction );
79+ }
80+
81+ public EaseVectorEffect (VectorGroup vectorToModify , VectorGroup targetVector , float duration ,
82+ EaseFunction easeFunction , float delay ) {
83+ this (vectorToModify , targetVector , duration );
84+ setEaseFunction (easeFunction );
85+ setDelayTime (delay );
86+ }
87+
88+
89+ @ Override
90+ public void update (float tpf ) {
91+ super .update (tpf );
92+
93+ if (delayTimer <= delay ) {
94+ delayTimer += tpf ;
95+ return ;
96+ }
97+
98+ if (startVectors == null ) {
99+ startVectors = vectorsToModify .clone ();
100+ }
101+
102+ easeTimer += tpf ;
103+ float t = Math .min (easeTimer / duration , 1f );
104+
105+ float easedT = easeFunction .apply (t );
106+
107+ for (int v = 0 ; v < vectorsToModify .getSize (); v ++){
108+
109+ int targetIndex = Math .min (v , targetVectors .getSize () - 1 ); //allows multiple vectors to share a lesser number of targets if desired
110+ targetVectors .getAsVector4 (targetIndex , tempTargetVec );
111+ startVectors .getAsVector4 (v , tempStartVec );
112+ tempTargetVec .subtractLocal (tempStartVec );
113+ tempTargetVec .multLocal (easedT );
114+
115+ vectorsToModify .updateVectorObject (tempStartVec .addLocal (tempTargetVec ), v );
116+ }
117+
118+ if (t >= 1f ) {
119+ super .setIsFinished (true );
120+ }
121+ }
122+
123+ public EaseVectorEffect setEaseToValueOverDuration (float dur , VectorGroup targetVector ) {
124+ this .targetVectors = targetVector ;
125+ duration = dur ;
126+ startVectors = null ;
127+ return this ;
128+ }
129+
130+ public void setDelayTime (float delay ) {
131+ this .delay = delay ;
132+ }
133+
134+ public void setEaseFunction (EaseFunction func ) {
135+ this .easeFunction = func ;
136+ }
137+
138+ @ Override
139+ public void reset () {
140+ delayTimer = 0 ;
141+ easeTimer = 0 ;
142+ startVectors = null ;
143+ super .reset ();
144+ }
145+
146+ }
0 commit comments