aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft/modelAnimator/Bone.java
blob: 0bda33dd103d7821d4d2650d6e972562c5136831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package ru.olamedia.olacraft.modelAnimator;

import java.util.Random;

public class Bone implements ISkeletonNode {
	private String name;
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	private float speed = 1f;
	private float yaw;
	private float pitch;
	private float roll;
	private float yawCorrection = 0;
	private float pitchCorrection = 0;
	private float rollCorrection = 0;
	@SuppressWarnings("unused")
	private boolean isAnglesModified = false;
	private boolean isMatrixModified = false;

	@Override
	public int getChildrenCount() {
		return 0;
	}

	@Override
	public Bone getChild(int i) {
		return null;
	}

	private void updateAngles() {
		if (isMatrixModified) {

		}
	}

	/*
	 * private void updateMatrix() {
	 * if (isAnglesModified) {
	 * 
	 * }
	 * }
	 */

	public float getSpeed() {
		return speed;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ru.olamedia.olacraft.modelAnimator.ISkeletonNode#setSpeed(float)
	 */
	@Override
	public void setSpeed(float speed) {
		this.speed = speed;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#copyOrientation(ru.olamedia
	 * .olacraft.modelAnimator.Bone)
	 */
	@Override
	public void copyOrientation(ISkeletonNode node) {
		final Bone b = (Bone) node;
		setPitch(b.getPitch());
		setPitchCorrection(b.getPitchCorrection());
		setYaw(b.getYaw());
		setYawCorrection(b.getYawCorrection());
		setRoll(b.getRoll());
		setRollCorrection(b.getRollCorrection());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#setDelta(ru.olamedia
	 * .olacraft.modelAnimator.Bone, ru.olamedia.olacraft.modelAnimator.Bone,
	 * float)
	 */
	@Override
	public void setDelta(ISkeletonNode firstNode, ISkeletonNode secondNode, float delta) {
		final Bone first = (Bone) firstNode;
		final Bone second = (Bone) secondNode;
		final float dPitch = second.getPitch() - first.getPitch();
		setPitch(first.getPitch() + dPitch * getSpeed() * delta);
		final float dYaw = second.getYaw() - first.getYaw();
		setYaw(first.getYaw() + dYaw * getSpeed() * delta);
		final float dRoll = second.getRoll() - first.getRoll();
		setRoll(first.getRoll() + dRoll * getSpeed() * delta);
	}

	public float getYaw() {
		updateAngles();
		return yaw;
	}

	public float getCorrectedYaw() {
		return getYawCorrection() + getYaw();
	}

	public void setYaw(float yaw) {
		this.yaw = yaw;
		isAnglesModified = true;
	}

	public float getPitch() {
		updateAngles();
		return pitch;
	}

	public float getCorrectedPitch() {
		return getPitchCorrection() + getPitch();
	}

	public void setPitch(float pitch) {
		this.pitch = pitch;
		isAnglesModified = true;
	}

	public float getRoll() {
		updateAngles();
		return roll;
	}

	public float getCorrectedRoll() {
		return getRollCorrection() + getRoll();
	}

	public void setRoll(float roll) {
		this.roll = roll;
		isAnglesModified = true;
	}

	private final float yawRand = 5f;
	private final float pitchRand = 1f;
	private final float rollRand = 5f;

	/*
	 * (non-Javadoc)
	 * 
	 * @see ru.olamedia.olacraft.modelAnimator.ISkeletonNode#reset()
	 */
	@Override
	public void reset() {
		yaw = 0;
		pitch = 0;
		roll = 0;
	}

	private float nextFloatDelta(Random rand, Random prev, float delta) {
		final float first = prev.nextFloat();
		final float second = rand.nextFloat();
		return first + (second - first) * delta;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * ru.olamedia.olacraft.modelAnimator.ISkeletonNode#randomize(java.util.
	 * Random, java.util.Random, float)
	 */
	@Override
	public void randomize(Random rand, Random prev, float delta) {
		// delta = 1;
		setYaw(yaw + (nextFloatDelta(rand, prev, delta) - 0.5f) * yawRand);
		setPitch(pitch + (nextFloatDelta(rand, prev, delta) - 0.5f) * pitchRand);
		setRoll(roll + (nextFloatDelta(rand, prev, delta) - 0.5f) * rollRand);
	}

	public float getYawCorrection() {
		return yawCorrection;
	}

	public void setYawCorrection(float yawCorrection) {
		this.yawCorrection = yawCorrection;
	}

	public float getPitchCorrection() {
		return pitchCorrection;
	}

	public void setPitchCorrection(float pitchCorrection) {
		this.pitchCorrection = pitchCorrection;
	}

	public float getRollCorrection() {
		return rollCorrection;
	}

	public void setRollCorrection(float rollCorrection) {
		this.rollCorrection = rollCorrection;
	}

	@Override
	public void setChild(int i, ISkeletonNode b) {

	}
}