13 {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}};
16int g_planePointIndexMap[18] = {0, 1, 5, 6, 2, 3, 3, 0, 4, 1, 2, 6, 0, 3, 2, 4, 5, 6};
39 : scene(scene), flags(c_bit1 | c_bit2 | c_bit3 | c_bit4)
42 prev_render_time = 0.09;
52 memset(transformed_points, 0,
sizeof(transformed_points));
53 seconds_allowed = 1.0;
66 const Vector3* box[] = {&p_bounding_box.
Min(), &p_bounding_box.
Max()};
71 for (i = 0; i < 8; i++) {
72 for (j = 0; j < 3; j++) {
77 for (i = 0; i < 6; i++) {
78 for (k = 0; k < 8; k++) {
79 if (frustum_planes[i][0] * und[k][0] + frustum_planes[i][2] * und[k][2] + frustum_planes[i][1] * und[k][1] +
80 frustum_planes[i][3] >=
97 for (CompoundObject::iterator it = rois.begin(); it != rois.end(); it++) {
108 for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) {
109 if (((
ViewROI*) *it)->GetUnknown0xe0() >= 0) {
124 for (CompoundObject::iterator it = rois.begin(); it != rois.end(); it++) {
128 rois.erase(rois.begin(), rois.end());
139 for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) {
157 if (unk0xe0 == p_und) {
179 if (meshBuilder !=
NULL) {
180 group->
Remove(meshBuilder);
190 if (meshBuilder !=
NULL) {
191 group->
Add(meshBuilder);
212 if (meshBuilder !=
NULL) {
213 roiGeometry->
Remove(meshBuilder);
216 scene->
Remove(roiGeometry);
255 for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) {
260 else if (comp ==
NULL) {
269 for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) {
282 prev_render_time = p_previousRenderTime;
288 else if (flags &
c_bit2) {
292 for (CompoundObject::iterator it = rois.begin(); it != rois.end(); it++) {
304 if (height == 0.0F || front == 0.0F) {
308 float fVar7 = tan(view_angle / 2.0F);
309 view_area_at_one = view_angle * view_angle * 4.0F;
311 float fVar1 = front * fVar7;
312 float fVar2 = (width / height) * fVar1;
314 float fVar3 = back + front;
315 float fVar4 = fVar3 / front;
316 float fVar5 = fVar4 * fVar1;
317 fVar4 = fVar4 * fVar2;
319 float* frustumVertices = (
float*) this->frustum_vertices;
322 *frustumVertices = fVar2; frustumVertices++;
323 *frustumVertices = fVar1; frustumVertices++;
324 *frustumVertices = uVar6; frustumVertices++;
325 *frustumVertices = fVar2; frustumVertices++;
326 *frustumVertices = -fVar1; frustumVertices++;
327 *frustumVertices = uVar6; frustumVertices++;
328 *frustumVertices = -fVar2; frustumVertices++;
329 *frustumVertices = -fVar1; frustumVertices++;
330 *frustumVertices = uVar6; frustumVertices++;
331 *frustumVertices = -fVar2; frustumVertices++;
332 *frustumVertices = fVar1; frustumVertices++;
333 *frustumVertices = uVar6; frustumVertices++;
334 *frustumVertices = fVar4; frustumVertices++;
335 *frustumVertices = fVar5; frustumVertices++;
336 *frustumVertices = fVar3; frustumVertices++;
337 *frustumVertices = fVar4; frustumVertices++;
338 *frustumVertices = -fVar5; frustumVertices++;
339 *frustumVertices = fVar3; frustumVertices++;
340 *frustumVertices = -fVar4; frustumVertices++;
341 *frustumVertices = -fVar5; frustumVertices++;
342 *frustumVertices = fVar3; frustumVertices++;
343 *frustumVertices = -fVar4; frustumVertices++;
344 *frustumVertices = fVar5; frustumVertices++;
345 *frustumVertices = fVar3;
369 for (i = p_und2; result < g_maxLODLevels && p_und1 >= i; i *=
g_LODScaleFactor) {
380 if (lods !=
NULL && lods->
Size() > 0) {
391 for (CompoundObject::const_iterator it = comp->begin(); !(it == comp->end()); it++) {
394 if (lods !=
NULL && lods->
Size() > 0) {
395 if (((
ViewLOD*) ((
ViewROI*) *it)->GetLOD(0))->GetUnknown0x08Test8()) {
414 for (i = 0; i < 8; i++) {
415 for (j = 0; j < 3; j++) {
416 transformed_points[i][j] = pov[3][j];
418 for (k = 0; k < 3; k++) {
419 transformed_points[i][j] += pov[k][j] * frustum_vertices[i][k];
424 for (i = 0; i < 6; i++) {
430 Vector3 normal(frustum_planes[i]);
441 frustum_planes[i][3] = -normal.
Dot(normal, a);
452 this->height = height;
461 view_angle = fov * 0.017453292519944444;
467 if (point_of_view !=
NULL) {
483 float sphere_projected_area = 3.14159265359 * (p_bounding_sphere.
Radius() * p_bounding_sphere.
Radius());
484 float square_dist_to_sphere =
DISTSQRD3(p_bounding_sphere.
Center(), pov[3]);
485 return sphere_projected_area / view_area_at_one / square_dist_to_sphere;
491 LPDIRECT3DRMPICKEDARRAY picked =
NULL;
496 if (d3drm->Pick(x, y, &picked) !=
D3DRM_OK) {
500 if (picked !=
NULL) {
501 if (picked->GetSize() != 0) {
502 LPDIRECT3DRMVISUAL visual;
503 LPDIRECT3DRMFRAMEARRAY frameArray;
506 if (picked->GetPick(0, &visual, &frameArray, &desc) ==
D3DRM_OK) {
507 if (frameArray !=
NULL) {
508 int size = frameArray->GetSize();
511 for (
int i = 1; i < size; i++) {
512 LPDIRECT3DRMFRAME frame =
NULL;
514 if (frameArray->GetElement(i, &frame) ==
D3DRM_OK) {
515 result = (
ViewROI*) frame->GetAppData();
517 if (result !=
NULL) {
528 frameArray->Release();
541 IDirect3DRMFrame2* frame =
NULL;
544 frame->SetAppData(data);
[AI] Represents an axis-aligned bounding box in 3D space, using minimum and maximum points.
const Vector3 & Min() const
[AI] Const accessor for the minimum corner of the bounding box.
const Vector3 & Max() const
[AI] Const accessor for the maximum corner of the bounding box.
[AI] Represents a bounding sphere in 3D space with center and radius.
const float & Radius() const
[AI] Const accessor for the sphere radius.
const Vector3 & Center() const
[AI] Const accessor for the center of the sphere.
[AI] Abstract base class for an ordered list of LODObject pointers, where each entry represents an in...
size_t Size() const
[AI] Returns the current number of LODObject pointers contained.
virtual void SetIdentity()
Sets this matrix to identity (diagonal 1, others 0).
[AI] Represents a 3D point with floating-point precision, inheriting from Vector3.
Measures elapsed wall clock time using high resolution performance counters.
void Stop()
Stops timing and accumulates the elapsed interval to m_elapsedSeconds.
double ElapsedSeconds() const
Returns the total accumulated elapsed time in seconds.
void Start()
Starts (or resumes) timing from the current moment.
[AI] Represents an ROI (Real-time Object Instance) that can be oriented in world space,...
const BoundingSphere & GetWorldBoundingSphere() const override
Returns the object's bounding sphere in world coordinates.
const Matrix4 & GetLocal2World() const
Accessor for the current local-to-world transformation matrix.
unsigned char GetVisibility()
[AI] Returns the visibility flag; true if visible, false if hidden.
const CompoundObject * GetComp() const
[AI] Returns the pointer to the compound object structure, or NULL if not present.
int GetLODCount() const
[AI] Returns the number of available LODs for this ROI.
const LODListBase * GetLODs() const
[AI] Returns the LOD list associated with this ROI, or NULL if not set.
const LODObject * GetLOD(int i) const
[AI] Returns the LODObject at the specified index.
static float GetUserMaxLodPower()
[AI] Returns the cached LOD power, used for faster LOD checks in rendering.
[AI] Implementation of Tgl::Group, wraps a Direct3DRMFrame2 and provides scene graph and transformati...
[AI] Implements Tgl::MeshBuilder; facilitates mesh construction [AI]
[AI] Implementation of Tgl::View backed by Direct3DRMViewport, handles scene rendering,...
const ViewDataType & ImplementationData() const
Gets internal viewport pointer, const [AI].
[AI] Scene graph node for parental transforms/color/material/texture; can hold meshes or other groups...
virtual Result Remove(const Group *)=0
[AI] Removes a child group from this group.
virtual Result Add(const Group *)=0
[AI] Adds a child group to this group.
[AI] Builder class for assembling mesh data and extracting mesh objects.
[AI] Main interface/factory for rendering resources and scene graphs.
[AI] Represents a rendering viewport and drawing context.
virtual float Dot(const float *p_a, const float *p_b) const
[AI] Compute the dot product of the two float arrays interpreted as vectors of 2 elements.
virtual int Unitize()
[AI] Scales the vector so its norm is 1 (unit vector).
[AI] 3D vector class, providing vector and cross-product operations in 3D space.
virtual void EqualsCross(const Vector3 &p_a, const Vector3 &p_b)
[AI] Sets this vector to be the cross product of p_a and p_b.
[AI] Represents a Level of Detail (LOD) object for rendering, implemented with a mesh builder and sup...
@ c_bit4
[AI] Flag value for bit 4 mask operation.
undefined4 GetUnknown0x08()
[AI] Returns the internal flag value m_unk0x08.
Tgl::MeshBuilder * GetMeshBuilder()
[AI] Returns a pointer to the mesh builder associated with this LOD.
[AI] Manages all ViewROI objects that are rendered in a given scene, handles frustum culling,...
void SetFrustrum(float fov, float front, float back)
[AI] Sets the projection frustum parameters and marks the frustum as needing recalculation.
void SetPOVSource(const OrientableROI *point_of_view)
[AI] Sets the OrientableROI to use as the camera's point-of-view; updates the transformation matrix a...
void ManageVisibilityAndDetailRecursively(ViewROI *p_roi, int p_und)
[AI] Recursively traverses and updates the visibility and LOD detail of a ROI and its children,...
@ c_bit1
[AI] Used to signals a pending operation (exact purpose is contextually flagged during update routine...
@ c_bit4
[AI] Signals that the frustum parameters/planes are valid and up to date.
@ c_bit2
[AI] Indicates the need to update view transformation matrices.
@ c_bit3
[AI] Indicates the need to recalculate frustum parameters (e.g., due to a resolution or frustum chang...
ViewROI * Pick(Tgl::View *p_view, unsigned long x, unsigned long y)
[AI] Using a screen coordinate and viewport, finds the ViewROI (if any) under the given coordinates b...
void Update(float p_previousRenderTime, float)
[AI] Performs the per-frame update: applies frustum/view updates if needed and recurses the ROI graph...
ViewManager(Tgl::Renderer *pRenderer, Tgl::Group *scene, const OrientableROI *point_of_view)
[AI] Constructs the ViewManager with the renderer, scene group, and initial point-of-view.
unsigned int IsBoundingBoxInFrustum(const BoundingBox &p_bounding_box)
[AI] Determines if a bounding box is (partially) inside the camera's view frustum using frustum-plane...
void SetResolution(int width, int height)
[AI] Sets the viewport resolution and marks the frustum as needing recalculation.
static int CalculateLODLevel(float p_und1, float p_und2, ViewROI *p_roi)
[AI] Determines the LOD level index for a ROI based on projected size and user-defined/scene paramete...
void Remove(ViewROI *p_roi)
[AI] Removes a single ViewROI from the managed ROI list, also detaching any associated LOD data from ...
void UpdateROIDetailBasedOnLOD(ViewROI *p_roi, int p_und)
[AI] Based on computed LOD, updates the scene to show the correct mesh for a given ROI,...
static int IsROIVisibleAtLOD(ViewROI *p_roi)
[AI] Checks whether the given ROI should be considered visible at any LOD, including compound sub-ROI...
void RemoveROIDetailFromScene(ViewROI *p_roi)
[AI] Removes the currently active LOD detail from the rendering scene for the given ROI and detaches ...
void UpdateViewTransformations()
[AI] Updates the transformation matrices using the current POV and frustum edges, recalculating plane...
float ProjectedSize(const BoundingSphere &p_bounding_sphere)
[AI] Computes the projected area of a bounding sphere onto the camera's viewing plane (used for LOD c...
virtual ~ViewManager()
[AI] Destroys the ViewManager including detaching the current POV source and releasing Direct3DRM obj...
void RemoveAll(ViewROI *p_roi)
[AI] Recursively removes all ViewROI objects.
int CalculateFrustumTransformations()
[AI] Computes frustum planes and transformed corner positions for the current camera/view,...
[AI] ViewROI objects represent viewable and placeable objects in the scene, each holding their own tr...
int GetUnknown0xe0()
[AI] Gets the value of an internal state field at offset 0xe0.
void SetUnknown0xe0(int p_unk0xe0)
[AI] Sets the value of the internal state field at offset 0xe0.
virtual Tgl::Group * GetGeometry()
[AI] Returns a pointer to this ROI's Tgl::Group geometry for rendering and manipulation.
#define DECOMP_SIZE_ASSERT(T, S)
LPVOID LPD3DRM_APPDATA
[AI] Application data type varies by DirectX version [AI]
IDirect3DRM2 * GetD3DRM(Tgl::Renderer *pRenderer)
#define NULL
[AI] Null pointer value (C/C++ semantics).
list< ROI * > CompoundObject
int g_planePointIndexMap[18]
undefined4 GetFrame(IDirect3DRMFrame2 *&frame, Tgl::Group *scene)
int g_boundingBoxCornerMap[8][3]
void SetAppData(ViewROI *p_roi, LPD3DRM_APPDATA data)
undefined4 GetD3DRM(IDirect3DRM2 *&d3drm, Tgl::Renderer *pRenderer)