Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
camera.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WW3D *
24 * *
25 * $Archive:: /Commando/Code/ww3d2/camera.cpp $*
26 * *
27 * Org Author:: Greg_h *
28 * *
29 * $Author:: Kenny Mitchell *
30 * *
31 * $Modtime:: 06/26/02 4:04p $*
32 * *
33 * $Revision:: 24 $*
34 * *
35 * 06/26/02 KM Matrix name change to avoid MAX conflicts *
36 *---------------------------------------------------------------------------------------------*
37 * Functions: *
38 * CameraClass::CameraClass -- constructor *
39 * CameraClass::CameraClass -- copy constructor *
40 * CameraClass::operator == -- assignment operator *
41 * CameraClass::~CameraClass -- destructor *
42 * CameraClass::Clone -- virtual copy constructor *
43 * CameraClass::Add -- add the camera to the world? *
44 * CameraClass::Remove -- Remove the camera from the world? *
45 * CameraClass::Get_Obj_Space_Bounding_Sphere -- returns the object space bounding sphere *
46 * CameraClass::Get_Object_Space_Bounding_Box -- returns the object space bounding box *
47 * CameraClass::Set_Transform -- set the transform of the camera *
48 * CameraClass::Set_Position -- Set the position of the camera *
49 * CameraClass::Set_Animation -- set the animation state of the camera *
50 * CameraClass::Set_Animation -- Set the animation state of the camera *
51 * CameraClass::Set_Animation -- set the animation state of the camera *
52 * CameraClass::Set_Animation -- set the animation state of the camera *
53 * CameraClass::Set_View_Plane -- control over the view plane *
54 * CameraClass::Set_View_Plane -- set the viewplane using fov angles *
55 * CameraClass::Set_Focal_Length -- set the view plane using focal length and aspect ratio *
56 * CameraClass::Get_View_Plane -- get the corners of the current view plane *
57 * CameraClass::Project -- project a point from ws to the view plane *
58 * CameraClass::Project_Camera_Space_Point -- Project a point that is already in camera spac *
59 * CameraClass::Un_Project -- "unproject" a point from the view plane to world space *
60 * CameraClass::Transform_To_View_Space -- transforms the given world space point to camera *
61 * CameraClass::Rotate_To_View_Space -- rotates the given world space vector to camera space *
62 * CameraClass::Get_Near_Clip_Bounding_Box -- returns an obb that contains near clip plane *
63 * CameraCLass::Update_Frustum -- updates the frustum parameters *
64 * CameraClass::Cull_Box -- tests whether the given box can be culled *
65 * CameraClass::Device_To_View_Space -- converts the given device coordinate to view space *
66 * CameraClass::Device_To_World_Space -- converts given device coord to world space *
67 * CameraClass::Camera_Push -- pushes the camera's parameters into the given GERD *
68 * CameraClass::Camera_Pop -- pops the camera's parameters from the given GERD *
69 * CameraClass::Set_Aspect_Ratio -- sets the aspect ratio of the camera *
70 * CameraClass::Apply_D3D_State -- sets the D3D states controlled by the camera *
71 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
72
73
74#include "camera.h"
75#include "ww3d.h"
76#include "matrix4.h"
77#include "dx8wrapper.h"
78
79
80/***********************************************************************************************
81 * CameraClass::CameraClass -- constructor *
82 * *
83 * INPUT: *
84 * *
85 * OUTPUT: *
86 * *
87 * WARNINGS: *
88 * *
89 * HISTORY: *
90 * 3/21/98 GTH : Created. *
91 *=============================================================================================*/
94 Viewport(Vector2(0,0),Vector2(1,1)), // pixel viewport to render into
95 AspectRatio(4.0f/3.0f),
96 ZNear(1.0f), // near clip plane distance
97 ZFar(1000.0f), // far clip plane distance
98 ZBufferMin(0.0f), // smallest value we'll write into the z-buffer
99 ZBufferMax(1.0f), // largest value we'll write into the z-buffer
101{
104}
105
106
107/***********************************************************************************************
108 * CameraClass::CameraClass -- copy constructor *
109 * *
110 * INPUT: *
111 * *
112 * OUTPUT: *
113 * *
114 * WARNINGS: *
115 * *
116 * HISTORY: *
117 * 3/21/98 GTH : Created. *
118 * 4/13/2001 hy : added in copy code for new member functions *
119 *=============================================================================================*/
121 RenderObjClass(src),
123 Viewport(src.Viewport),
124 ViewPlane(src.ViewPlane),
125 ZNear(src.ZNear),
126 ZFar(src.ZFar),
128 Frustum(src.Frustum),
135{
136 // just being paraniod in case any parent class doesn't completely copy the entire state...
137 FrustumValid = false;
138}
139
140
141/***********************************************************************************************
142 * CameraClass::operator == -- assignment operator *
143 * *
144 * INPUT: *
145 * *
146 * OUTPUT: *
147 * *
148 * WARNINGS: *
149 * *
150 * HISTORY: *
151 * 3/21/98 GTH : Created. *
152 *=============================================================================================*/
154{
155 if (this != &that) {
157
158 Projection = that.Projection;
159 Viewport = that.Viewport;
160 ViewPlane = that.ViewPlane;
161 ZNear = that.ZNear;
162 ZFar = that.ZFar;
164 Frustum = that.Frustum;
168
169 // just being paraniod in case any parent class doesn't completely copy the entire state...
170 FrustumValid = false;
171 }
172
173 return * this;
174}
175
176
177/***********************************************************************************************
178 * CameraClass::~CameraClass -- destructor *
179 * *
180 * INPUT: *
181 * *
182 * OUTPUT: *
183 * *
184 * WARNINGS: *
185 * *
186 * HISTORY: *
187 * 3/21/98 GTH : Created. *
188 *=============================================================================================*/
192
193
194/***********************************************************************************************
195 * CameraClass::Clone -- virtual copy constructor *
196 * *
197 * INPUT: *
198 * *
199 * OUTPUT: *
200 * *
201 * WARNINGS: *
202 * *
203 * HISTORY: *
204 * 3/21/98 GTH : Created. *
205 *=============================================================================================*/
207{
208 return NEW_REF( CameraClass, (*this) );
209}
210
211
212/***********************************************************************************************
213 * CameraClass::Get_Obj_Space_Bounding_Sphere -- returns the object space bounding sphere *
214 * *
215 * INPUT: *
216 * *
217 * OUTPUT: *
218 * *
219 * WARNINGS: *
220 * *
221 * HISTORY: *
222 * 9/29/98 GTH : Created. *
223 *=============================================================================================*/
225{
226 sphere.Center.Set(0,0,0);
227 sphere.Radius = ZFar; // could optimize this but its not really used.
228}
229
230
231/***********************************************************************************************
232 * CameraClass::Get_Object_Space_Bounding_Box -- returns the object space bounding box *
233 * *
234 * INPUT: *
235 * *
236 * OUTPUT: *
237 * *
238 * WARNINGS: *
239 * *
240 * HISTORY: *
241 * 9/29/98 GTH : Created. *
242 *=============================================================================================*/
244{
245 box.Center.Set(0,0,0);
246 box.Extent.Set(ZFar,ZFar,ZFar); // could optimize this but its not really used.
247}
248
249
250/***********************************************************************************************
251 * CameraClass::Set_Transform -- set the transform of the camera *
252 * *
253 * This is over-ridden to invalidate the cached frustum parameters *
254 * *
255 * INPUT: *
256 * *
257 * OUTPUT: *
258 * *
259 * WARNINGS: *
260 * *
261 * HISTORY: *
262 * 5/29/98 GTH : Created. *
263 *=============================================================================================*/
269
270
271/***********************************************************************************************
272 * CameraClass::Set_Position -- Set the position of the camera *
273 * *
274 * This is overriden to invalidate the cached frustum parameters *
275 * *
276 * INPUT: *
277 * *
278 * OUTPUT: *
279 * *
280 * WARNINGS: *
281 * *
282 * HISTORY: *
283 * 5/29/98 GTH : Created. *
284 *=============================================================================================*/
290
291
292/***********************************************************************************************
293 * CameraClass::Set_View_Plane -- control over the view plane *
294 * *
295 * INPUT: *
296 * min - x,y of the upper left corner of the view rectangle (dist is assumed to be 1.0) *
297 * max - x,y of the lower right corner of the view rectangle *
298 * *
299 * OUTPUT: *
300 * *
301 * WARNINGS: *
302 * *
303 * HISTORY: *
304 * 3/21/98 GTH : Created. *
305 *=============================================================================================*/
306void CameraClass::Set_View_Plane(const Vector2 & vmin,const Vector2 & vmax)
307{
308 ViewPlane.Min = vmin;
309 ViewPlane.Max = vmax;
310 AspectRatio = (vmax.X - vmin.X) / (vmax.Y - vmin.Y);
311 FrustumValid = false;
312}
313
314
315/***********************************************************************************************
316 * CameraClass::Set_View_Plane -- set the viewplane using fov angles *
317 * *
318 * INPUT: *
319 * *
320 * OUTPUT: *
321 * *
322 * WARNINGS: *
323 * *
324 * HISTORY: *
325 * 3/21/98 GTH : Created. *
326 *=============================================================================================*/
327void CameraClass::Set_View_Plane(float hfov,float vfov)
328{
329
330 float width_half = tan(hfov/2.0);
331 float height_half = 0.0f;
332
333 if (vfov == -1) {
334 height_half = (1.0f / AspectRatio) * width_half; // use the aspect ratio
335 } else {
336 height_half = tan(vfov/2.0);
337 AspectRatio = width_half / height_half; // or, initialize the aspect ratio
338 }
339
340 ViewPlane.Min.Set(-width_half,-height_half);
341 ViewPlane.Max.Set(width_half,height_half);
342
343 FrustumValid = false;
344}
345
346
347/***********************************************************************************************
348 * CameraClass::Set_Aspect_Ratio -- sets the aspect ratio of the camera *
349 * *
350 * INPUT: *
351 * *
352 * OUTPUT: *
353 * *
354 * WARNINGS: *
355 * *
356 * HISTORY: *
357 * 1/29/2001 gth : Created. *
358 *=============================================================================================*/
359void CameraClass::Set_Aspect_Ratio(float width_to_height)
360{
361 AspectRatio = width_to_height;
362 ViewPlane.Min.Y = ViewPlane.Min.X / AspectRatio;
363 ViewPlane.Max.Y = ViewPlane.Max.X / AspectRatio;
364 FrustumValid = false;
365}
366
367
368/***********************************************************************************************
369 * CameraClass::Get_View_Plane -- get the corners of the current view plane *
370 * *
371 * INPUT: *
372 * *
373 * OUTPUT: *
374 * *
375 * WARNINGS: *
376 * *
377 * HISTORY: *
378 * 3/21/98 GTH : Created. *
379 *=============================================================================================*/
380void CameraClass::Get_View_Plane(Vector2 & set_min,Vector2 & set_max) const
381{
382 set_min = ViewPlane.Min;
383 set_max = ViewPlane.Max;
384}
385
386
387/***********************************************************************************************
388 * CameraClass::Project -- project a point from ws to the view plane *
389 * *
390 * INPUT: *
391 * dest - will be set to a point on the normalized view plane. x,y, and z range from -1 to 1 *
392 * ws_point - input point in world space *
393 * *
394 * OUTPUT: *
395 * ProjectionResType indicating whether the point was in the frustum *
396 * *
397 * WARNINGS: *
398 * When the input is behind the near clip plane, 0,0,0 is returned. *
399 * *
400 * HISTORY: *
401 * 3/21/98 GTH : Created. *
402 *=============================================================================================*/
404{
406
407 Vector3 cam_point;
409
410 if (cam_point.Z > -ZNear) {
411 dest.Set(0,0,0);
412 return OUTSIDE_NEAR_CLIP;
413 }
414
415 Vector4 view_point = ProjectionTransform * cam_point;
416 float oow = 1.0f / view_point.W;
417 dest.X = view_point.X * oow;
418 dest.Y = view_point.Y * oow;
419 dest.Z = view_point.Z * oow;
420
421 if (dest.Z > 1.0f) {
422 return OUTSIDE_FAR_CLIP;
423 }
424
425 if ((dest.X < -1.0f) || (dest.X > 1.0f) || (dest.Y < -1.0f) || (dest.Y > 1.0f)) {
426 return OUTSIDE_FRUSTUM;
427 }
428
429 return INSIDE_FRUSTUM;
430}
431
432/***********************************************************************************************
433 * CameraClass::Project_Camera_Space_Point -- Project a point that is already in camera space *
434 * *
435 * INPUT: *
436 * dest - will be set to a point on the normalized view plane. x,y, and z range from -1 to 1 *
437 * cam_point - input point in camera space *
438 * *
439 * OUTPUT: *
440 * ProjectionResType indicating whether the point was in the frustum *
441 * *
442 * WARNINGS: *
443 * When the input is behind the near clip plane, 0,0,0 is returned. *
444 * *
445 * HISTORY: *
446 * 11/17/2000 gth : Created. *
447 *=============================================================================================*/
450{
452
453 if ( cam_point.Z > -ZNear + WWMATH_EPSILON) {
454 dest.Set(0,0,0);
455 return OUTSIDE_NEAR_CLIP;
456 }
457
458 Vector4 view_point = ProjectionTransform * cam_point;
459 float oow = 1.0f / view_point.W;
460 dest.X = view_point.X * oow;
461 dest.Y = view_point.Y * oow;
462 dest.Z = view_point.Z * oow;
463
464 if (dest.Z > 1.0f) {
465 return OUTSIDE_FAR_CLIP;
466 }
467
468 if ((dest.X < -1.0f) || (dest.X > 1.0f) || (dest.Y < -1.0f) || (dest.Y > 1.0f)) {
469 return OUTSIDE_FRUSTUM;
470 }
471
472 return INSIDE_FRUSTUM;
473}
474
475/***********************************************************************************************
476 * CameraClass::Un_Project -- "unproject" a point from the view plane to world space *
477 * *
478 * The given point is assumed to be on the view_plane at z=-1. The 3D world space point that *
479 * this represents will be returned in dest. *
480 * *
481 * INPUT: *
482 * dest - will be filled in with the 3D world space point that the given point represents *
483 * view_point - point on the view_plane to be un-projected *
484 * *
485 * OUTPUT: *
486 * *
487 * WARNINGS: *
488 * *
489 * HISTORY: *
490 * 3/21/98 GTH : Created. *
491 *=============================================================================================*/
492void CameraClass::Un_Project(Vector3 & dest,const Vector2 & view_point) const
493{
494 /*
495 ** map view_point.X from -1..1 to ViewPlaneMin.X..ViewPlaneMax.X
496 ** map view_point.Y from -1..1 to ViewPlaneMin.X..ViewPlaneMax.X
497 */
498 float vpdx = ViewPlane.Max.X - ViewPlane.Min.X;
499 float vpdy = ViewPlane.Max.Y - ViewPlane.Min.Y;
500
501 Vector3 point;
502 point.X = ViewPlane.Min.X + vpdx * (view_point.X + 1.0f) * 0.5f;
503 point.Y = ViewPlane.Min.Y + vpdy * (view_point.Y + 1.0f) * 0.5f;
504 point.Z = -1.0f;
505
507}
508
509
510/***********************************************************************************************
511 * CameraClass::Transform_To_View_Space -- transforms the given world space point to camera sp *
512 * *
513 * INPUT: *
514 * *
515 * OUTPUT: *
516 * *
517 * WARNINGS: *
518 * *
519 * HISTORY: *
520 * 2/22/2001 gth : Created. *
521 *=============================================================================================*/
522void CameraClass::Transform_To_View_Space(Vector3 & dest,const Vector3 & ws_point) const
523{
526}
527
528
529/***********************************************************************************************
530 * CameraClass::Rotate_To_View_Space -- rotates the given world space vector to camera space *
531 * *
532 * INPUT: *
533 * *
534 * OUTPUT: *
535 * *
536 * WARNINGS: *
537 * *
538 * HISTORY: *
539 * 2/22/2001 gth : Created. *
540 *=============================================================================================*/
541void CameraClass::Rotate_To_View_Space(Vector3 & dest,const Vector3 & ws_vector) const
542{
545}
546
547
548
549/***********************************************************************************************
550 * CameraClass::Get_Near_Clip_Bounding_Box -- returns an obb that contains near clip plane *
551 * *
552 * INPUT: *
553 * *
554 * OUTPUT: *
555 * *
556 * WARNINGS: *
557 * *
558 * HISTORY: *
559 * 8/25/99 GTH : Created. *
560 *=============================================================================================*/
562{
564 return NearClipBBox;
565}
566
567
568/***********************************************************************************************
569 * CameraClass::Cull_Box -- tests whether the given box can be culled *
570 * *
571 * INPUT: *
572 * *
573 * OUTPUT: *
574 * *
575 * WARNINGS: *
576 * *
577 * HISTORY: *
578 * 12/8/98 GTH : Created. *
579 *=============================================================================================*/
580bool CameraClass::Cull_Box(const AABoxClass & box) const
581{
582 const FrustumClass & frustum = Get_Frustum();
584}
585
586
587/***********************************************************************************************
588 * CameraClass::Update_Frustum -- updates the frustum parameters *
589 * *
590 * INPUT: *
591 * *
592 * OUTPUT: *
593 * *
594 * WARNINGS: *
595 * *
596 * HISTORY: *
597 * 5/29/98 GTH : Created. *
598 *=============================================================================================*/
600{
601 if (FrustumValid) return;
602
603 Vector2 vpmin,vpmax;
604 float znear,zfar;
605 float znear_dist,zfar_dist;
606
607 Matrix3D cam_mat = Get_Transform();
608 Get_View_Plane(vpmin, vpmax); // Normalized view plane at a depth of 1.0
609 Get_Clip_Planes(znear_dist, zfar_dist);
610
611 // Forward is negative Z in our viewspace coordinate system.
612 znear = -znear_dist;
613 zfar = -zfar_dist;
614
615 // Update the frustum
616 FrustumValid = true;
617 Frustum.Init(cam_mat,vpmin,vpmax,znear,zfar);
618 ViewSpaceFrustum.Init(Matrix3D(1),vpmin,vpmax,znear,zfar);
619
620 // Update the OBB around the near clip rectangle
621#ifdef ALLOW_TEMPORARIES
622 NearClipBBox.Center = cam_mat * Vector3(0,0,znear);
623#else
624 cam_mat.mulVector3(Vector3(0,0,znear), NearClipBBox.Center);
625#endif
626 NearClipBBox.Extent.X = (vpmax.X - vpmin.X) * (-znear) * 0.5f; // (near_clip_x / |znear|) == (vpmin.X / 1.0f)...
627 NearClipBBox.Extent.Y = (vpmax.Y - vpmin.Y) * (-znear) * 0.5f;
628 NearClipBBox.Extent.Z = 0.01f;
629 NearClipBBox.Basis.Set(cam_mat);
630
631 // Update the inverse camera matrix
632 Transform.Get_Inverse(CameraInvTransform);
633
634 // Update the projection matrix
635 if (Projection == PERSPECTIVE) {
636
637 ProjectionTransform.Init_Perspective( vpmin.X*znear_dist, vpmax.X*znear_dist,
638 vpmin.Y*znear_dist, vpmax.Y*znear_dist,
639 znear_dist, zfar_dist );
640
641 } else {
642
643 ProjectionTransform.Init_Ortho( vpmin.X,vpmax.X,vpmin.Y,vpmax.Y,znear_dist,zfar_dist);
644
645 }
646}
647
648
649/***********************************************************************************************
650 * CameraClass::Device_To_View_Space -- converts the given device coordinate to view space *
651 * *
652 * INPUT: *
653 * *
654 * OUTPUT: *
655 * *
656 * WARNINGS: *
657 * *
658 * HISTORY: *
659 * 12/8/98 GTH : Created. *
660 *=============================================================================================*/
661void CameraClass::Device_To_View_Space(const Vector2 & device_coord,Vector3 * set_view)
662{
663 int res_width;
664 int res_height;
665 int res_bits;
666 bool windowed;
667
668 WW3D::Get_Render_Target_Resolution(res_width,res_height,res_bits,windowed);
669
670 // convert the device coordinates into normalized device coordinates:
671 Vector2 ndev;
672 ndev.X = device_coord.X / (float)res_width;
673 ndev.Y = device_coord.Y / (float)res_height;
674
675 // view space rectangle which corresponds to the viewport
676 Vector2 vs_min;
677 Vector2 vs_max;
678 Get_View_Plane(vs_min,vs_max);
679
680 // mapping from the viewport coordinates to view space coordinates
681 set_view->X = vs_min.X + (ndev.X - Viewport.Min.X) * (vs_max.X - vs_min.X) / (Viewport.Width());
682 set_view->Y = vs_max.Y - (ndev.Y - Viewport.Min.Y) * (vs_max.Y - vs_min.Y) / (Viewport.Height());
683 set_view->Z = -1.0f;
684}
685
686
687/***********************************************************************************************
688 * CameraClass::Device_To_World_Space -- converts given device coord to world space *
689 * *
690 * INPUT: *
691 * *
692 * OUTPUT: *
693 * *
694 * WARNINGS: *
695 * *
696 * HISTORY: *
697 * 12/8/98 GTH : Created. *
698 *=============================================================================================*/
699void CameraClass::Device_To_World_Space(const Vector2 & device_coord,Vector3 * world_coord)
700{
701 Vector3 vs;
702 Device_To_View_Space(device_coord,&vs);
704}
705
706
707/***********************************************************************************************
708 * CameraClass::Apply -- sets the D3D states controlled by the camera *
709 * *
710 * INPUT: *
711 * *
712 * OUTPUT: *
713 * *
714 * WARNINGS: *
715 * *
716 * HISTORY: *
717 * 1/29/2001 gth : Created. *
718 *=============================================================================================*/
720{
722
723 int width,height,bits;
724 bool windowed;
725 WW3D::Get_Render_Target_Resolution(width,height,bits,windowed);
726
727 D3DVIEWPORT8 vp;
728 vp.X = (DWORD)(Viewport.Min.X * (float)width);
729 vp.Y = (DWORD)(Viewport.Min.Y * (float)height);
730 vp.Width = (DWORD)((Viewport.Max.X - Viewport.Min.X) * (float)width);
731 vp.Height = (DWORD)((Viewport.Max.Y - Viewport.Min.Y) * (float)height);
732 vp.MinZ = ZBufferMin;
733 vp.MaxZ = ZBufferMax;
735
736 Matrix4x4 d3dprojection;
737 Get_D3D_Projection_Matrix(&d3dprojection);
740}
741
742void CameraClass::Set_Clip_Planes(float znear,float zfar)
743{
744 FrustumValid = false;
745 ZNear = znear;
746 ZFar = zfar;
747}
748
749void CameraClass::Get_Clip_Planes(float & znear,float & zfar) const
750{
751 znear = ZNear;
752 zfar = ZFar;
753}
754
756{
757 float width = ViewPlane.Max.X - ViewPlane.Min.X;
758 return 2*WWMath::Atan2(width,2.0);
759}
760
762{
763 float height = ViewPlane.Max.Y - ViewPlane.Min.Y;
764 return 2*WWMath::Atan2(height,2.0);
765}
766
768{
769 return AspectRatio;
770}
771
773{
774 WWASSERT(set_tm != NULL);
775
777 *set_tm = ProjectionTransform;
778}
779
781{
782 WWASSERT(set_tm != NULL);
784 *set_tm = ProjectionTransform;
785
786 /*
787 ** We need to flip the handed-ness of the projection matrix and
788 ** move the z-range to 0<z<1 rather than -1<z<1
789 */
790 float oozdiff = 1.0 / (ZFar - ZNear);
791 if (Projection == PERSPECTIVE) {
792 (*set_tm)[2][2] = -(ZFar) * oozdiff;
793 (*set_tm)[2][3] = -(ZFar*ZNear) * oozdiff;
794 } else {
795 (*set_tm)[2][2] = -oozdiff;
796 (*set_tm)[2][3] = -ZNear * oozdiff;
797 }
798
799}
800
802{
803 WWASSERT(set_tm != NULL);
805 *set_tm = CameraInvTransform;
806}
807
813
819
821{
822 pos.X=(pos.X+1)/2;
823 pos.Y=(pos.Y+1)/2;
824}
825
827{
828 Vector4 result = ProjectionTransform * Vector4(radius,0.0f,dist,1.0f);
829 return result.X / result.W;
830}
#define NULL
Definition BaseType.h:92
#define WWASSERT
unsigned long DWORD
Definition bittype.h:57
@ false
Definition bool.h:59
#define WWMATH_EPSILON
Definition wwmath.h:54
#define DEG_TO_RADF(x)
Definition wwmath.h:87
Vector3 Center
Definition aabox.h:123
Vector3 Extent
Definition aabox.h:124
virtual ~CameraClass(void)
Definition camera.cpp:189
virtual void Set_Position(const Vector3 &v)
Definition camera.cpp:285
const Matrix3D & Get_View_Matrix(void)
Definition camera.cpp:814
float Compute_Projected_Sphere_Radius(float dist, float radius)
Definition camera.cpp:826
void Apply(void)
Definition camera.cpp:719
void Device_To_World_Space(const Vector2 &device_coord, Vector3 *world_coord)
Definition camera.cpp:699
@ PERSPECTIVE
Definition camera.h:113
void Set_Aspect_Ratio(float width_to_height)
Definition camera.cpp:359
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition camera.cpp:243
void Set_Clip_Planes(float znear, float zfar)
Definition camera.cpp:742
float ZNear
Definition camera.h:245
void Get_View_Plane(Vector2 &set_min, Vector2 &set_max) const
Definition camera.cpp:380
ProjectionResType Project(Vector3 &dest, const Vector3 &ws_point) const
Definition camera.cpp:403
float ZBufferMin
Definition camera.h:247
Matrix4x4 ProjectionTransform
Definition camera.h:254
void Rotate_To_View_Space(Vector3 &dest, const Vector3 &ws_vector) const
Definition camera.cpp:541
virtual RenderObjClass * Clone(void) const
Definition camera.cpp:206
CameraClass(void)
Definition camera.cpp:92
bool Cull_Box(const AABoxClass &box) const
Definition camera.cpp:580
CameraClass & operator=(const CameraClass &)
Definition camera.cpp:153
ViewportClass ViewPlane
Definition camera.h:243
const OBBoxClass & Get_Near_Clip_Bounding_Box(void) const
Definition camera.cpp:561
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition camera.cpp:224
ViewportClass Viewport
Definition camera.h:242
ProjectionResType
Definition camera.h:118
@ OUTSIDE_FRUSTUM
Definition camera.h:120
@ OUTSIDE_FAR_CLIP
Definition camera.h:122
@ OUTSIDE_NEAR_CLIP
Definition camera.h:121
@ INSIDE_FRUSTUM
Definition camera.h:119
void Set_View_Plane(const Vector2 &min, const Vector2 &max)
Definition camera.cpp:306
void Un_Project(Vector3 &dest, const Vector2 &view_point) const
Definition camera.cpp:492
bool FrustumValid
Definition camera.h:250
float Get_Horizontal_FOV(void) const
Definition camera.cpp:755
void Get_Clip_Planes(float &znear, float &zfar) const
Definition camera.cpp:749
OBBoxClass NearClipBBox
Definition camera.h:253
float ZBufferMax
Definition camera.h:248
FrustumClass Frustum
Definition camera.h:251
virtual void Set_Transform(const Matrix3D &m)
Definition camera.cpp:264
Matrix3D CameraInvTransform
Definition camera.h:255
static void Convert_Old(Vector3 &pos)
Definition camera.cpp:820
const FrustumClass & Get_Frustum(void) const
Definition camera.h:339
void Transform_To_View_Space(Vector3 &dest, const Vector3 &ws_point) const
Definition camera.cpp:522
void Device_To_View_Space(const Vector2 &device_coord, Vector3 *view_coord)
Definition camera.cpp:661
const Matrix4x4 & Get_Projection_Matrix(void)
Definition camera.cpp:808
void Get_D3D_Projection_Matrix(Matrix4x4 *set_tm)
Definition camera.cpp:780
float AspectRatio
Definition camera.h:244
ProjectionType Projection
Definition camera.h:241
FrustumClass ViewSpaceFrustum
Definition camera.h:252
float ZFar
Definition camera.h:246
void Update_Frustum(void) const
Definition camera.cpp:599
float Get_Aspect_Ratio(void) const
Definition camera.cpp:767
ProjectionResType Project_Camera_Space_Point(Vector3 &dest, const Vector3 &cam_point) const
Definition camera.cpp:449
float Get_Vertical_FOV(void) const
Definition camera.cpp:761
static OverlapType Overlap_Test(const AAPlaneClass &plane, const Vector3 &point)
static void Set_Projection_Transform_With_Z_Bias(const Matrix4x4 &matrix, float znear, float zfar)
static void Set_Viewport(CONST D3DVIEWPORT8 *pViewport)
static void Set_Transform(D3DTRANSFORMSTATETYPE transform, const Matrix4x4 &m)
Vector3 Rotate_Vector(const Vector3 &vect) const
Definition matrix3d.cpp:300
void mulVector3(const Vector3 &in, Vector3 &out) const
Definition matrix3d.h:1650
static WWINLINE void Transform_Vector(const Matrix3D &tm, const Vector3 &in, Vector3 *out)
Definition matrix3d.h:1742
virtual void Set_Transform(const Matrix3D &m)
Definition rendobj.cpp:423
RenderObjClass(void)
Definition rendobj.cpp:170
virtual void Set_Position(const Vector3 &v)
Definition rendobj.cpp:444
RenderObjClass & operator=(const RenderObjClass &)
Definition rendobj.cpp:232
const Matrix3D & Get_Transform(void) const
Definition rendobj.h:617
Matrix3D Transform
Definition rendobj.h:549
float Radius
Definition sphere.h:91
Vector3 Center
Definition sphere.h:90
float Y
Definition vector2.h:79
float X
Definition vector2.h:74
float X
Definition vector3.h:90
float Z
Definition vector3.h:92
float Y
Definition vector3.h:91
WWINLINE void Set(float x, float y, float z)
Definition vector3.h:103
float Y
Definition vector4.h:67
float Z
Definition vector4.h:68
float X
Definition vector4.h:66
float W
Definition vector4.h:69
static void Get_Render_Target_Resolution(int &set_w, int &set_h, int &get_bits, bool &get_windowed)
Definition ww3d.cpp:651
static float Atan2(float y, float x)
Definition wwmath.h:150
#define NEW_REF(C, P)
Definition refcount.h:62