Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/src/goddard/skin_movement.c
7858 views
1
#include <PR/ultratypes.h>
2
3
#include "debug_utils.h"
4
#include "gd_math.h"
5
#include "gd_types.h"
6
#include "joints.h"
7
#include "macros.h"
8
#include "objects.h"
9
#include "skin.h"
10
#include "skin_movement.h"
11
12
/* bss */
13
struct ObjWeight *sResetCurWeight;
14
static Mat4f D_801B9EA8; // TODO: rename to sHead2Mtx?
15
static struct ObjJoint *D_801B9EE8; // set but not used
16
17
/* @ 22FDB0 for 0x180 */
18
void func_801815E0(Mat4f *mtx) {
19
struct GdVec3f scratchVec;
20
21
scratchVec.x = (*mtx)[0][0];
22
scratchVec.y = (*mtx)[0][1];
23
scratchVec.z = (*mtx)[0][2];
24
gd_normalize_vec3f(&scratchVec);
25
(*mtx)[0][0] = scratchVec.x;
26
(*mtx)[0][1] = scratchVec.y;
27
(*mtx)[0][2] = scratchVec.z;
28
29
scratchVec.x = (*mtx)[1][0];
30
scratchVec.y = (*mtx)[1][1];
31
scratchVec.z = (*mtx)[1][2];
32
gd_normalize_vec3f(&scratchVec);
33
(*mtx)[1][0] = scratchVec.x;
34
(*mtx)[1][1] = scratchVec.y;
35
(*mtx)[1][2] = scratchVec.z;
36
37
scratchVec.x = (*mtx)[2][0];
38
scratchVec.y = (*mtx)[2][1];
39
scratchVec.z = (*mtx)[2][2];
40
gd_normalize_vec3f(&scratchVec);
41
(*mtx)[2][0] = scratchVec.x;
42
(*mtx)[2][1] = scratchVec.y;
43
(*mtx)[2][2] = scratchVec.z;
44
}
45
46
/* @ 22FF30 for 0xDC */
47
/* called with ObjNext->unk1A8 (variable obj ptr?) ->unk20 or ->unk24 ptr*/
48
// TODO: figure out the proper object type for a0
49
void scale_verts(struct ObjGroup *a0) {
50
register f32 sp1C;
51
register struct ListNode *link;
52
struct ObjVertex *vtx;
53
54
for (link = a0->firstMember; link != NULL; link = link->next) {
55
vtx = (struct ObjVertex *) link->obj;
56
57
if ((sp1C = vtx->scaleFactor) != 0.0f) {
58
vtx->pos.x = vtx->initPos.x * sp1C;
59
vtx->pos.y = vtx->initPos.y * sp1C;
60
vtx->pos.z = vtx->initPos.z * sp1C;
61
} else {
62
vtx->pos.x = vtx->pos.y = vtx->pos.z = 0.0f;
63
}
64
}
65
}
66
67
/* @ 23000C for 0x58; orig name: func8018183C*/
68
void move_skin(struct ObjNet *net) {
69
UNUSED u8 pad1C[8];
70
71
if (net->shapePtr != NULL) {
72
scale_verts(net->shapePtr->scaledVtxGroup);
73
}
74
}
75
76
/* @ 230064 for 0x13C*/
77
void func_80181894(struct ObjJoint *joint) {
78
register struct ObjGroup *weightGroup; // baseGroup? weights Only?
79
struct GdVec3f stackVec;
80
register struct ObjWeight *curWeight;
81
register struct ObjVertex *connectedVtx;
82
register struct ListNode *link;
83
register f32 scaleFactor;
84
struct GdObj *linkedObj;
85
86
weightGroup = joint->weightGrp;
87
if (weightGroup != NULL) {
88
for (link = weightGroup->firstMember; link != NULL; link = link->next) {
89
linkedObj = link->obj;
90
curWeight = (struct ObjWeight *) linkedObj;
91
92
if (curWeight->weightVal > 0.0) //? 0.0f
93
{
94
stackVec.x = curWeight->vec20.x;
95
stackVec.y = curWeight->vec20.y;
96
stackVec.z = curWeight->vec20.z;
97
gd_rotate_and_translate_vec3f(&stackVec, &joint->matE8);
98
99
connectedVtx = curWeight->vtx;
100
scaleFactor = curWeight->weightVal;
101
102
connectedVtx->pos.x += stackVec.x * scaleFactor;
103
connectedVtx->pos.y += stackVec.y * scaleFactor;
104
connectedVtx->pos.z += stackVec.z * scaleFactor;
105
}
106
}
107
}
108
}
109
110
/* @ 2301A0 for 0x110 */
111
void reset_weight_vtx(struct ObjVertex *vtx) {
112
struct GdVec3f localVec;
113
UNUSED u8 pad24[0x10];
114
115
if (sResetWeightVtxNum++ == sResetCurWeight->vtxId) { // found matching vertex
116
sResetCurWeight->vtx = vtx;
117
localVec.x = vtx->pos.x;
118
localVec.y = vtx->pos.y;
119
localVec.z = vtx->pos.z;
120
121
gd_rotate_and_translate_vec3f(&localVec, &D_801B9EA8);
122
sResetCurWeight->vec20.x = localVec.x;
123
sResetCurWeight->vec20.y = localVec.y;
124
sResetCurWeight->vec20.z = localVec.z;
125
126
vtx->scaleFactor -= sResetCurWeight->weightVal;
127
}
128
}
129
130
void reset_weight(struct ObjWeight *weight) {
131
UNUSED u32 vtxCount;
132
UNUSED u32 pad20;
133
struct ObjGroup *skinGroup;
134
135
sResetCurWeight = weight;
136
sResetWeightVtxNum = 0;
137
if ((skinGroup = gGdSkinNet->skinGrp) != NULL) {
138
// Go through every vertex in the skin group, and reset the weight if the vertex is managed by the weight
139
vtxCount =
140
apply_to_obj_types_in_group(OBJ_TYPE_VERTICES, (applyproc_t) reset_weight_vtx, skinGroup);
141
} else {
142
fatal_printf("reset_weight(): Skin net has no SkinGroup");
143
}
144
145
if (weight->vtx == NULL) {
146
fatal_printf("reset_weight(): Skin vertex ID %d not found", weight->vtxId);
147
}
148
}
149
150
void reset_joint_weights(struct ObjJoint *joint) {
151
struct ObjGroup *group;
152
153
gd_inverse_mat4f(&joint->matE8, &D_801B9EA8);
154
D_801B9EE8 = joint;
155
if ((group = joint->weightGrp) != NULL) {
156
apply_to_obj_types_in_group(OBJ_TYPE_WEIGHTS, (applyproc_t) reset_weight, group);
157
}
158
}
159
160