1 /* NAME:
2 E3Camera.c
3
4 DESCRIPTION:
5 Quesa camera object implementation.
6
7 The implementation of the E3Camera_xxx routines _requires_ that a
8 TQ3CameraData field be the first field in any camera specific
9 instance data.
10
11 This allows the generic routines to manipulate the generic fields
12 in any camera object, without having to have accessors for every
13 camera type.
14
15 COPYRIGHT:
16 Copyright (c) 1999-2005, Quesa Developers. All rights reserved.
17
18 For the current release of Quesa, please see:
19
20 <http://www.quesa.org/>
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions
24 are met:
25
26 o Redistributions of source code must retain the above copyright
27 notice, this list of conditions and the following disclaimer.
28
29 o Redistributions in binary form must reproduce the above
30 copyright notice, this list of conditions and the following
31 disclaimer in the documentation and/or other materials provided
32 with the distribution.
33
34 o Neither the name of Quesa nor the names of its contributors
35 may be used to endorse or promote products derived from this
36 software without specific prior written permission.
37
38 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
44 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
45 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
47 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
48 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 ___________________________________________________________________________
50 */
51 //=============================================================================
52 // Include files
53 //-----------------------------------------------------------------------------
54 #include "E3Prefix.h"
55 #include "E3Camera.h"
56
57 #include <cstring>
58 using namespace std;
59
60
61
62 //=============================================================================
63 // Internal functions
64 //-----------------------------------------------------------------------------
65 // E3CameraInfo::E3CameraInfo : Constructor for class info of the class.
66 //-----------------------------------------------------------------------------
67
E3CameraInfo(TQ3XMetaHandler newClassMetaHandler,E3ClassInfo * newParent)68 E3CameraInfo::E3CameraInfo (
69 TQ3XMetaHandler newClassMetaHandler,
70 E3ClassInfo* newParent // nil for root class of course
71 )
72 : E3ShapeInfo ( newClassMetaHandler, newParent ) ,
73 frustumMatrixMethod ( (TQ3XCameraFrustumMatrixMethod) Find_Method ( kQ3XMethodTypeCameraFrustumMatrix ) )
74 {
75 if ( frustumMatrixMethod == NULL )
76 SetAbstract () ;
77 } ;
78
79
80 //=============================================================================
81 // e3camera_new_class_info : Method to construct a class info record.
82 //-----------------------------------------------------------------------------
83 static E3ClassInfo*
e3camera_new_class_info(TQ3XMetaHandler newClassMetaHandler,E3ClassInfo * newParent)84 e3camera_new_class_info (
85 TQ3XMetaHandler newClassMetaHandler,
86 E3ClassInfo* newParent
87 )
88 {
89 return new ( std::nothrow ) E3CameraInfo ( newClassMetaHandler, newParent ) ;
90 }
91
92
93
94
95
96 //=============================================================================
97 // e3camera_orthographic_frustum_matrix : Get the view to frustum matrix.
98 //-----------------------------------------------------------------------------
99 static void
e3camera_orthographic_frustum_matrix(TQ3CameraObject theCamera,TQ3Matrix4x4 * theMatrix)100 e3camera_orthographic_frustum_matrix ( TQ3CameraObject theCamera, TQ3Matrix4x4 *theMatrix)
101 {
102 ( ( E3OrthographicCamera* ) theCamera )->GetFrustumMatrix ( theMatrix ) ;
103 }
104
105
106
107 void
GetFrustumMatrix(TQ3Matrix4x4 * theMatrix)108 E3OrthographicCamera::GetFrustumMatrix ( TQ3Matrix4x4 *theMatrix )
109 {
110 // Initialise ourselves
111 float x = 2.0f / ( right - left ) ;
112 float y = 2.0f / ( top - bottom ) ;
113 float z = 1.0f / ( cameraData.range.yon - cameraData.range.hither ) ;
114
115 float tx = - ( right + left ) / ( right - left ) ;
116 float ty = - ( top + bottom ) / ( top - bottom ) ;
117
118
119
120 // Set up the matrix
121 Q3Matrix4x4_SetIdentity(theMatrix);
122 theMatrix->value[0][0] = x;
123 theMatrix->value[3][0] = tx;
124 theMatrix->value[1][1] = y;
125 theMatrix->value[3][1] = ty;
126 theMatrix->value[2][2] = z;
127 theMatrix->value[3][2] = cameraData.range.hither * z ;
128 }
129
130
131
132
133
134 //=============================================================================
135 // e3camera_orthographic_new : Orthographic camera new method.
136 //-----------------------------------------------------------------------------
137 TQ3Status
e3camera_orthographic_new(TQ3Object theObject,void * privateData,const void * paramData)138 e3camera_orthographic_new(TQ3Object theObject, void *privateData, const void *paramData)
139 {
140 const TQ3OrthographicCameraData *CameraData = (const TQ3OrthographicCameraData *) paramData;
141 #pragma unused(privateData)
142
143
144
145 // Initialise our instance data
146 ( (E3OrthographicCamera*) theObject )->cameraData = CameraData->cameraData ;
147 ( (E3OrthographicCamera*) theObject )->left = CameraData->left ;
148 ( (E3OrthographicCamera*) theObject )->top = CameraData->top ;
149 ( (E3OrthographicCamera*) theObject )->right = CameraData->right ;
150 ( (E3OrthographicCamera*) theObject )->bottom = CameraData->bottom ;
151 return kQ3Success ;
152 }
153
154
155
156
157
158 //=============================================================================
159 // e3camera_orthographic_read : read an orthographic camera.
160 //-----------------------------------------------------------------------------
161 static TQ3Object
e3camera_orthographic_read(TQ3FileObject theFile)162 e3camera_orthographic_read ( TQ3FileObject theFile )
163 {
164 TQ3OrthographicCameraData cameraData ;
165
166 // Initialise the camera data
167 Q3Memory_Clear ( &cameraData, sizeof ( cameraData ) ) ;
168
169 Q3Float32_Read ( &cameraData.left, theFile ) ;
170 Q3Float32_Read ( &cameraData.top, theFile ) ;
171 Q3Float32_Read ( &cameraData.right, theFile ) ;
172 Q3Float32_Read ( &cameraData.bottom, theFile ) ;
173
174 // Read in the attributes
175 while ( Q3File_IsEndOfContainer ( theFile, NULL ) == kQ3False )
176 {
177 TQ3Object childObject = Q3File_ReadObject ( theFile ) ;
178 if ( childObject != NULL )
179 {
180 switch ( childObject->GetLeafType () )
181 {
182 case kQ3CameraPlacment :
183 {
184 memcpy( &cameraData.cameraData.placement, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraPlacement ) ) ;
185 break ;
186 }
187 case kQ3CameraRange :
188 {
189 memcpy( &cameraData.cameraData.range, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraRange ) ) ;
190 break ;
191 }
192 case kQ3CameraViewPort :
193 {
194 memcpy( &cameraData.cameraData.viewPort, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraViewPort ) ) ;
195 break ;
196 }
197 case kQ3SharedTypeSet :
198 {
199 // Set must be at end so we know we've finished
200
201 TQ3CameraObject result = Q3OrthographicCamera_New ( &cameraData ) ;
202 result->SetSet ( childObject ) ;
203 Q3Object_Dispose ( childObject ) ;
204 return result ;
205 }
206 }
207
208 Q3Object_Dispose ( childObject ) ;
209 }
210 }
211
212
213
214 // Create the camera
215 return Q3OrthographicCamera_New ( &cameraData ) ;
216 }
217
218
219 //=============================================================================
220 // e3camera_orthographic_traverse : traverse an orthographic camera.
221 //-----------------------------------------------------------------------------
222 static TQ3Status
e3camera_orthographic_traverse(TQ3SharedObject theObject,void * data,TQ3ViewObject theView)223 e3camera_orthographic_traverse ( TQ3SharedObject theObject, void *data, TQ3ViewObject theView )
224 {
225 TQ3Uns32 result = Q3XView_SubmitWriteData ( theView, sizeof ( TQ3Float32 ) * 4, theObject, NULL ) ;
226
227 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraPlacment ), sizeof ( TQ3CameraPlacement ), theObject, NULL ) ;
228 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraRange ), sizeof ( TQ3CameraRange ), theObject, NULL ) ;
229 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraViewPort ), sizeof ( TQ3CameraViewPort ), theObject, NULL ) ;
230
231 return (TQ3Status) result ;
232 }
233
234
235 //=============================================================================
236 // e3camera_orthographic_write : write an orthographic camera.
237 //-----------------------------------------------------------------------------
238 static TQ3Status
e3camera_orthographic_write(TQ3ViewObject theObject,TQ3FileObject theFile)239 e3camera_orthographic_write ( TQ3ViewObject theObject, TQ3FileObject theFile )
240 {
241 TQ3OrthographicCameraData cameraData ;
242 Q3OrthographicCamera_GetData ( theObject , &cameraData ) ;
243
244 TQ3Uns32 result = kQ3Success ;
245
246 result &= Q3Float32_Write ( cameraData.left, theFile ) ;
247 result &= Q3Float32_Write ( cameraData.top, theFile ) ;
248 result &= Q3Float32_Write ( cameraData.right, theFile ) ;
249 result &= Q3Float32_Write ( cameraData.bottom, theFile ) ;
250
251 return (TQ3Status) result ;
252 }
253
254
255 //=============================================================================
256 // e3camera_orthographic_metahandler : Orthographic camera metahandler.
257 //-----------------------------------------------------------------------------
258 static TQ3XFunctionPointer
e3camera_orthographic_metahandler(TQ3XMethodType methodType)259 e3camera_orthographic_metahandler ( TQ3XMethodType methodType )
260 {
261 // Return our methods
262 switch (methodType) {
263 case kQ3XMethodTypeObjectNew :
264 return (TQ3XFunctionPointer) e3camera_orthographic_new ;
265
266 case kQ3XMethodTypeCameraFrustumMatrix:
267 return (TQ3XFunctionPointer) e3camera_orthographic_frustum_matrix ;
268
269 case kQ3XMethodTypeObjectRead :
270 return (TQ3XFunctionPointer) e3camera_orthographic_read ;
271
272 case kQ3XMethodTypeObjectTraverse :
273 return (TQ3XFunctionPointer) e3camera_orthographic_traverse ;
274
275 case kQ3XMethodTypeObjectWrite :
276 return (TQ3XFunctionPointer) e3camera_orthographic_write ;
277 }
278
279 return NULL ;
280 }
281
282
283
284
285
286 //=============================================================================
287 // e3camera_viewplane_frustum_matrix : Get the view to frustum matrix.
288 //-----------------------------------------------------------------------------
289 void
e3camera_viewplane_frustum_matrix(TQ3CameraObject theCamera,TQ3Matrix4x4 * theMatrix)290 e3camera_viewplane_frustum_matrix(TQ3CameraObject theCamera, TQ3Matrix4x4 *theMatrix)
291 {
292
293
294
295 // Calculate the view to frustum matrix for the camera
296 // dair, to be implemented
297 Q3Matrix4x4_SetIdentity(theMatrix);
298 }
299
300
301
302
303
304 //=============================================================================
305 // e3camera_viewplane_new : View Plane camera new method.
306 //-----------------------------------------------------------------------------
307 TQ3Status
e3camera_viewplane_new(TQ3Object theObject,void * privateData,const void * paramData)308 e3camera_viewplane_new(TQ3Object theObject, void *privateData, const void *paramData)
309 {
310 const TQ3ViewPlaneCameraData *CameraData = (const TQ3ViewPlaneCameraData *) paramData;
311 #pragma unused(privateData)
312
313
314
315 // Initialise our instance data
316 ( (E3ViewPlaneCamera*) theObject )->cameraData = CameraData->cameraData ;
317 ( (E3ViewPlaneCamera*) theObject )->viewPlane = CameraData->viewPlane ;
318 ( (E3ViewPlaneCamera*) theObject )->halfWidthAtViewPlane = CameraData->halfWidthAtViewPlane ;
319 ( (E3ViewPlaneCamera*) theObject )->halfHeightAtViewPlane = CameraData->halfHeightAtViewPlane ;
320 ( (E3ViewPlaneCamera*) theObject )->centerXOnViewPlane = CameraData->centerXOnViewPlane ;
321 ( (E3ViewPlaneCamera*) theObject )->centerYOnViewPlane = CameraData->centerYOnViewPlane ;
322 return kQ3Success ;
323 }
324
325
326
327
328
329 //=============================================================================
330 // e3camera_viewplane_read : read an view plane camera.
331 //-----------------------------------------------------------------------------
332 static TQ3Object
e3camera_viewplane_read(TQ3FileObject theFile)333 e3camera_viewplane_read ( TQ3FileObject theFile )
334 {
335 TQ3ViewPlaneCameraData cameraData ;
336
337 // Initialise the camera data
338 Q3Memory_Clear ( &cameraData, sizeof ( cameraData ) ) ;
339
340 Q3Float32_Read ( &cameraData.viewPlane, theFile ) ;
341 Q3Float32_Read ( &cameraData.halfWidthAtViewPlane, theFile ) ;
342 Q3Float32_Read ( &cameraData.halfHeightAtViewPlane, theFile ) ;
343 Q3Float32_Read ( &cameraData.centerXOnViewPlane, theFile ) ;
344 Q3Float32_Read ( &cameraData.centerYOnViewPlane, theFile ) ;
345
346 // Read in the attributes
347 while ( Q3File_IsEndOfContainer ( theFile, NULL ) == kQ3False )
348 {
349 TQ3Object childObject = Q3File_ReadObject ( theFile ) ;
350 if ( childObject != NULL )
351 {
352 switch ( childObject->GetLeafType () )
353 {
354 case kQ3CameraPlacment :
355 {
356 memcpy( &cameraData.cameraData.placement, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraPlacement ) ) ;
357 break ;
358 }
359 case kQ3CameraRange :
360 {
361 memcpy( &cameraData.cameraData.range, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraRange ) ) ;
362 break ;
363 }
364 case kQ3CameraViewPort :
365 {
366 memcpy( &cameraData.cameraData.viewPort, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraViewPort ) ) ;
367 break ;
368 }
369 case kQ3SharedTypeSet :
370 {
371 // Set must be at end so we know we've finished
372
373 TQ3CameraObject result = Q3ViewPlaneCamera_New ( &cameraData ) ;
374 result->SetSet ( childObject ) ;
375 Q3Object_Dispose ( childObject ) ;
376 return result ;
377 }
378 }
379
380 Q3Object_Dispose ( childObject ) ;
381 }
382 }
383
384
385
386 // Create the camera
387 return Q3ViewPlaneCamera_New ( &cameraData ) ;
388 }
389
390
391
392
393
394
395
396 //=============================================================================
397 // e3camera_viewplane_traverse : traverse a view plane camera.
398 //-----------------------------------------------------------------------------
399 static TQ3Status
e3camera_viewplane_traverse(TQ3SharedObject theObject,void * data,TQ3ViewObject theView)400 e3camera_viewplane_traverse ( TQ3SharedObject theObject, void *data, TQ3ViewObject theView )
401 {
402 TQ3Uns32 result = Q3XView_SubmitWriteData ( theView, sizeof ( TQ3Float32 ) * 5, theObject, NULL ) ;
403
404 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraPlacment ), sizeof ( TQ3CameraPlacement ), theObject, NULL ) ;
405 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraRange ), sizeof ( TQ3CameraRange ), theObject, NULL ) ;
406 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraViewPort ), sizeof ( TQ3CameraViewPort ), theObject, NULL ) ;
407
408 return (TQ3Status) result ;
409 }
410
411
412 //=============================================================================
413 // e3camera_viewplane_write : write a view plane camera.
414 //-----------------------------------------------------------------------------
415 static TQ3Status
e3camera_viewplane_write(TQ3ViewObject theObject,TQ3FileObject theFile)416 e3camera_viewplane_write ( TQ3ViewObject theObject, TQ3FileObject theFile )
417 {
418 TQ3ViewPlaneCameraData cameraData ;
419 Q3ViewPlaneCamera_GetData ( theObject , &cameraData ) ;
420
421 TQ3Uns32 result = kQ3Success ;
422
423 result &= Q3Float32_Write ( cameraData.viewPlane, theFile ) ;
424 result &= Q3Float32_Write ( cameraData.halfWidthAtViewPlane, theFile ) ;
425 result &= Q3Float32_Write ( cameraData.halfHeightAtViewPlane, theFile ) ;
426 result &= Q3Float32_Write ( cameraData.centerXOnViewPlane, theFile ) ;
427 result &= Q3Float32_Write ( cameraData.centerYOnViewPlane, theFile ) ;
428
429 return (TQ3Status) result ;
430 }
431
432
433 //=============================================================================
434 // e3camera_viewplane_metahandler : View Plane camera metahandler.
435 //-----------------------------------------------------------------------------
436 static TQ3XFunctionPointer
e3camera_viewplane_metahandler(TQ3XMethodType methodType)437 e3camera_viewplane_metahandler ( TQ3XMethodType methodType )
438 {
439 // Return our methods
440 switch ( methodType )
441 {
442 case kQ3XMethodTypeObjectNew:
443 return (TQ3XFunctionPointer) e3camera_viewplane_new;
444
445 case kQ3XMethodTypeCameraFrustumMatrix:
446 return (TQ3XFunctionPointer) e3camera_viewplane_frustum_matrix;
447
448 case kQ3XMethodTypeObjectRead :
449 return (TQ3XFunctionPointer) e3camera_viewplane_read ;
450
451 case kQ3XMethodTypeObjectTraverse :
452 return (TQ3XFunctionPointer) e3camera_viewplane_traverse ;
453
454 case kQ3XMethodTypeObjectWrite :
455 return (TQ3XFunctionPointer) e3camera_viewplane_write ;
456 }
457
458 return NULL ;
459 }
460
461
462
463
464
465 //=============================================================================
466 // e3camera_viewangle_frustum_matrix : Get the view to frustum matrix.
467 //-----------------------------------------------------------------------------
468 static void
e3camera_viewangle_frustum_matrix(TQ3CameraObject theCamera,TQ3Matrix4x4 * theMatrix)469 e3camera_viewangle_frustum_matrix(TQ3CameraObject theCamera, TQ3Matrix4x4 *theMatrix)
470 {
471 ( ( E3ViewAngleAspectCamera* ) theCamera )->GetFrustumMatrix ( theMatrix ) ;
472 }
473
474
475 void
GetFrustumMatrix(TQ3Matrix4x4 * theMatrix)476 E3ViewAngleAspectCamera::GetFrustumMatrix ( TQ3Matrix4x4 *theMatrix )
477 {
478 // Initialise ourselves
479 float zNear = cameraData.range.hither;
480 float zFar = cameraData.range.yon;
481 float oneOverZFar = 1.0f / zFar;
482
483 float a = 1.0f / (1.0f - zNear * oneOverZFar);
484 float c = (-zNear * a) / (zNear * zFar);
485
486 float w = 1.0f / (float) tan ( fov * 0.5f ) ;
487 if ( aspectRatioXToY > 1.0f )
488 w = w / aspectRatioXToY ;
489
490 float h = w * aspectRatioXToY;
491 float q = zFar / (zFar - zNear);
492
493
494
495 // Set up the matrix
496 Q3Matrix4x4_SetIdentity(theMatrix);
497 theMatrix->value[0][0] = w * oneOverZFar;
498 theMatrix->value[1][1] = h * oneOverZFar;
499 theMatrix->value[2][2] = a * oneOverZFar;
500 theMatrix->value[2][3] = c / q;
501 theMatrix->value[3][2] = q * zNear * oneOverZFar;
502 theMatrix->value[3][3] = 0.0f;
503 }
504
505
506
507
508
509
510 //=============================================================================
511 // e3camera_viewangle_read : read a view angle aspect camera.
512 //-----------------------------------------------------------------------------
513 static TQ3Object
e3camera_viewangle_read(TQ3FileObject theFile)514 e3camera_viewangle_read ( TQ3FileObject theFile )
515 {
516 TQ3ViewAngleAspectCameraData cameraData ;
517
518 // Initialise the camera data
519 Q3Memory_Clear ( &cameraData, sizeof ( cameraData ) ) ;
520
521 if ( Q3Float32_Read ( &cameraData.fov, theFile ) == kQ3Failure )
522 cameraData.fov = 1.0f ; // What is a sensible default?
523
524 if ( Q3Float32_Read ( &cameraData.aspectRatioXToY, theFile ) == kQ3Failure )
525 cameraData.aspectRatioXToY = 1.0f ;
526
527 // Read in the attributes
528 while ( Q3File_IsEndOfContainer ( theFile, NULL ) == kQ3False )
529 {
530 TQ3Object childObject = Q3File_ReadObject ( theFile ) ;
531 if ( childObject != NULL )
532 {
533 switch ( childObject->GetLeafType () )
534 {
535 case kQ3CameraPlacment :
536 {
537 memcpy( &cameraData.cameraData.placement, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraPlacement ) ) ;
538 break ;
539 }
540 case kQ3CameraRange :
541 {
542 memcpy( &cameraData.cameraData.range, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraRange ) ) ;
543 break ;
544 }
545 case kQ3CameraViewPort :
546 {
547 memcpy( &cameraData.cameraData.viewPort, childObject->FindLeafInstanceData () , sizeof ( TQ3CameraViewPort ) ) ;
548 break ;
549 }
550 case kQ3SharedTypeSet :
551 {
552 // Set must be at end so we know we've finished
553
554 TQ3CameraObject result = Q3ViewAngleAspectCamera_New ( &cameraData ) ;
555 result->SetSet ( childObject ) ;
556 Q3Object_Dispose ( childObject ) ;
557 return result ;
558 }
559 }
560
561 Q3Object_Dispose ( childObject ) ;
562 }
563 }
564
565
566
567 // Create the camera
568 return Q3ViewAngleAspectCamera_New ( &cameraData ) ;
569 }
570
571
572 //=============================================================================
573 // e3camera_viewangle_new : View Angle camera new method.
574 //-----------------------------------------------------------------------------
575 TQ3Status
e3camera_viewangle_new(TQ3Object theObject,void * privateData,const void * paramData)576 e3camera_viewangle_new(TQ3Object theObject, void *privateData, const void *paramData)
577 {
578 const TQ3ViewAngleAspectCameraData* CameraData = (const TQ3ViewAngleAspectCameraData *) paramData;
579 #pragma unused(privateData)
580
581
582
583 // Initialise our instance data
584 ( (E3ViewAngleAspectCamera*) theObject )->cameraData = CameraData->cameraData ;
585 ( (E3ViewAngleAspectCamera*) theObject )->fov = CameraData->fov ;
586 ( (E3ViewAngleAspectCamera*) theObject )->aspectRatioXToY = CameraData->aspectRatioXToY ;
587 return kQ3Success ;
588 }
589
590
591
592 //=============================================================================
593 // e3camera_viewangle_traverse : traverse a view angle aspect camera.
594 //-----------------------------------------------------------------------------
595 static TQ3Status
e3camera_viewangle_traverse(TQ3SharedObject theObject,void * data,TQ3ViewObject theView)596 e3camera_viewangle_traverse ( TQ3SharedObject theObject, void *data, TQ3ViewObject theView )
597 {
598 TQ3Uns32 result = Q3XView_SubmitWriteData ( theView, sizeof ( TQ3Float32 ) * 2, theObject, NULL ) ;
599
600 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraPlacment ), sizeof ( TQ3CameraPlacement ), theObject, NULL ) ;
601 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraRange ), sizeof ( TQ3CameraRange ), theObject, NULL ) ;
602 result &= Q3XView_SubmitSubObjectData ( theView, (TQ3XObjectClass) E3ClassTree::GetClass ( kQ3CameraViewPort ), sizeof ( TQ3CameraViewPort ), theObject, NULL ) ;
603
604 return (TQ3Status) result ;
605 }
606
607
608 //=============================================================================
609 // e3camera_viewangle_write : write a view angle aspect camera.
610 //-----------------------------------------------------------------------------
611 static TQ3Status
e3camera_viewangle_write(TQ3ViewObject theObject,TQ3FileObject theFile)612 e3camera_viewangle_write ( TQ3ViewObject theObject, TQ3FileObject theFile )
613 {
614 TQ3ViewAngleAspectCameraData cameraData ;
615 Q3ViewAngleAspectCamera_GetData ( theObject , &cameraData ) ;
616
617 TQ3Uns32 result = kQ3Success ;
618
619 result &= Q3Float32_Write ( cameraData.fov, theFile ) ;
620 result &= Q3Float32_Write ( cameraData.aspectRatioXToY, theFile ) ;
621
622 return (TQ3Status) result ;
623 }
624
625
626 //=============================================================================
627 // e3camera_viewangle_metahandler : View Angle camera metahandler.
628 //-----------------------------------------------------------------------------
629 static TQ3XFunctionPointer
e3camera_viewangle_metahandler(TQ3XMethodType methodType)630 e3camera_viewangle_metahandler(TQ3XMethodType methodType)
631 {
632 // Return our methods
633 switch ( methodType )
634 {
635 case kQ3XMethodTypeObjectNew:
636 return (TQ3XFunctionPointer) e3camera_viewangle_new ;
637
638 case kQ3XMethodTypeCameraFrustumMatrix:
639 return (TQ3XFunctionPointer) e3camera_viewangle_frustum_matrix ;
640
641 case kQ3XMethodTypeObjectRead :
642 return (TQ3XFunctionPointer) e3camera_viewangle_read ;
643
644 case kQ3XMethodTypeObjectTraverse :
645 return (TQ3XFunctionPointer) e3camera_viewangle_traverse ;
646
647 case kQ3XMethodTypeObjectWrite :
648 return (TQ3XFunctionPointer) e3camera_viewangle_write ;
649 }
650
651 return NULL ;
652 }
653
654
655
656
657
658 //=============================================================================
659 // e3camera_metahandler : Camera metahandler.
660 //-----------------------------------------------------------------------------
661 static TQ3XFunctionPointer
e3camera_metahandler(TQ3XMethodType methodType)662 e3camera_metahandler ( TQ3XMethodType methodType )
663 {
664 // Return our methods
665 switch ( methodType )
666 {
667 case kQ3XMethodTypeNewObjectClass :
668 return (TQ3XFunctionPointer) e3camera_new_class_info ;
669 }
670
671 return NULL ;
672 }
673
674
675
676
677
678 //=============================================================================
679 // Public functions
680 //-----------------------------------------------------------------------------
681 // E3Camera_RegisterClass : Register the camera classes.
682 //-----------------------------------------------------------------------------
683 #pragma mark -
684 TQ3Status
RegisterClass(void)685 E3Camera::RegisterClass(void)
686 { TQ3Status qd3dStatus;
687
688
689
690 // Register the camera classes
691 qd3dStatus = Q3_REGISTER_CLASS ( kQ3ClassNameCamera,
692 e3camera_metahandler,
693 E3Camera ) ;
694
695 if (qd3dStatus == kQ3Success)
696 qd3dStatus = Q3_REGISTER_CLASS ( kQ3ClassNameCameraOrthographic,
697 e3camera_orthographic_metahandler,
698 E3OrthographicCamera ) ;
699
700 if (qd3dStatus == kQ3Success)
701 qd3dStatus = Q3_REGISTER_CLASS ( kQ3ClassNameCameraViewPlane,
702 e3camera_viewplane_metahandler,
703 E3ViewPlaneCamera ) ;
704
705 if (qd3dStatus == kQ3Success)
706 qd3dStatus = Q3_REGISTER_CLASS ( kQ3ClassNameCameraViewAngle,
707 e3camera_viewangle_metahandler,
708 E3ViewAngleAspectCamera ) ;
709
710 return(qd3dStatus);
711 }
712
713
714
715
716
717 //=============================================================================
718 // E3Camera_UnregisterClass : Unregister the camera classes.
719 //-----------------------------------------------------------------------------
720 TQ3Status
UnregisterClass(void)721 E3Camera::UnregisterClass(void)
722 {
723 // Unregister the camera classes
724 TQ3Status qd3dStatus = E3ClassTree::UnregisterClass ( kQ3CameraTypeViewAngleAspect, kQ3True ) ;
725 * ( (TQ3Int32*) &qd3dStatus ) &= E3ClassTree::UnregisterClass ( kQ3CameraTypeViewPlane, kQ3True ) ;
726 * ( (TQ3Int32*) &qd3dStatus ) &= E3ClassTree::UnregisterClass ( kQ3CameraTypeOrthographic, kQ3True ) ;
727 * ( (TQ3Int32*) &qd3dStatus ) &= E3ClassTree::UnregisterClass ( kQ3ShapeTypeCamera, kQ3True ) ;
728
729 return qd3dStatus ; // We used to only return the result of the final unregister, now we return failure if any of them failed
730 }
731
732
733
734
735
736 //=============================================================================
737 // E3Camera::IsOfMyClass : Check if object pointer is valid and of type camera
738 //-----------------------------------------------------------------------------
739 // Replaces Q3Object_IsType ( object, kQ3ShapeTypeCamera )
740 // but call is smaller and does not call E3System_Bottleneck
741 // as this is (always?) done in the calling code as well
742 //-----------------------------------------------------------------------------
743 TQ3Boolean
IsOfMyClass(TQ3Object object)744 E3Camera::IsOfMyClass ( TQ3Object object )
745 {
746 if ( object == NULL )
747 return kQ3False ;
748
749 if ( object->IsObjectValid () )
750 return Q3_OBJECT_IS_CLASS ( object, E3Camera ) ;
751
752 return kQ3False ;
753 }
754
755
756
757
758
759 //=============================================================================
760 // E3Camera_GetType : Return the type of a camera.
761 //-----------------------------------------------------------------------------
762 TQ3ObjectType
GetType(void)763 E3Camera::GetType ( void )
764 {
765 // Return the type
766 return GetObjectType ( kQ3ShapeTypeCamera ) ;
767 }
768
769
770
771
772
773 //=============================================================================
774 // E3Camera_SetData : Set the data for a camera.
775 //-----------------------------------------------------------------------------
776 TQ3Status
SetData(const TQ3CameraData * CameraData)777 E3Camera::SetData ( const TQ3CameraData *CameraData )
778 {
779 // Set the camera data
780 cameraData = *CameraData ;
781
782 Q3Shared_Edited ( this ) ;
783
784 return kQ3Success ;
785 }
786
787
788
789
790
791 //=============================================================================
792 // E3Camera_GetData : Return the data for a camera.
793 //-----------------------------------------------------------------------------
794 TQ3Status
GetData(TQ3CameraData * CameraData)795 E3Camera::GetData ( TQ3CameraData *CameraData )
796 {
797 // Return the camera data
798
799 *CameraData = cameraData ;
800
801 return kQ3Success ;
802 }
803
804
805
806
807
808 //=============================================================================
809 // E3Camera_SetPlacement : Set the placement for a camera.
810 //-----------------------------------------------------------------------------
811 TQ3Status
SetPlacement(const TQ3CameraPlacement * Placement)812 E3Camera::SetPlacement ( const TQ3CameraPlacement *Placement )
813 {
814 // Set the camera placement
815 cameraData.placement = *Placement ;
816 Q3Shared_Edited ( this ) ;
817
818 return kQ3Success ;
819 }
820
821
822
823
824
825 //=============================================================================
826 // E3Camera_GetPlacement : Return the placement of a camera.
827 //-----------------------------------------------------------------------------
828 TQ3Status
GetPlacement(TQ3CameraPlacement * placement)829 E3Camera::GetPlacement ( TQ3CameraPlacement *placement )
830 {
831 // Return the camera placement
832 *placement = cameraData.placement ;
833
834 return kQ3Success ;
835 }
836
837
838
839
840
841 //=============================================================================
842 // E3Camera_SetRange : Set the range for a camera.
843 //-----------------------------------------------------------------------------
844 TQ3Status
SetRange(const TQ3CameraRange * range)845 E3Camera::SetRange ( const TQ3CameraRange *range )
846 {
847 // Set the camera range
848 cameraData.range = *range ;
849
850 Q3Shared_Edited ( this ) ;
851
852 return kQ3Success ;
853 }
854
855
856
857
858
859 //=============================================================================
860 // E3Camera_GetRange : Return the range of a camera.
861 //-----------------------------------------------------------------------------
862 TQ3Status
GetRange(TQ3CameraRange * range)863 E3Camera::GetRange ( TQ3CameraRange *range )
864 {
865 // Return the camera range
866 *range = cameraData.range ;
867
868 return kQ3Success ;
869 }
870
871
872
873
874
875 //=============================================================================
876 // E3Camera_SetViewPort : Set the viewport for a camera.
877 //-----------------------------------------------------------------------------
878 TQ3Status
SetViewPort(const TQ3CameraViewPort * viewPort)879 E3Camera::SetViewPort ( const TQ3CameraViewPort *viewPort )
880 {
881 // Set the camera viewport
882 cameraData.viewPort = *viewPort ;
883
884 Q3Shared_Edited ( this ) ;
885
886 return kQ3Success ;
887 }
888
889
890
891
892
893 //=============================================================================
894 // E3Camera_GetViewPort : Return the viewport of a camera.
895 //-----------------------------------------------------------------------------
896 TQ3Status
GetViewPort(TQ3CameraViewPort * viewPort)897 E3Camera::GetViewPort ( TQ3CameraViewPort *viewPort )
898 {
899 // Return the camera viewport
900 *viewPort = cameraData.viewPort ;
901
902 return kQ3Success ;
903 }
904
905
906
907
908
909 //=============================================================================
910 // E3Camera_GetWorldToView : Return a camera's world-to-view matrix.
911 //-----------------------------------------------------------------------------
912 // Note : The world-to-view space transform is defined only by the
913 // placement of the camera; it establishes the camera location as
914 // the origin of the view space, with the view vector (that is,
915 // the vector from the camera's eye toward the point of interest)
916 // placed along the -z axis and the up vector placed along the
917 // y axis.
918 //-----------------------------------------------------------------------------
919 TQ3Status
GetWorldToView(TQ3Matrix4x4 * worldToView)920 E3Camera::GetWorldToView ( TQ3Matrix4x4 *worldToView )
921 {
922 TQ3Matrix4x4 translateMatrix;
923 TQ3Vector3D n, v, u;
924
925
926
927 // Work out our vectors
928 Q3Point3D_Subtract(&cameraData.placement.cameraLocation,
929 &cameraData.placement.pointOfInterest,
930 &n);
931
932 Q3Vector3D_Normalize(&n, &n);
933 Q3Vector3D_Normalize(&cameraData.placement.upVector, &v);
934
935 Q3Vector3D_Cross(&v, &n, &u);
936 Q3Vector3D_Normalize(&u, &u);
937
938 Q3Vector3D_Cross(&n, &u, &v);
939 Q3Vector3D_Normalize(&v, &v);
940
941
942
943 // Set up the rotation matrix
944 Q3Matrix4x4_SetIdentity(worldToView);
945
946 worldToView->value[0][0] = u.x;
947 worldToView->value[1][0] = u.y;
948 worldToView->value[2][0] = u.z;
949
950 worldToView->value[0][1] = v.x;
951 worldToView->value[1][1] = v.y;
952 worldToView->value[2][1] = v.z;
953
954 worldToView->value[0][2] = n.x;
955 worldToView->value[1][2] = n.y;
956 worldToView->value[2][2] = n.z;
957
958
959
960 // Multiply in the translation matrix
961 Q3Matrix4x4_SetTranslate(&translateMatrix,
962 - cameraData.placement.cameraLocation.x,
963 - cameraData.placement.cameraLocation.y,
964 - cameraData.placement.cameraLocation.z);
965
966 Q3Matrix4x4_Multiply(&translateMatrix, worldToView, worldToView);
967
968 return kQ3Success ;
969 }
970
971
972
973
974
975 //=============================================================================
976 // E3Camera_GetWorldToFrustum : Return a camera's world-to-frustum matrix.
977 //-----------------------------------------------------------------------------
978 TQ3Status
GetWorldToFrustum(TQ3Matrix4x4 * worldToFrustum)979 E3Camera::GetWorldToFrustum ( TQ3Matrix4x4 *worldToFrustum )
980 {
981 TQ3Matrix4x4 worldToView, viewToFrustum;
982
983
984
985 // Get the two matrices we need, and multiply them together
986 Q3Camera_GetWorldToView( this , &worldToView);
987 Q3Camera_GetViewToFrustum( this , &viewToFrustum);
988
989 Q3Matrix4x4_Multiply(&worldToView, &viewToFrustum, worldToFrustum);
990
991 return kQ3Success ;
992 }
993
994
995
996
997
998 //=============================================================================
999 // E3Camera_GetViewToFrustum : Return a camera's view-to-frustum matrix.
1000 //-----------------------------------------------------------------------------
1001 TQ3Status
GetViewToFrustum(TQ3Matrix4x4 * viewToFrustum)1002 E3Camera::GetViewToFrustum ( TQ3Matrix4x4 *viewToFrustum )
1003 {
1004 TQ3Matrix4x4 viewPortMatrix;
1005 TQ3CameraViewPort viewPort;
1006
1007
1008
1009 // Initialise a return value
1010 Q3Matrix4x4_SetIdentity(viewToFrustum); // Is this needed any more?
1011
1012
1013
1014 // Get the view to frustum matrix
1015 //
1016 // This matrix transforms the viewing coordinate system to the canonical
1017 // frustum. This ranges from -1 to +1 in x and y, and 0 to -1 in z (where
1018 // 0 is the near clip plane, and -1 is the far clip plane).
1019 GetClass ()->frustumMatrixMethod ( this, viewToFrustum ) ;
1020
1021
1022
1023 // Get the camera view port
1024 //
1025 // A portion of the viewing frustum can be selected with the camera's
1026 // view port.
1027 //
1028 // Since the frustum sides are parallel, this can be accomplished by
1029 // scaling and translating the viewing frustum in order to expand some
1030 // portion of the xy plane to the full -1/+1 range.
1031 //
1032 // The default view port corresponds to the full -1/+1 range, and so the
1033 // additional transforms will be identity transforms for that case.
1034 Q3Camera_GetViewPort( this, &viewPort);
1035
1036
1037
1038 // Translate the view port to the origin
1039 float translateX = viewPort.origin.x + (viewPort.width / 2.0f);
1040 float translateY = viewPort.origin.y - (viewPort.height / 2.0f);
1041
1042 Q3Matrix4x4_SetTranslate(&viewPortMatrix, -translateX, -translateY, 0.0f);
1043 Q3Matrix4x4_Multiply(viewToFrustum, &viewPortMatrix, viewToFrustum);
1044
1045
1046
1047 // Scale it back up to -1 to +1 in x and y
1048 float scaleWidth = 2.0f / viewPort.width;
1049 float scaleHeight = 2.0f / viewPort.height;
1050
1051 Q3Matrix4x4_SetScale(&viewPortMatrix, scaleWidth, scaleHeight, 1.0f);
1052 Q3Matrix4x4_Multiply(viewToFrustum, &viewPortMatrix, viewToFrustum);
1053
1054 return kQ3Success ;
1055 }
1056
1057
1058
1059
1060
1061 //=============================================================================
1062 // E3OrthographicCamera_New : Create an orthographic camera.
1063 //-----------------------------------------------------------------------------
1064 #pragma mark -
1065 TQ3CameraObject
E3OrthographicCamera_New(const TQ3OrthographicCameraData * orthographicData)1066 E3OrthographicCamera_New(const TQ3OrthographicCameraData *orthographicData)
1067 {
1068 // Create the object
1069 return E3ClassTree::CreateInstance ( kQ3CameraTypeOrthographic, kQ3False, orthographicData ) ;
1070 }
1071
1072
1073
1074
1075
1076 //=============================================================================
1077 // E3OrthographicCamera_GetData : Return an orthographic camera's data.
1078 //-----------------------------------------------------------------------------
1079 TQ3Status
GetData(TQ3OrthographicCameraData * CameraData)1080 E3OrthographicCamera::GetData ( TQ3OrthographicCameraData *CameraData )
1081 {
1082 // Return the camera's data
1083 *CameraData = * ( ( TQ3OrthographicCameraData* ) &cameraData ) ;
1084
1085 return kQ3Success ;
1086 }
1087
1088
1089
1090
1091
1092 //=============================================================================
1093 // E3OrthographicCamera_SetData : Set the data for an orthographic camera.
1094 //-----------------------------------------------------------------------------
1095 TQ3Status
SetData(const TQ3OrthographicCameraData * CameraData)1096 E3OrthographicCamera::SetData ( const TQ3OrthographicCameraData *CameraData )
1097 {
1098 // Return the camera's data
1099 * ( ( TQ3OrthographicCameraData* ) &cameraData ) = *CameraData ;
1100
1101 Q3Shared_Edited ( this );
1102
1103 return kQ3Success ;
1104 }
1105
1106
1107
1108
1109
1110 //=============================================================================
1111 // E3OrthographicCamera_SetLeft : Set the left field.
1112 //-----------------------------------------------------------------------------
1113 TQ3Status
SetLeft(float Left)1114 E3OrthographicCamera::SetLeft ( float Left )
1115 {
1116 // Set the field
1117 left = Left ;
1118
1119 Q3Shared_Edited ( this ) ;
1120
1121 return kQ3Success ;
1122 }
1123
1124
1125
1126
1127
1128 //=============================================================================
1129 // E3OrthographicCamera_GetLeft : Return the left field.
1130 //-----------------------------------------------------------------------------
1131 TQ3Status
GetLeft(float * Left)1132 E3OrthographicCamera::GetLeft ( float *Left )
1133 {
1134 // Return the field
1135 *Left = left ;
1136
1137 return kQ3Success ;
1138 }
1139
1140
1141
1142
1143
1144 //=============================================================================
1145 // E3OrthographicCamera_SetTop : Set the top field.
1146 //-----------------------------------------------------------------------------
1147 TQ3Status
SetTop(float Top)1148 E3OrthographicCamera::SetTop ( float Top)
1149 {
1150 // Set the field
1151 top = Top ;
1152
1153 Q3Shared_Edited ( this ) ;
1154
1155 return kQ3Success ;
1156 }
1157
1158
1159
1160
1161
1162 //=============================================================================
1163 // E3OrthographicCamera_GetTop : Return the top field.
1164 //-----------------------------------------------------------------------------
1165 TQ3Status
GetTop(float * Top)1166 E3OrthographicCamera::GetTop ( float *Top )
1167 {
1168 // Return the field
1169 *Top = top ;
1170
1171 return kQ3Success ;
1172 }
1173
1174
1175
1176
1177
1178 //=============================================================================
1179 // E3OrthographicCamera_SetRight : Set the right field.
1180 //-----------------------------------------------------------------------------
1181 TQ3Status
SetRight(float Right)1182 E3OrthographicCamera::SetRight ( float Right )
1183 {
1184 // Set the field
1185 right = Right ;
1186
1187 Q3Shared_Edited ( this ) ;
1188
1189 return kQ3Success ;
1190 }
1191
1192
1193
1194
1195
1196 //=============================================================================
1197 // E3OrthographicCamera_GetRight : Return the right field.
1198 //-----------------------------------------------------------------------------
1199 TQ3Status
GetRight(float * Right)1200 E3OrthographicCamera::GetRight ( float *Right )
1201 {
1202 // Return the field
1203 *Right = right ;
1204
1205 return kQ3Success ;
1206 }
1207
1208
1209
1210
1211
1212 //=============================================================================
1213 // E3OrthographicCamera_SetBottom : Set the bottom field.
1214 //-----------------------------------------------------------------------------
1215 TQ3Status
SetBottom(float Bottom)1216 E3OrthographicCamera::SetBottom ( float Bottom )
1217 {
1218 // Set the field
1219 bottom = Bottom ;
1220
1221 Q3Shared_Edited ( this ) ;
1222
1223 return kQ3Success ;
1224 }
1225
1226
1227
1228
1229
1230 //=============================================================================
1231 // E3OrthographicCamera_GetBottom : Return the bottom field.
1232 //-----------------------------------------------------------------------------
1233 TQ3Status
GetBottom(float * Bottom)1234 E3OrthographicCamera::GetBottom ( float *Bottom )
1235 {
1236 // Return the field
1237 *Bottom = bottom ;
1238
1239 return kQ3Success ;
1240 }
1241
1242
1243
1244
1245
1246 //=============================================================================
1247 // E3ViewPlaneCamera_New : Create a view plane camera.
1248 //-----------------------------------------------------------------------------
1249 #pragma mark -
1250 TQ3CameraObject
E3ViewPlaneCamera_New(const TQ3ViewPlaneCameraData * cameraData)1251 E3ViewPlaneCamera_New(const TQ3ViewPlaneCameraData *cameraData)
1252 { TQ3Object theObject;
1253
1254
1255
1256 // Create the object
1257 theObject = E3ClassTree::CreateInstance ( kQ3CameraTypeViewPlane, kQ3False, cameraData);
1258 return(theObject);
1259 }
1260
1261
1262
1263
1264
1265 //=============================================================================
1266 // E3ViewPlaneCamera_GetData : Return a view plane camera's data.
1267 //-----------------------------------------------------------------------------
1268 TQ3Status
GetData(TQ3ViewPlaneCameraData * CameraData)1269 E3ViewPlaneCamera::GetData ( TQ3ViewPlaneCameraData *CameraData)
1270 {
1271 // Return the camera's data
1272 *CameraData = * ( (TQ3ViewPlaneCameraData*) &cameraData ) ;
1273
1274 return kQ3Success ;
1275 }
1276
1277
1278
1279
1280
1281 //=============================================================================
1282 // E3ViewPlaneCamera_SetData : Set the data for a view plane camera.
1283 //-----------------------------------------------------------------------------
1284 TQ3Status
SetData(const TQ3ViewPlaneCameraData * CameraData)1285 E3ViewPlaneCamera::SetData ( const TQ3ViewPlaneCameraData *CameraData )
1286 {
1287 // Set the camera's data
1288 * ( (TQ3ViewPlaneCameraData*) &cameraData ) = *CameraData;
1289
1290 Q3Shared_Edited ( this ) ;
1291
1292 return kQ3Success ;
1293 }
1294
1295
1296
1297
1298
1299 //=============================================================================
1300 // E3ViewPlaneCamera_SetViewPlane : Set the view plane field.
1301 //-----------------------------------------------------------------------------
1302 TQ3Status
SetViewPlane(float ViewPlane)1303 E3ViewPlaneCamera::SetViewPlane ( float ViewPlane )
1304 {
1305 // Set the field
1306 viewPlane = ViewPlane ;
1307
1308 Q3Shared_Edited ( this ) ;
1309
1310 return kQ3Success ;
1311 }
1312
1313
1314
1315
1316
1317 //=============================================================================
1318 // E3ViewPlaneCamera_GetViewPlane : Return the view plane field.
1319 //-----------------------------------------------------------------------------
1320 TQ3Status
GetViewPlane(float * ViewPlane)1321 E3ViewPlaneCamera::GetViewPlane ( float *ViewPlane )
1322 {
1323 // Return the field
1324 *ViewPlane = viewPlane ;
1325
1326 return kQ3Success ;
1327 }
1328
1329
1330
1331
1332
1333 //=============================================================================
1334 // E3ViewPlaneCamera_SetHalfWidth : Set the half width field.
1335 //-----------------------------------------------------------------------------
1336 TQ3Status
SetHalfWidth(float HalfWidthAtViewPlane)1337 E3ViewPlaneCamera::SetHalfWidth ( float HalfWidthAtViewPlane )
1338 {
1339 // Set the field
1340 halfWidthAtViewPlane = HalfWidthAtViewPlane ;
1341
1342 Q3Shared_Edited ( this ) ;
1343
1344 return kQ3Success ;
1345 }
1346
1347
1348
1349
1350
1351 //=============================================================================
1352 // E3ViewPlaneCamera_GetHalfWidth : Return the half width field.
1353 //-----------------------------------------------------------------------------
1354 TQ3Status
GetHalfWidth(float * HalfWidthAtViewPlane)1355 E3ViewPlaneCamera::GetHalfWidth ( float *HalfWidthAtViewPlane )
1356 {
1357 // Return the field
1358 *HalfWidthAtViewPlane = halfWidthAtViewPlane ;
1359
1360 return kQ3Success ;
1361 }
1362
1363
1364
1365
1366
1367 //=============================================================================
1368 // E3ViewPlaneCamera_SetHalfHeight : Set the half height field.
1369 //-----------------------------------------------------------------------------
1370 TQ3Status
SetHalfHeight(float HalfHeightAtViewPlane)1371 E3ViewPlaneCamera::SetHalfHeight ( float HalfHeightAtViewPlane )
1372 {
1373 // Set the field
1374 halfHeightAtViewPlane = HalfHeightAtViewPlane ;
1375
1376 Q3Shared_Edited ( this ) ;
1377
1378 return kQ3Success ;
1379 }
1380
1381
1382
1383
1384
1385 //=============================================================================
1386 // E3ViewPlaneCamera_GetHalfHeight : Return the half height field.
1387 //-----------------------------------------------------------------------------
1388 TQ3Status
GetHalfHeight(float * HalfHeightAtViewPlane)1389 E3ViewPlaneCamera::GetHalfHeight ( float *HalfHeightAtViewPlane )
1390 {
1391 // Return the field
1392 *HalfHeightAtViewPlane = halfHeightAtViewPlane ;
1393
1394 return kQ3Success ;
1395 }
1396
1397
1398
1399
1400
1401 //=============================================================================
1402 // E3ViewPlaneCamera_SetCenterX : Set the center X field.
1403 //-----------------------------------------------------------------------------
1404 TQ3Status
SetCenterX(float CenterXOnViewPlane)1405 E3ViewPlaneCamera::SetCenterX ( float CenterXOnViewPlane )
1406 {
1407 // Set the field
1408 centerXOnViewPlane = CenterXOnViewPlane ;
1409
1410 Q3Shared_Edited ( this ) ;
1411
1412 return kQ3Success ;
1413 }
1414
1415
1416
1417
1418
1419 //=============================================================================
1420 // E3ViewPlaneCamera_GetCenterX : Return the center X field.
1421 //-----------------------------------------------------------------------------
1422 TQ3Status
GetCenterX(float * CenterXOnViewPlane)1423 E3ViewPlaneCamera::GetCenterX ( float *CenterXOnViewPlane )
1424 {
1425 // Return the field
1426 *CenterXOnViewPlane = centerXOnViewPlane ;
1427
1428 return kQ3Success ;
1429 }
1430
1431
1432
1433
1434
1435 //=============================================================================
1436 // E3ViewPlaneCamera_SetCenterY : Set the center Y field.
1437 //-----------------------------------------------------------------------------
1438 TQ3Status
SetCenterY(float CenterYOnViewPlane)1439 E3ViewPlaneCamera::SetCenterY ( float CenterYOnViewPlane )
1440 {
1441 // Set the field
1442 centerYOnViewPlane = CenterYOnViewPlane ;
1443
1444 Q3Shared_Edited ( this ) ;
1445
1446 return kQ3Success ;
1447 }
1448
1449
1450
1451
1452
1453 //=============================================================================
1454 // E3ViewPlaneCamera_GetCenterY : Return the center Y field.
1455 //-----------------------------------------------------------------------------
1456 TQ3Status
GetCenterY(float * CenterYOnViewPlane)1457 E3ViewPlaneCamera::GetCenterY ( float *CenterYOnViewPlane )
1458 {
1459 // Return the field
1460 *CenterYOnViewPlane = centerYOnViewPlane ;
1461
1462 return kQ3Success ;
1463 }
1464
1465
1466
1467
1468
1469 //=============================================================================
1470 // E3ViewAngleAspectCamera_New : Create a view angle camera.
1471 //-----------------------------------------------------------------------------
1472 #pragma mark -
1473 TQ3CameraObject
E3ViewAngleAspectCamera_New(const TQ3ViewAngleAspectCameraData * cameraData)1474 E3ViewAngleAspectCamera_New(const TQ3ViewAngleAspectCameraData *cameraData)
1475 { TQ3Object theObject;
1476
1477
1478
1479 // Create the object
1480 theObject = E3ClassTree::CreateInstance ( kQ3CameraTypeViewAngleAspect, kQ3False, cameraData);
1481 return(theObject);
1482 }
1483
1484
1485
1486
1487
1488 //=============================================================================
1489 // E3ViewAngleAspectCamera_SetData : Set the data for a view angle camera.
1490 //-----------------------------------------------------------------------------
1491 TQ3Status
SetData(const TQ3ViewAngleAspectCameraData * CameraData)1492 E3ViewAngleAspectCamera::SetData ( const TQ3ViewAngleAspectCameraData *CameraData )
1493 {
1494 // Set the camera's data
1495 * ( (TQ3ViewAngleAspectCameraData*) &cameraData ) = *CameraData ;
1496
1497 Q3Shared_Edited ( this ) ;
1498
1499 return kQ3Success ;
1500 }
1501
1502
1503
1504
1505
1506 //=============================================================================
1507 // E3ViewAngleAspectCamera_GetData : Return a view angle camera.
1508 //-----------------------------------------------------------------------------
1509 TQ3Status
GetData(TQ3ViewAngleAspectCameraData * CameraData)1510 E3ViewAngleAspectCamera::GetData ( TQ3ViewAngleAspectCameraData *CameraData )
1511 {
1512 // Return the camera's data
1513 *CameraData = * ( (TQ3ViewAngleAspectCameraData*) &cameraData ) ;
1514
1515 return kQ3Success ;
1516 }
1517
1518
1519
1520
1521
1522 //=============================================================================
1523 // E3ViewAngleAspectCamera_SetFOV : Set the FOV field.
1524 //-----------------------------------------------------------------------------
1525 TQ3Status
SetFOV(float Fov)1526 E3ViewAngleAspectCamera::SetFOV ( float Fov )
1527 {
1528 // Set the field
1529 fov = Fov ;
1530
1531 Q3Shared_Edited ( this ) ;
1532
1533 return kQ3Success ;
1534 }
1535
1536
1537
1538
1539
1540 //=============================================================================
1541 // E3ViewAngleAspectCamera_GetFOV : Return the FOV field.
1542 //-----------------------------------------------------------------------------
1543 TQ3Status
GetFOV(float * Fov)1544 E3ViewAngleAspectCamera::GetFOV ( float *Fov )
1545 {
1546 // Return the field
1547 *Fov = fov ;
1548
1549 return kQ3Success ;
1550 }
1551
1552
1553
1554
1555
1556 //=============================================================================
1557 // E3ViewAngleAspectCamera_SetAspectRatio : Set the aspect ratio field.
1558 //-----------------------------------------------------------------------------
1559 TQ3Status
SetAspectRatio(float AspectRatioXToY)1560 E3ViewAngleAspectCamera::SetAspectRatio ( float AspectRatioXToY )
1561 {
1562 // Set the field
1563 aspectRatioXToY = AspectRatioXToY ;
1564
1565 Q3Shared_Edited ( this ) ;
1566
1567 return kQ3Success ;
1568 }
1569
1570
1571
1572
1573
1574 //=============================================================================
1575 // E3ViewAngleAspectCamera_GetAspectRatio : Return the aspect ratio field.
1576 //-----------------------------------------------------------------------------
1577 TQ3Status
GetAspectRatio(float * AspectRatioXToY)1578 E3ViewAngleAspectCamera::GetAspectRatio ( float *AspectRatioXToY )
1579 {
1580 // Return the field
1581 *AspectRatioXToY = aspectRatioXToY ;
1582
1583 return kQ3Success ;
1584 }
1585
1586
1587
1588
1589
1590