Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
colboxsave.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 : Max2W3d *
24 * *
25 * $Archive:: /Commando/Code/Tools/max2w3d/colboxsave.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 12/06/00 4:06p $*
30 * *
31 * $Revision:: 7 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#include "colboxsave.h"
39#include "w3d_file.h"
40#include "util.h"
41#include "w3dappdata.h"
42#include "errclass.h"
43
44
46(
47 char * mesh_name,
48 char * container_name,
49 INode * inode,
50 Matrix3 & exportspace,
51 TimeValue curtime,
53)
54{
56 // wrestle the mesh out of 3dsMAX
58 Object * obj = inode->EvalWorldState(curtime).obj;
59 TriObject * tri = (TriObject *)obj->ConvertToType(curtime, triObjectClassID);
60 Mesh mesh = tri->mesh;
61 DWORD wirecolor = inode->GetWireColor();
62
63 if (mesh.getNumVerts() == 0) {
64 throw ErrorClass("Mesh %s has no vertices!\n",mesh_name);
65 }
66
68 // Generate the AABox or OBBox data.
70 memset(&BoxData,0,sizeof(BoxData));
71
72 BoxData.Version = W3D_BOX_CURRENT_VERSION;
73 if ((container_name != NULL) && (strlen(container_name) > 0)) {
74 strcpy(BoxData.Name,container_name);
75 strcat(BoxData.Name,".");
76 }
77 strcat(BoxData.Name,mesh_name);
78
79 BoxData.Attributes = 0;
80 if (Is_Collision_AABox(inode)) {
81 BoxData.Attributes |= W3D_BOX_ATTRIBUTE_ALIGNED;
82 } else {
83 BoxData.Attributes |= W3D_BOX_ATTRIBUTE_ORIENTED;
84 }
85 if (Is_Physical_Collision(inode)) {
87 }
88 if (Is_Projectile_Collision(inode)) {
90 }
91 if (Is_Vis_Collision(inode)) {
92 BoxData.Attributes |= W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VIS;
93 }
94 if (Is_Camera_Collision(inode)) {
95 BoxData.Attributes |= W3D_BOX_ATTRIBTUE_COLLISION_TYPE_CAMERA;
96 }
97 if (Is_Vehicle_Collision(inode)) {
98 BoxData.Attributes |= W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VEHICLE;
99 }
100
101 BoxData.Color.R = GetRValue(wirecolor);
102 BoxData.Color.G = GetGValue(wirecolor);
103 BoxData.Color.B = GetBValue(wirecolor);
104
105 // if this is an axis-aligned box, then use the world coord system
106 if (Is_Collision_AABox(inode)) {
107 exportspace.NoRot();
108 }
109
110 // Transform the mesh into the desired coordinate system
111 Matrix3 node_matrix = inode->GetObjectTM(curtime);
112 Matrix3 offset_matrix = node_matrix * Inverse(exportspace);
113 int ivert;
114
115 for (ivert = 0; ivert < mesh.getNumVerts (); ++ivert) {
116 mesh.verts[ivert] = mesh.verts[ivert] * offset_matrix;
117 }
118
119 // Find the center and extent of the box.
120 Point3 min_point = mesh.verts[0];
121 Point3 max_point = mesh.verts[1];
122
123 for (ivert=0; ivert < mesh.getNumVerts(); ++ivert) {
124 if (mesh.verts[ivert].x < min_point.x) min_point.x = mesh.verts[ivert].x;
125 if (mesh.verts[ivert].y < min_point.y) min_point.y = mesh.verts[ivert].y;
126 if (mesh.verts[ivert].z < min_point.z) min_point.z = mesh.verts[ivert].z;
127
128 if (mesh.verts[ivert].x > max_point.x) max_point.x = mesh.verts[ivert].x;
129 if (mesh.verts[ivert].y > max_point.y) max_point.y = mesh.verts[ivert].y;
130 if (mesh.verts[ivert].z > max_point.z) max_point.z = mesh.verts[ivert].z;
131 }
132
133 Point3 center = (max_point + min_point) / 2.0f;
134 Point3 extent = (max_point - min_point) / 2.0f;
135
136 BoxData.Center.X = center.x;
137 BoxData.Center.Y = center.y;
138 BoxData.Center.Z = center.z;
139
140 BoxData.Extent.X = extent.x;
141 BoxData.Extent.Y = extent.y;
142 BoxData.Extent.Z = extent.z;
143}
144
145
146
148{
150 csave.Write(&BoxData,sizeof(BoxData));
151 csave.End_Chunk();
152 return 0;
153}
154
155
156
#define NULL
Definition BaseType.h:92
#define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PHYSICAL
Definition w3d_file.h:2091
#define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_PROJECTILE
Definition w3d_file.h:2092
#define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VIS
Definition w3d_file.h:2093
@ W3D_CHUNK_BOX
Definition w3d_file.h:473
#define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_CAMERA
Definition w3d_file.h:2094
#define W3D_BOX_ATTRIBTUE_COLLISION_TYPE_VEHICLE
Definition w3d_file.h:2095
#define W3D_BOX_ATTRIBUTE_ALIGNED
Definition w3d_file.h:2088
#define W3D_BOX_ATTRIBUTE_ORIENTED
Definition w3d_file.h:2087
#define W3D_BOX_CURRENT_VERSION
Definition w3d_file.h:2085
unsigned long DWORD
Definition bittype.h:57
uint32 Write(const void *buf, uint32 nbytes)
Definition chunkio.cpp:264
bool Begin_Chunk(uint32 id)
Definition chunkio.cpp:108
bool End_Chunk()
Definition chunkio.cpp:148
CollisionBoxSaveClass(char *mesh_name, char *container_name, INode *inode, Matrix3 &exportspace, TimeValue curtime, Progress_Meter_Class &meter)
int Write_To_File(ChunkSaveClass &csave)
WWINLINE Quaternion Inverse(const Quaternion &a)
Definition quat.h:117
bool Is_Projectile_Collision(INode *node)
bool Is_Collision_AABox(INode *node)
bool Is_Vis_Collision(INode *node)
bool Is_Camera_Collision(INode *node)
bool Is_Physical_Collision(INode *node)
bool Is_Vehicle_Collision(INode *node)