mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-19 07:51:08 +00:00
[scene] Correct the calculation of world scale
World scale can only be approximate if non-uniform scales and non-orthogonal rotations are involved, but it is still useful information sometimes. However, the calculation is expensive (needs a square root), so remove world scale as a component and instead calculate it on an as-needed basis because it is quite expensive to do for every transform when it is used only by the legacy-GL alias model renderer.
This commit is contained in:
parent
7c4ee70d9e
commit
8e1bf69d5d
2 changed files with 9 additions and 18 deletions
|
@ -55,7 +55,6 @@ enum {
|
|||
transform_type_localRotation,
|
||||
transform_type_localScale,
|
||||
transform_type_worldRotation,
|
||||
transform_type_worldScale,
|
||||
|
||||
transform_type_count
|
||||
};
|
||||
|
@ -321,8 +320,15 @@ Transform_GetWorldScale (transform_t transform)
|
|||
{
|
||||
__auto_type ref = Transform_GetRef (transform);
|
||||
hierarchy_t *h = ref->hierarchy;
|
||||
vec4f_t *worldScale = h->components[transform_type_worldScale];
|
||||
return worldScale[ref->index];
|
||||
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
|
||||
vec4f_t *m = worldMatrix[ref->index];
|
||||
vec4f_t s = {
|
||||
dotf (m[0], m[0])[0],
|
||||
dotf (m[1], m[1])[0],
|
||||
dotf (m[2], m[2])[0],
|
||||
0,
|
||||
};
|
||||
return vsqrt4f (s);
|
||||
}
|
||||
|
||||
XFORMINLINE
|
||||
|
|
|
@ -119,11 +119,6 @@ static const component_t transform_components[transform_type_count] = {
|
|||
.create = transform_rotation_identity,
|
||||
.name = "World Rotation",
|
||||
},
|
||||
[transform_type_worldScale] = {
|
||||
.size = sizeof (vec4f_t),
|
||||
.create = transform_scale_identity,
|
||||
.name = "World Scale",
|
||||
},
|
||||
};
|
||||
|
||||
static const hierarchy_type_t transform_type = {
|
||||
|
@ -166,9 +161,7 @@ Transform_UpdateMatrices (hierarchy_t *h)
|
|||
mat4f_t *worldMatrix = h->components[transform_type_worldMatrix];
|
||||
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
|
||||
vec4f_t *localRotation = h->components[transform_type_localRotation];
|
||||
vec4f_t *localScale = h->components[transform_type_localScale];
|
||||
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
|
||||
vec4f_t *worldScale = h->components[transform_type_worldScale];
|
||||
byte *modified = h->components[transform_type_modified];
|
||||
|
||||
for (uint32_t i = 0; i < h->num_objects; i++) {
|
||||
|
@ -182,7 +175,6 @@ Transform_UpdateMatrices (hierarchy_t *h)
|
|||
memcpy (worldInverse[0],
|
||||
localInverse[0], sizeof (mat4_t));
|
||||
worldRotation[0] = localRotation[0];
|
||||
worldScale[0] = localScale[0];
|
||||
}
|
||||
for (size_t i = 1; i < h->num_objects; i++) {
|
||||
uint32_t parent = h->parentIndex[i];
|
||||
|
@ -208,13 +200,6 @@ Transform_UpdateMatrices (hierarchy_t *h)
|
|||
localRotation[i]);
|
||||
}
|
||||
}
|
||||
for (size_t i = 1; i < h->num_objects; i++) {
|
||||
uint32_t parent = h->parentIndex[i];
|
||||
if (modified[i] || modified[parent]) {
|
||||
worldScale[i] = m3vmulf (worldMatrix[parent],
|
||||
localScale[i]);
|
||||
}
|
||||
}
|
||||
memset (modified, 0, h->num_objects);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue