aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llanimalcontrols.cpp
blob: 2e047aec71edfdd3cfbcf8e9fddc594fd85e5bb6 (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/** 
 * @file llanimalcontrols.cpp
 * @brief LLAnimalControl class implementation
 *
 * Copyright (c) 2005-2007, Linden Research, Inc.
 * 
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlife.com/developers/opensource/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlife.com/developers/opensource/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 */

#include "llviewerprecompiledheaders.h"

#include "llanimalcontrols.h"
#include "llglheaders.h"
#include "llsphere.h"
#include "llrand.h"
#include "llviewerobject.h"

/*
//const F32 ANIMAL_CONTROLS_MAX_TENSION_FORCE = 0.99f;// I'll explain in a minute...
//const F32 ANIMAL_CONTROLS_MINIMUM_RADIUS	= 0.005f;

const F32 OPACITY		= 1.0f;
const int _X_			= 0;
const int _Y_			= 1;
const int _Z_			= 2;
const F32 BODY_RADIUS	= 0.2f;
const F32 HEAD_RADIUS	= 0.1f;
const F32 ONE_HALF		= 0.5f;

//-----------------------------------------------
// constructor
//-----------------------------------------------
LLHUDAnimalControls::LLHUDAnimalControls()
: LLHUDObject( LL_HUD_ANIMAL_CONTROLS )// cal the base class and pass this in, K?
{
	mParentObject = NULL;

}//------------------------------------------------------------------------------




//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Virtual Server methods...
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
LLAnimalControlsVirtualServer::LLAnimalControlsVirtualServer()
{
	focusPosition.setVec( 0.0f, 0.0f, 0.0f );
	animalPosition.setVec( 0.0f, 0.0f, 0.0f );
	animalRotation			= LLQuaternion::DEFAULT;
	fakeClock				= 0;
	settingFocusPosition	= false;

}//---------------------------------------------------------------------------------



//---------------------------------------------------------------------------------
void LLAnimalControlsVirtualServer::update()
{
	fakeClock ++;

	if ( settingFocusPosition )
	{
		settingFocusPosition = false;
	}

	if ( fakeClock == 20 )
	{
		fakeClock = 0;

		settingFocusPosition = true;

		LLMatrix3 bodyRotationMatrix = animalRotation.getMatrix3();

		LLVector3 forwardDirection	= bodyRotationMatrix.getLeftRow();
		LLVector3 leftDirection		= bodyRotationMatrix.getFwdRow();

		forwardDirection.mV[_Z_] = 0.0f;
		forwardDirection.normVec();
		
		focusPosition = animalPosition + forwardDirection * 5.0f;

		F32 leftRightSpan = 5.0f;

		F32 randomSpan = ll_frand( leftRightSpan );

		focusPosition += leftDirection * ( - leftRightSpan * ONE_HALF + randomSpan );
	}

}//------------------------------------------------------------------------------



//---------------------------------------------------------------------------------
bool LLAnimalControlsVirtualServer::getSettingFocusPosition()
{
	return settingFocusPosition;

}//------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
LLVector3 LLAnimalControlsVirtualServer::getFocusPosition()
{
	return focusPosition;

}//------------------------------------------------------------------------------


//---------------------------------------------------------------------------------
void LLAnimalControlsVirtualServer::setParentPositionAndRotation( LLVector3 p, LLQuaternion r )
{
	animalPosition	= p;
	animalRotation	= r;

}//------------------------------------------------------------------------------

//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// End of Virtual Server methods...
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------




//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Head behavior methods...
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
LLAnimalControlsHeadBehavior::LLAnimalControlsHeadBehavior()
{
	mPosition.setVec		( 0.0f, 0.0f, 0.0f );
	mFocusPosition.setVec	( 0.0f, 0.0f, 0.0f );
	mBodyPosition.setVec	( 0.0f, 0.0f, 0.0f );
	mRotation		= LLQuaternion::DEFAULT;
	mEyesBlinking	= true;
	mEyeBlinkRate	= 0.1f;
	mBodyRotation	= LLQuaternion::DEFAULT;

	LLFlexibleObjectAttributes headFeatherAttributes;
	headFeatherAttributes.mAnchorPositionOffset.setVec( 0.0f, 0.0f, 0.1f );
	headFeatherAttributes.mAnchorDirection.setVec( 0.0f, 1.0f, 1.0f );
	headFeatherAttributes.mAnchorDirection.normVec();
	headFeatherAttributes.mColor = LLColor4( 1.0f, 0.4f, 0.0f, 1.0f );
	headFeatherAttributes.mAnchorRadius = 0.01f;
	headFeatherAttributes.mLength = 0.4f;
	headFeatherAttributes.mEndRadius = 0.06f;
	headFeatherAttributes.mRenderStyle = "tube";

	mFeather.setAttributes( headFeatherAttributes );

}//------------------------------------------------------------------

//------------------------------------------------------------------
void LLAnimalControlsHeadBehavior::setBodyPositionAndRotation( LLVector3 p, LLQuaternion r )
{
	mBodyPosition = p;
	mBodyRotation = r;

}//------------------------------------------------------------------

//------------------------------------------------------------------
void LLAnimalControlsHeadBehavior::setFocusPosition( LLVector3 f )
{
	mFocusPosition = f;

}//------------------------------------------------------------------


//------------------------------------------------------------------
void LLAnimalControlsHeadBehavior::update()
{
	//--------------------------------------------------------------------------
	// Let's get the parent orientation and associated components
	//--------------------------------------------------------------------------
	LLQuaternion	parentOrientation		= mBodyRotation;
	LLMatrix3		parentMatrix			= parentOrientation.getMatrix3();
	LLVector3		parentForwardDirection	= parentMatrix.getLeftRow();
	LLVector3		parentUpwardDirection	= parentMatrix.getUpRow();

	//--------------------------------------------------------------------------
	// head position is based on this
	//--------------------------------------------------------------------------
	mPosition = mBodyPosition + parentForwardDirection * 0.5f + parentUpwardDirection * 0.5f;

	//--------------------------------------------------------------------------------------------------
	// let's figure out how the head would have to rotate in order to aim in the focus direction
	//--------------------------------------------------------------------------------------------------
	LLVector3 headFocusDirection = mFocusPosition - mPosition;
	LLQuaternion headRotationToFocusDirection;
	headRotationToFocusDirection.shortestArc( parentForwardDirection, headFocusDirection );

	//--------------------------------------------------------------------------------------------------
	// Now we rotate the head towards its focus direction
	//--------------------------------------------------------------------------------------------------
	mRotation = parentOrientation * headRotationToFocusDirection;

	//--------------------------------------------------------------------------------------------------
	// now, setting the head feather position and orientation, and updating it...
	//--------------------------------------------------------------------------------------------------
	mFeather.setParentPositionAndRotationDirectly( mPosition, mRotation );
	mFeather.update();

}//------------------------------------------------------------------

//------------------------------------------------------------------


{
	//--------------------------------------------------------------------------------------------------
	// let's get the head rotation components...
	//--------------------------------------------------------------------------------------------------
	LLMatrix3	headMatrix				= mRotation.getMatrix3();
	LLVector3	headForwardDirection	= headMatrix.getLeftRow();
	LLVector3	headUpwardDirection		= headMatrix.getUpRow();
	LLVector3	headLeftDirection		= headMatrix.getFwdRow();

	//------------------------------------------------------
	// show head ball
	//------------------------------------------------------
	glColor4fv( LLColor4( 1.0f, 1.0f, 1.0f, OPACITY ).mV );
	glPushMatrix();
	glTranslatef( mPosition.mV[_X_], mPosition.mV[_Y_], mPosition.mV[_Z_] );
	glScalef( HEAD_RADIUS, HEAD_RADIUS, HEAD_RADIUS );
	gSphere.render();
	glPopMatrix();

	//------------------------------------------------------
	// show head direction
	//------------------------------------------------------
	LLVector3 end = mPosition + headForwardDirection * 0.4f;
	glBegin( GL_LINES );
		glVertex3fv( mPosition.mV );
		glVertex3fv( end.mV );
	glEnd();


	//------------------------------------------------------
	// show eye behavior
	//------------------------------------------------------
	LLVector3 leftEyePosition	= mPosition + headForwardDirection * HEAD_RADIUS + headUpwardDirection * HEAD_RADIUS + headLeftDirection * HEAD_RADIUS * ONE_HALF;
	LLVector3 rightEyePosition	= mPosition + headForwardDirection * HEAD_RADIUS + headUpwardDirection * HEAD_RADIUS - headLeftDirection * HEAD_RADIUS * ONE_HALF;
	glColor4fv( LLColor4( 0.0f, 0.0f, 0.0f, 1.0f ).mV );

	glPushMatrix();
	glTranslatef( leftEyePosition.mV[_X_], leftEyePosition.mV[_Y_], leftEyePosition.mV[_Z_] );
	glScalef( 0.03f, 0.03f, 0.03f );
	gSphere.render();
	glPopMatrix();

	glPushMatrix();
	glTranslatef( rightEyePosition.mV[_X_], rightEyePosition.mV[_Y_], rightEyePosition.mV[_Z_] );
	glScalef( 0.03f, 0.03f, 0.03f );
	gSphere.render();
	glPopMatrix();

	//------------------------------------------------------------------
	// render feather
	//------------------------------------------------------------------
	mFeather.render();

}//------------------------------------------------------------------

//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// End of head behavior methods...
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------




//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Leg behavior methods...
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
LLAnimalControlsLegBehavior::LLAnimalControlsLegBehavior()
{
	mBodyPosition.setVec		( 0.0f, 0.0f, 0.0f );
	mHipAnchorPosition.setVec	( 0.0f, 0.0f, 0.0f ); 
	mBodyRotation		= LLQuaternion::DEFAULT;
	mWalking			= false;
	mIsLeft				= true;

}//-------------------------------------------------------------


//------------------------------------------------------------------
void LLAnimalControlsLegBehavior::setBodyPositionAndRotation( LLVector3 p, LLQuaternion r )
{
	mBodyPosition = p;
	mBodyRotation = r;

}//------------------------------------------------------------------


//---------------------------------------------------------------------------------
void LLAnimalControlsLegBehavior::update()
{

}//-------------------------------------------------------------


//---------------------------------------------------------------------------------
void LLAnimalControlsLegBehavior::render()
{
}//-------------------------------------------------------------








//---------------------------------------------------------------------------------
void LLHUDAnimalControls::update()
{
	if ( ! mParentObject )
	{
		return;
	}

	//-----------------------------------------------------------------------------------
	// To help in development of this client-side functionality, 
	// we are pretending that the server is periodically sending us information,
	// such as focus position (what we want the animal head to look at)
	//-----------------------------------------------------------------------------------
	mVirtualServer.setParentPositionAndRotation( mParentObject->getRenderPosition(), mParentObject->getRenderRotation() ); // fake, hacky, temporary, just ignore this.
	mVirtualServer.update();

	// here is where we ask the virtual server stuff.
	if ( mVirtualServer.getSettingFocusPosition() )
	{
		mHeadBehavior.setFocusPosition( mVirtualServer.getFocusPosition() );
	}

	updateBodyBehavior();

	mHeadBehavior.setBodyPositionAndRotation	( mParentObject->getPosition(), mParentObject->getRenderRotation() );
	mLeftLegBehavior.setBodyPositionAndRotation	( mParentObject->getPosition(), mParentObject->getRenderRotation() );
	mRightLegBehavior.setBodyPositionAndRotation( mParentObject->getPosition(), mParentObject->getRenderRotation() );

	mHeadBehavior.update();
	mLeftLegBehavior.update();
	mRightLegBehavior.update();

}//------------------------------------------------------------------





//------------------------------------------------------------------
void LLHUDAnimalControls::updateBodyBehavior()
{

}//------------------------------------------------------------------




//------------------------------------------------------------------
void LLHUDAnimalControls::render()
{
	mHeadBehavior.render();
	mLeftLegBehavior.render();
	mRightLegBehavior.render();

}//------------------------------------------------------------------









//------------------------------------------------------------------
void LLHUDAnimalControls::setAttributes( LLAnimalControlsAttributes a )
{
	//mAttributes = a; // ???? // how do I do this?

	//mAttributes.mAnchorPositionOffset	= a.mAnchorPositionOffset;
	//mAttributes.mAnchorDirection		= a.mAnchorDirection;
	//mAttributes.mAnchorRadius			= a.mAnchorRadius;	
	//mAttributes.mNumSections			= a.mNumSections;			
	//mAttributes.mLength					= a.mLength;			
	//mAttributes.mGravity				= a.mGravity;			
	//mAttributes.mAirFriction			= a.mAirFriction;		
	//mAttributes.mTension				= a.mTension;			
	//mAttributes.mRadiusChange			= a.mRadiusChange;	

}//------------------------------------------------------------------



//------------------------------------------------------------------
void LLHUDAnimalControls::setParentObject( LLViewerObject * p )
{
	printf( "Setting parent of animal controls %x to object %x \n", this, p );
	mParentObject = p;

}//------------------------------------------------------------------


//------------------------------------------------------------------
LLViewerObject * LLHUDAnimalControls::getParentObject()
{
 return mParentObject;

}//------------------------------------------------------------------



//------------------------------------------------------------------
void LLHUDAnimalControls::markAsDead()
{
	mDead = TRUE;
	mParentObject = NULL;

}//------------------------------------------------------------------




*/