2021-03-09 02:39:41 +00:00
|
|
|
/*
|
|
|
|
transform.c
|
|
|
|
|
|
|
|
General transform handling
|
|
|
|
|
|
|
|
Copyright (C) 2021 Bill Currke
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2022-02-20 23:33:41 +00:00
|
|
|
#define IMPLEMENT_TRANSFORM_Funcs
|
|
|
|
|
2022-02-14 11:01:36 +00:00
|
|
|
#include "QF/scene/scene.h"
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/transform.h"
|
2021-03-09 02:39:41 +00:00
|
|
|
|
2022-10-09 17:00:33 +00:00
|
|
|
static void
|
|
|
|
transform_mat4f_identity (void *_mat)
|
|
|
|
{
|
|
|
|
vec4f_t *mat = _mat;
|
|
|
|
mat4fidentity (mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
transform_rotation_identity (void *_rot)
|
|
|
|
{
|
|
|
|
vec4f_t *rot = _rot;
|
|
|
|
*rot = (vec4f_t) { 0, 0, 0, 1 };
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
transform_scale_identity (void *_scale)
|
|
|
|
{
|
|
|
|
vec4f_t *scale = _scale;
|
|
|
|
*scale = (vec4f_t) { 1, 1, 1, 1 };
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
transform_modified_init (void *_modified)
|
|
|
|
{
|
|
|
|
byte *modified = _modified;
|
|
|
|
*modified = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const component_t transform_components[transform_type_count] = {
|
|
|
|
[transform_type_name] = {
|
|
|
|
.size = sizeof (char *),
|
|
|
|
.name = "Name",
|
|
|
|
},
|
|
|
|
[transform_type_tag] = {
|
|
|
|
.size = sizeof (uint32_t),
|
|
|
|
.name = "Tag",
|
|
|
|
},
|
|
|
|
[transform_type_modified] = {
|
|
|
|
.size = sizeof (byte),
|
|
|
|
.create = transform_modified_init,
|
|
|
|
.name = "Modified",
|
|
|
|
},
|
|
|
|
[transform_type_localMatrix] = {
|
|
|
|
.size = sizeof (mat4f_t),
|
|
|
|
.create = transform_mat4f_identity,
|
|
|
|
.name = "Local Matrix",
|
|
|
|
},
|
|
|
|
[transform_type_localInverse] = {
|
|
|
|
.size = sizeof (mat4f_t),
|
|
|
|
.create = transform_mat4f_identity,
|
|
|
|
.name = "Local Inverse",
|
|
|
|
},
|
|
|
|
[transform_type_worldMatrix] = {
|
|
|
|
.size = sizeof (mat4f_t),
|
|
|
|
.create = transform_mat4f_identity,
|
|
|
|
.name = "World Matrix",
|
|
|
|
},
|
|
|
|
[transform_type_worldInverse] = {
|
|
|
|
.size = sizeof (mat4f_t),
|
|
|
|
.create = transform_mat4f_identity,
|
|
|
|
.name = "World Inverse",
|
|
|
|
},
|
|
|
|
[transform_type_localRotation] = {
|
|
|
|
.size = sizeof (vec4f_t),
|
|
|
|
.create = transform_rotation_identity,
|
|
|
|
.name = "Local Rotation",
|
|
|
|
},
|
|
|
|
[transform_type_localScale] = {
|
|
|
|
.size = sizeof (vec4f_t),
|
|
|
|
.create = transform_scale_identity,
|
|
|
|
.name = "Local Scale",
|
|
|
|
},
|
|
|
|
[transform_type_worldRotation] = {
|
|
|
|
.size = sizeof (vec4f_t),
|
|
|
|
.create = transform_rotation_identity,
|
|
|
|
.name = "World Rotation",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const hierarchy_type_t transform_type = {
|
|
|
|
.num_components = transform_type_count,
|
|
|
|
.components = transform_components,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
transform_calcLocalInverse (hierarchy_t *h, uint32_t index)
|
|
|
|
{
|
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
mat4f_t *localInverse = h->components[transform_type_localInverse];
|
|
|
|
// This takes advantage of the fact that localMatrix is a simple
|
|
|
|
// homogenous scale/rotate/translate matrix with no shear
|
|
|
|
vec4f_t x = localMatrix[index][0];
|
|
|
|
vec4f_t y = localMatrix[index][1];
|
|
|
|
vec4f_t z = localMatrix[index][2];
|
|
|
|
vec4f_t t = localMatrix[index][3];
|
|
|
|
|
|
|
|
// "one" is to ensure both the scalar and translation have 1 in their
|
|
|
|
// fourth components
|
|
|
|
vec4f_t one = { 0, 0, 0, 1 };
|
|
|
|
vec4f_t nx = { x[0], y[0], z[0], 0 };
|
|
|
|
vec4f_t ny = { x[1], y[1], z[1], 0 };
|
|
|
|
vec4f_t nz = { x[2], y[2], z[2], 0 };
|
|
|
|
vec4f_t nt = one - t[0] * nx - t[1] * ny - t[2] * nz;
|
|
|
|
// vertical dot product!!!
|
|
|
|
vec4f_t s = 1 / (nx * nx + ny * ny + nz * nz + one);
|
|
|
|
localInverse[index][0] = nx * s;
|
|
|
|
localInverse[index][1] = ny * s;
|
|
|
|
localInverse[index][2] = nz * s;
|
|
|
|
localInverse[index][3] = nt * s;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
Transform_UpdateMatrices (hierarchy_t *h)
|
|
|
|
{
|
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
mat4f_t *localInverse = h->components[transform_type_localInverse];
|
|
|
|
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 *worldRotation = h->components[transform_type_worldRotation];
|
|
|
|
byte *modified = h->components[transform_type_modified];
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < h->num_objects; i++) {
|
|
|
|
if (modified[i]) {
|
|
|
|
transform_calcLocalInverse (h, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (modified[0]) {
|
|
|
|
memcpy (worldMatrix[0],
|
|
|
|
localMatrix[0], sizeof (mat4_t));
|
|
|
|
memcpy (worldInverse[0],
|
|
|
|
localInverse[0], sizeof (mat4_t));
|
|
|
|
worldRotation[0] = localRotation[0];
|
|
|
|
}
|
|
|
|
for (size_t i = 1; i < h->num_objects; i++) {
|
|
|
|
uint32_t parent = h->parentIndex[i];
|
|
|
|
|
|
|
|
if (modified[i] || modified[parent]) {
|
|
|
|
mmulf (worldMatrix[i],
|
|
|
|
worldMatrix[parent], localMatrix[i]);
|
|
|
|
modified[i] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t i = 1; i < h->num_objects; i++) {
|
|
|
|
uint32_t parent = h->parentIndex[i];
|
|
|
|
|
|
|
|
if (modified[i] || modified[parent]) {
|
|
|
|
mmulf (worldInverse[i],
|
|
|
|
localInverse[i], worldInverse[parent]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t i = 1; i < h->num_objects; i++) {
|
|
|
|
uint32_t parent = h->parentIndex[i];
|
|
|
|
if (modified[i] || modified[parent]) {
|
|
|
|
worldRotation[i] = qmulf (worldRotation[parent],
|
|
|
|
localRotation[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memset (modified, 0, h->num_objects);
|
|
|
|
}
|
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
transform_t
|
2022-10-26 06:22:09 +00:00
|
|
|
Transform_New (ecs_registry_t *reg, transform_t parent)
|
2022-05-08 02:14:00 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
uint32_t transform = ECS_NewEntity (reg);
|
|
|
|
hierref_t *ref = Ent_AddComponent (transform, scene_href, reg);
|
|
|
|
|
|
|
|
if (parent.reg && parent.id != nullent) {
|
|
|
|
hierref_t *pref = Transform_GetRef (parent);
|
|
|
|
ref->hierarchy = pref->hierarchy;
|
|
|
|
ref->index = Hierarchy_InsertHierarchy (pref->hierarchy, 0,
|
|
|
|
pref->index, 0);
|
2021-03-09 02:39:41 +00:00
|
|
|
} else {
|
2022-12-11 15:20:20 +00:00
|
|
|
ref->hierarchy = Hierarchy_New (reg, scene_href, &transform_type, 1);
|
2022-10-22 04:04:07 +00:00
|
|
|
ref->index = 0;
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
ref->hierarchy->ent[ref->index] = transform;
|
2022-10-22 04:04:07 +00:00
|
|
|
Transform_UpdateMatrices (ref->hierarchy);
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
return (transform_t) { .reg = reg, .id = transform, .comp = scene_href };
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-10-26 06:22:09 +00:00
|
|
|
Transform_Delete (transform_t transform)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
hierref_t *ref = Transform_GetRef (transform);
|
|
|
|
if (ref->index != 0) {
|
2021-03-09 02:39:41 +00:00
|
|
|
// The transform is not the root, so pull it out of its current
|
|
|
|
// hierarchy so deleting it is easier
|
2022-10-26 06:22:09 +00:00
|
|
|
Transform_SetParent (transform, (transform_t) {});
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
2022-03-02 01:46:29 +00:00
|
|
|
// Takes care of freeing the transforms
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Hierarchy_Delete (ref->hierarchy);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
transform_t
|
2022-10-26 06:22:09 +00:00
|
|
|
Transform_NewNamed (ecs_registry_t *reg, transform_t parent, const char *name)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
2022-10-26 06:22:09 +00:00
|
|
|
transform_t transform = Transform_New (reg, parent);
|
2021-03-09 02:39:41 +00:00
|
|
|
Transform_SetName (transform, name);
|
|
|
|
return transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-10-26 06:22:09 +00:00
|
|
|
Transform_SetParent (transform_t transform, transform_t parent)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
2022-11-05 08:38:14 +00:00
|
|
|
hierarchy_t *dst = 0;
|
|
|
|
uint32_t dstParent = nullent;
|
|
|
|
hierarchy_t *src = 0;
|
|
|
|
uint32_t srcIndex = 0;
|
|
|
|
if (Transform_Valid (parent)) {
|
|
|
|
__auto_type ref = Transform_GetRef (parent);
|
|
|
|
dst = ref->hierarchy;
|
|
|
|
dstParent = ref->index;
|
|
|
|
}
|
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-11-05 08:38:14 +00:00
|
|
|
src = ref->hierarchy;
|
|
|
|
srcIndex = ref->index;
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
2022-11-05 08:38:14 +00:00
|
|
|
Hierarchy_SetParent (dst, dstParent, src, srcIndex);
|
|
|
|
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
byte *modified = h->components[transform_type_modified];
|
2022-10-22 04:04:07 +00:00
|
|
|
modified[ref->index] = 1;
|
2022-10-09 17:00:33 +00:00
|
|
|
Transform_UpdateMatrices (h);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetName (transform_t transform, const char *_name)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
char **name = h->components[transform_type_name];
|
2021-03-09 02:39:41 +00:00
|
|
|
//FIXME create a string pool (similar to qfcc's, or even move that to util)
|
2022-10-22 04:04:07 +00:00
|
|
|
if (name[ref->index]) {
|
|
|
|
free (name[ref->index]);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
2022-10-22 04:04:07 +00:00
|
|
|
name[ref->index] = strdup (_name);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetTag (transform_t transform, uint32_t _tag)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
uint32_t *tag = h->components[transform_type_tag];
|
2022-10-22 04:04:07 +00:00
|
|
|
tag[ref->index] = _tag;
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetLocalPosition (transform_t transform, vec4f_t position)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
byte *modified = h->components[transform_type_modified];
|
2022-10-22 04:04:07 +00:00
|
|
|
localMatrix[ref->index][3] = position;
|
|
|
|
modified[ref->index] = 1;
|
2022-10-09 17:00:33 +00:00
|
|
|
Transform_UpdateMatrices (h);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetLocalRotation (transform_t transform, vec4f_t rotation)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
vec4f_t *localRotation = h->components[transform_type_localRotation];
|
|
|
|
vec4f_t *localScale = h->components[transform_type_localScale];
|
|
|
|
byte *modified = h->components[transform_type_modified];
|
2022-10-22 04:04:07 +00:00
|
|
|
vec4f_t scale = localScale[ref->index];
|
2021-03-09 02:39:41 +00:00
|
|
|
|
|
|
|
mat4f_t mat;
|
|
|
|
mat4fquat (mat, rotation);
|
|
|
|
|
2022-10-22 04:04:07 +00:00
|
|
|
localRotation[ref->index] = rotation;
|
|
|
|
localMatrix[ref->index][0] = mat[0] * scale[0];
|
|
|
|
localMatrix[ref->index][1] = mat[1] * scale[1];
|
|
|
|
localMatrix[ref->index][2] = mat[2] * scale[2];
|
|
|
|
modified[ref->index] = 1;
|
2022-10-09 17:00:33 +00:00
|
|
|
Transform_UpdateMatrices (h);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetLocalScale (transform_t transform, vec4f_t scale)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
vec4f_t *localRotation = h->components[transform_type_localRotation];
|
|
|
|
vec4f_t *localScale = h->components[transform_type_localScale];
|
|
|
|
byte *modified = h->components[transform_type_modified];
|
2022-10-22 04:04:07 +00:00
|
|
|
vec4f_t rotation = localRotation[ref->index];
|
2021-03-09 02:39:41 +00:00
|
|
|
|
|
|
|
mat4f_t mat;
|
|
|
|
mat4fquat (mat, rotation);
|
|
|
|
|
2022-10-22 04:04:07 +00:00
|
|
|
localScale[ref->index] = scale;
|
|
|
|
localMatrix[ref->index][0] = mat[0] * scale[0];
|
|
|
|
localMatrix[ref->index][1] = mat[1] * scale[1];
|
|
|
|
localMatrix[ref->index][2] = mat[2] * scale[2];
|
|
|
|
modified[ref->index] = 1;
|
2022-10-09 17:00:33 +00:00
|
|
|
Transform_UpdateMatrices (h);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetWorldPosition (transform_t transform, vec4f_t position)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
if (ref->index) {
|
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
mat4f_t *worldInverse = h->components[transform_type_worldInverse];
|
2022-10-22 04:04:07 +00:00
|
|
|
uint32_t parent = h->parentIndex[ref->index];
|
2022-10-09 17:00:33 +00:00
|
|
|
position = mvmulf (worldInverse[parent], position);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
Transform_SetLocalPosition (transform, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetWorldRotation (transform_t transform, vec4f_t rotation)
|
2021-03-09 02:39:41 +00:00
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
if (ref->index) {
|
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
vec4f_t *worldRotation = h->components[transform_type_worldRotation];
|
2022-10-22 04:04:07 +00:00
|
|
|
uint32_t parent = h->parentIndex[ref->index];
|
2022-10-09 17:00:33 +00:00
|
|
|
rotation = qmulf (qconjf (worldRotation[parent]), rotation);
|
2021-03-09 02:39:41 +00:00
|
|
|
}
|
|
|
|
Transform_SetLocalRotation (transform, rotation);
|
|
|
|
}
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
void
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
Transform_SetLocalTransform (transform_t transform, vec4f_t scale,
|
2021-03-09 14:52:40 +00:00
|
|
|
vec4f_t rotation, vec4f_t position)
|
|
|
|
{
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
__auto_type ref = Transform_GetRef (transform);
|
2022-10-22 04:04:07 +00:00
|
|
|
hierarchy_t *h = ref->hierarchy;
|
2022-10-09 17:00:33 +00:00
|
|
|
mat4f_t *localMatrix = h->components[transform_type_localMatrix];
|
|
|
|
vec4f_t *localRotation = h->components[transform_type_localRotation];
|
|
|
|
vec4f_t *localScale = h->components[transform_type_localScale];
|
|
|
|
byte *modified = h->components[transform_type_modified];
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t mat;
|
|
|
|
mat4fquat (mat, rotation);
|
|
|
|
|
|
|
|
position[3] = 1;
|
2022-10-22 04:04:07 +00:00
|
|
|
localRotation[ref->index] = rotation;
|
|
|
|
localScale[ref->index] = scale;
|
|
|
|
localMatrix[ref->index][0] = mat[0] * scale[0];
|
|
|
|
localMatrix[ref->index][1] = mat[1] * scale[1];
|
|
|
|
localMatrix[ref->index][2] = mat[2] * scale[2];
|
|
|
|
localMatrix[ref->index][3] = position;
|
|
|
|
modified[ref->index] = 1;
|
2022-10-09 17:00:33 +00:00
|
|
|
Transform_UpdateMatrices (h);
|
2021-03-09 14:52:40 +00:00
|
|
|
}
|