DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
cloth.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 285
4
5#include "cloth.hpp"
6
7#include <cstring>
8
9#include "bound.hpp"
10#include "frame.hpp"
11#include "framevu1.hpp"
12#include "mglib.hpp"
13#include "texture.hpp"
14#include "wind.hpp"
15
20 CFrameVu1 draw_frame;
21 int i;
22
23 draw_frame.SetVisual(this);
24 draw_frame.max[0] = 10000.0f;
25 draw_frame.max[1] = 10000.0f;
26 draw_frame.max[2] = 10000.0f;
27 draw_frame.min[0] = -10000.0f;
28 draw_frame.min[1] = -10000.0f;
29 draw_frame.min[2] = -10000.0f;
30
31 for (i = 0; i < 8; i++) {
32 float *corner[2];
33
34 corner[0] = draw_frame.min;
35 corner[1] = draw_frame.max;
36 draw_frame.corner[i][3] = 1.0f;
37 draw_frame.corner[i][0] = corner[(i & 1) != 0][0];
38 draw_frame.corner[i][1] = corner[(i & 2) != 0][1];
39 draw_frame.corner[i][2] = corner[(i & 4) != 0][2];
40 }
41
42 CFrameAttr attr;
43
44 attr.fog_enable = false;
45 attr.program_option = 0;
46 attr.clip_enable = false;
47 float origin = 0.0f;
48
49 draw_frame.SetAttr(attr, 1, 0);
50 draw_frame.SetPosition(origin, origin, origin);
51 MGDraw(&draw_frame);
52}
53
62 sceVu0FMATRIX matrix;
63 int i;
64 int j;
65
66 if (frame != NULL) {
67 frame->GetLWMatrix(matrix);
68 }
69
70 sceVu0ApplyMatrix(last_position, matrix, position);
71
72 for (j = 0; j < num_j; j++) {
73 for (i = 0; i < num_i; i++) {
74 float *velocity = speed[i][j];
75 float *vertex = point[i][j];
76 velocity[0] = 0.0f;
77 velocity[1] = 0.0f;
78 velocity[2] = 0.0f;
79
80 if (frame != NULL) {
81 sceVu0ApplyMatrix(point[i][j], matrix, home[i][j]);
82 sceVu0CopyVector(last[i][j], point[i][j]);
83 }
84 }
85 }
86}
87#ifndef PORT
91static void StretchBind2(float *point_a, float *point_b, float *spring) {
92 asm {
93 lqc2 $vf10, 0x0($4)
94 lqc2 $vf11, 0x0($5)
95 lqc2 $vf12, 0x0($6)
96 vmulx.xyzw $vf1, $vf0, $vf0x
97 vsub.xyz $vf13, $vf10, $vf11
98 vnop
99 vnop
100 vnop
101 vaddy.x $vf5, $vf1, $vf13y
102 vaddz.x $vf6, $vf1, $vf13z
103 vmula.x $ACC, $vf13, $vf13
104 vmadday.x $ACC, $vf5, $vf13y
105 vmaddz.x $vf7, $vf6, $vf13z
106 vrsqrt $Q, $vf12x, $vf7x
107 vaddax.xyzw $ACC, $vf13, $vf0x
108 vwaitq
109 vmsubq.xyzw $vf25, $vf13, $Q
110 vaddax.xyzw $ACC, $vf10, $vf0x
111 vmsuby.xyz $vf10, $vf25, $vf12y
112 vaddax.xyzw $ACC, $vf11, $vf0x
113 vmaddz.xyz $vf11, $vf25, $vf12z
114 sqc2 $vf10, 0x0($4)
115 sqc2 $vf11, 0x0($5)
116 }
117}
118
122static float vuabs(float *vector) {
123 asm {
124 lqc2 $vf4, 0x0($4)
125 vmul.xyz $vf4, $vf4, $vf4
126 vmr32.xy $vf5, $vf4
127 vmr32.x $vf6, $vf5
128 vadd.x $vf7, $vf4, $vf5
129 vadd.x $vf5, $vf6, $vf7
130 vsqrt $Q, $vf5x
131 vwaitq
132 cfc2.ni $2, $vi22
133 mtc1 $2, $f0
134 }
135}
136
144void CCloth::Step(int step) {
145 float *velocity;
146 int i;
147 float *hit_point;
148 int j;
149 int pass;
150 float *scratchpad;
151 int reset;
152 sceVu0FVECTOR(*work)[16];
153 float ground;
154 float *vertex;
155
156 sceVu0FVECTOR root;
157 sceVu0FVECTOR delta;
158 sceVu0FMATRIX matrix;
159 sceVu0FVECTOR scratch;
160 sceVu0FVECTOR *stretch_params;
161
162 if (step < 0) {
163 Clear();
164 return;
165 }
166
167 reset = 0;
168 ground = floor_y;
169 // The grid is solved in scratchpad memory, followed by the per-column stretch parameters and the hit buffer.
170 scratchpad = (float *) 0x70000000;
171 work = (sceVu0FVECTOR(*)[16]) scratchpad;
172
173 for (i = 0; i < num_i; i++) {
174 for (j = 0; j < num_j; j++) {
175 *(u_long128 *) work[i][j] = *(u_long128 *) point[i][j];
176 }
177 }
178
179 scratchpad += sizeof(point) / sizeof(float);
180
181 if (frame != NULL) {
182 frame->GetLWMatrix(matrix);
183 sceVu0ApplyMatrix(root, matrix, this->position);
184 sceVu0SubVector(delta, root, last_position);
185
186 if (vuabs(delta) > 10.0f || stop != 0) {
187 reset = 1;
188 } else {
189 delta[0] *= follow[0];
190 delta[1] *= follow[1];
191 delta[2] *= follow[2];
192 }
193
194 last_position[0] = root[0];
195 last_position[1] = root[1];
196 last_position[2] = root[2];
197 }
198
199 // Load the frame's matrix and the stiffness into VU0 for the springs below.
200 {
201 register float *stiffness_ptr;
202 register float *matrix_ptr;
203
204 matrix_ptr = &matrix[0][0];
205 stiffness_ptr = stiffness;
206
207 asm {
208 lqc2 $vf1, 0x0(matrix_ptr)
209 lqc2 $vf2, 0x10(matrix_ptr)
210 lqc2 $vf3, 0x20(matrix_ptr)
211 lqc2 $vf4, 0x30(matrix_ptr)
212 lqc2 $vf5, 0x0(stiffness_ptr)
213 }
214 }
215
216 // Pull each vertex after its frame, springing towards where the frame carries its rest position.
217 for (j = 0; j < num_j; j++) {
218 for (i = 0; i < num_i; i++) {
219 vertex = work[i][j];
220 velocity = speed[i][j];
221
222 if (reset != 0) {
223 vertex[0] += delta[0];
224 vertex[1] += delta[1];
225 vertex[2] += delta[2];
226 } else if (frame != NULL) {
227 register float *delta_ptr;
228 register float *home_ptr;
229 register float *world_home_ptr;
230 register float *vel_ptr;
231 register float *vertex_ptr;
232
233 vertex_ptr = vertex;
234 vel_ptr = velocity;
235 world_home_ptr = world_home[i][j];
236 home_ptr = home[i][j];
237 delta_ptr = delta;
238
239 asm {
240 lqc2 $vf13, 0x0(home_ptr)
241 lqc2 $vf10, 0x0(vertex_ptr)
242 lqc2 $vf11, 0x0(vel_ptr)
243 lqc2 $vf12, 0x0(delta_ptr)
244 vmulax.xyzw $ACC, $vf1, $vf13x
245 vmadday.xyzw $ACC, $vf2, $vf13y
246 vmaddaz.xyzw $ACC, $vf3, $vf13z
247 vmaddw.xyzw $vf23, $vf4, $vf13w
248 vaddx.w $vf10, $vf0, $vf0x
249 vaddx.w $vf11, $vf0, $vf0x
250 sqc2 $vf23, 0x0(world_home_ptr)
251 vsub.xyzw $vf20, $vf23, $vf10
252 vmulaw.xyzw $ACC, $vf12, $vf0w
253 vmadd.xyzw $vf26, $vf20, $vf5
254 vmulaw.xyzw $ACC, $vf10, $vf0w
255 vmaddaw.xyzw $ACC, $vf11, $vf0w
256 vmaddw.xyz $vf10, $vf26, $vf0w
257 vmulax.xyzw $ACC, $vf0, $vf0x
258 vmsubw.xyz $vf11, $vf26, $vf0w
259 sqc2 $vf10, 0x0(vertex_ptr)
260 sqc2 $vf11, 0x0(vel_ptr)
261 }
262 } else {
263 vertex[0] += velocity[0];
264 vertex[1] += velocity[1];
265 vertex[2] += velocity[2];
266 }
267 }
268 }
269
270 sceVu0FVECTOR origin = {0.0f, 0.0f, 0.0f, 1.0f};
271 stretch_params = (sceVu0FVECTOR *) scratchpad;
272 scratchpad += num_j * sizeof(sceVu0FVECTOR) / sizeof(float);
273 hit_point = scratchpad;
274 scratch[1] = 0.5f;
275 scratch[2] = 0.5f;
276
277 for (j = 0; j < num_j - 1; j++) {
278 stretch_params[j][1] = 0.3f + 0.2f * ((float) j / (float) num_j);
279 stretch_params[j][2] = 1.0f - stretch_params[j][1];
280 }
281
282 for (pass = 0; pass < 4 && reset == 0; pass++) {
283 for (j = 0; j < num_j - 1; j++) {
284 for (i = 0; i < num_i; i++) {
285 if (i > 1) {
286 scratch[0] = 2.0f * rest[i][j][0];
287 StretchBind2(work[i][j], work[i - 2][j], scratch);
288 } else {
289 scratch[0] = 0.0f;
290 }
291
292 stretch_params[j][0] = rest[i][j][1];
293 StretchBind2(work[i][j], work[i][j + 1], stretch_params[j]);
294 }
295 }
296
297 for (j = 0; j < num_i; j++) {
298 if (frame == NULL) {
299 sceVu0CopyVector(work[j][0], home[j][0]);
300 } else {
301 *(u_long128 *) work[j][0] = *(u_long128 *) world_home[j][0];
302 }
303 }
304 }
305
306 // Push the vertices out of the exclusion boxes.
307 if (bound != NULL) {
308 bound->UpDate();
309 }
310
311 for (j = 1; j < num_j; j++) {
312 for (i = 0; i < num_i; i++) {
313 CBound *box = bound;
314 int touched = 0;
315 float hit_count = 0.0f;
316 sceVu0FVECTOR hit_sum;
317 hit_sum[2] = 0.0f;
318 hit_sum[1] = 0.0f;
319 hit_sum[0] = 0.0f;
320 float friction = 0.0f;
321
322 for (; box != NULL; box = box->next) {
323 if ((mask[i][j] & (1 << box->mask_bit)) && box->InCheck(work[i][j], hit_point) != 0) {
324 hit_count += 1.0f;
325 sceVu0AddVector(hit_sum, hit_sum, hit_point);
326 friction += box->friction;
327 touched = 1;
328 }
329 }
330
331 if (touched) {
332 work[i][j][0] = hit_sum[0] / hit_count;
333 work[i][j][1] = hit_sum[1] / hit_count;
334 work[i][j][2] = hit_sum[2] / hit_count;
335 rest[i][j][3] = friction / hit_count;
336 } else {
337 rest[i][j][3] = -1.0f;
338 }
339 }
340 }
341
342 // Carry the motion into the speeds, with gravity, wind and damping.
343 sceVu0FVECTOR wind_force = {0.0f, 0.0f, 0.0f, 0.0f};
344
345 for (i = 0; i < num_i; i++) {
346 if (wind != NULL) {
347 ((CWind *) wind)->GetWindNoise(wind_force);
348 sceVu0ScaleVector(wind_force, wind_force, wind_effect);
349 }
350
351 for (j = 0; j < num_j; j++) {
352 speed[i][j][0] += gravity[0] + (work[i][j][0] - last[i][j][0]);
353 speed[i][j][1] += gravity[1] + (work[i][j][1] - last[i][j][1]);
354 speed[i][j][2] += gravity[2] + (work[i][j][2] - last[i][j][2]);
355 sceVu0CopyVector(last[i][j], work[i][j]);
356 sceVu0Normalize(scratch, speed[i][j]);
357 float facing = sceVu0InnerProduct(scratch, normal_grid[i][j]);
358
359 if (facing < 0.0f) {
360 facing *= -1.0f;
361 }
362
363 float damping = 0.6f + (1.0f - facing);
364
365 if (damping > 1.0f) {
366 damping = 1.0f;
367 }
368
369 speed[i][j][0] += facing * wind_force[0];
370 speed[i][j][1] += facing * wind_force[1];
371 speed[i][j][2] += facing * wind_force[2];
372 speed[i][j][0] *= damping;
373 speed[i][j][1] *= damping;
374 speed[i][j][2] *= damping;
375
376 if (reset != 0) {
377 speed[i][j][0] = 0.0f;
378 speed[i][j][1] = 0.0f;
379 speed[i][j][2] = 0.0f;
380 } else {
381 if (rest[i][j][3] > 0.0f) {
382 speed[i][j][0] *= rest[i][j][3];
383 speed[i][j][1] *= rest[i][j][3];
384 speed[i][j][2] *= rest[i][j][3];
385 }
386
387 if (work[i][j][1] <= ground && floor_on != 0) {
388 work[i][j][1] = ground;
389 speed[i][j][0] *= 0.4f;
390 speed[i][j][2] *= 0.4f;
391 }
392 }
393 }
394 }
395
396 // Rebuild each vertex's normal from its four neighbours.
397 sceVu0FVECTOR edge[4];
398 sceVu0FVECTOR normal;
399 sceVu0FVECTOR cross[4];
400 normal[3] = 0.0f;
401 normal[2] = 0.0f;
402 normal[1] = 0.0f;
403 normal[0] = 0.0f;
404
405 for (j = 0; j < num_j; j++) {
406 for (i = 0; i < num_i; i++) {
407 int next_i;
408 int prev_j;
409 int next_j;
410 int prev_i;
411
412 next_i = i + 1;
413 prev_i = i - 1;
414 prev_j = j - 1;
415 next_j = j + 1;
416
417 if (prev_i < 0) {
418 prev_i = 0;
419 }
420
421 if (prev_j < 0) {
422 prev_j = 0;
423 }
424
425 if (next_i >= num_i) {
426 next_i = num_i - 1;
427 }
428
429 if (next_j >= num_j) {
430 next_j = num_j - 1;
431 }
432
433 sceVu0SubVector(edge[0], work[next_i][j], work[i][j]);
434 sceVu0SubVector(edge[1], work[prev_i][j], work[i][j]);
435 sceVu0SubVector(edge[2], work[i][prev_j], work[i][j]);
436 sceVu0SubVector(edge[3], work[i][next_j], work[i][j]);
437 sceVu0OuterProduct(cross[0], edge[3], edge[0]);
438 sceVu0OuterProduct(cross[1], edge[1], edge[3]);
439 sceVu0OuterProduct(cross[2], edge[2], edge[1]);
440 sceVu0OuterProduct(cross[3], edge[0], edge[2]);
441 sceVu0AddVector(normal, cross[0], cross[1]);
442 sceVu0AddVector(normal, normal, cross[2]);
443 sceVu0AddVector(normal, normal, cross[3]);
444 sceVu0ScaleVector(normal, normal, normal_scale);
445 sceVu0Normalize(normal_grid[i][j], normal);
446 }
447 }
448
449 for (i = 0; i < num_i; i++) {
450 for (j = 0; j < num_j; j++) {
451 *(u_long128 *) point[i][j] = *(u_long128 *) work[i][j];
452 }
453 }
454}
455#endif
463int CCloth::DrawVu1(u_int *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
464 CreateVUData(vu_block[DBuffID]);
465 vu_data = vu_block[DBuffID];
466 return CVisualVu1::DrawVu1(packet, matrix, info, program, draw_state, unknown2, 0);
467}
468
476int CCloth::DrawVu1(sceVif1Packet *packet, float (*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2) {
477 CreateVUData(vu_block[DBuffID]);
478 vu_data = vu_block[DBuffID];
479 return CVisualVu1::DrawVu1(packet, matrix, info, program, draw_state, unknown2, 0);
480}
481
489int SetMaterial(u_int *packet, MDT_MATERIAL *material);
490int SetTEX0(u_int *packet, u_long tex0, u_long tex1);
491
492int CCloth::CreateVUData(u_int *packet) {
493 int j;
494 CTexture *texture;
495 int i;
496 u_int *tag;
497 int word;
498 int vertex_count;
499 int started;
500 int qwc;
501 int header_word;
502 int span;
503 u_long128 *vertex;
504 u_long128 *normal;
505 u_int header_tag;
506 u_long128 *uv;
507
508 word = 0;
509 u_int end_tag[4] = {0x11000000, 0, 0, 0};
510 u_int first_kick[4] = {0, 0, 0, 0x14000000};
511 u_int kick[4] = {0, 0, 0, 0x17000000};
512 u_int unpack[4] = {0, 0, 0, 0x6C008000};
513 sceVu0FVECTOR one = {1.0f, 1.0f, 1.0f, 1.0f};
514 MDT_MATERIAL cloth_material;
515
516 cloth_material.ambient[0] = 0.3f;
517 cloth_material.ambient[1] = 0.3f;
518 cloth_material.ambient[2] = 0.3f;
519 cloth_material.ambient[3] = 0.0f;
520 *(u_long128 *) cloth_material.diffuse = *(u_long128 *) one;
521 *(u_long128 *) cloth_material.specular = *(u_long128 *) one;
522 started = false;
523 word += SetMaterial(&packet[word], &cloth_material);
524 texture = TexManager.GetTexture(material.texture, -1);
525
526 if (texture != NULL) {
527 word += SetTEX0(&packet[word], texture->tex0, texture->tex1);
528 } else {
529 word += SetTEX0(&packet[word], 0, 0);
530 }
531
532 for (i = 0; i < num_i - 1; i++) {
533 span = num_j;
534 vertex_count = span * 2;
535 qwc = 0;
536 *(u_long128 *) &packet[word] = *(u_long128 *) unpack;
537 header_word = word + 3;
538 header_tag = vertex_count | 0x8000;
539 tag = &packet[word + 4];
540 tag[0] = header_tag;
541 tag[1] = 0x302E4000;
542 tag[2] = 0x412;
543 tag[3] = 0;
544 tag = &packet[word + 8];
545 tag[0] = vertex_count;
546 tag[1] = 4;
547 tag[2] = 0;
548 tag[3] = 0;
549 word += 12;
550 qwc += 2;
551 vertex = (u_long128 *) &packet[word];
552 normal = vertex + span * 2;
553 span = (int) (normal + span * 2);
554 uv = (u_long128 *) span;
555
556 // A divided row is drawn from the far side, so the strip winds the other way.
557 if (polygon_divide[i] != 0) {
558 for (j = 0; j < vertex_count >> 1; j++) {
559 vertex[0] = *(u_long128 *) point[i + 1][j];
560 normal[0] = *(u_long128 *) normal_grid[i + 1][j];
561 uv[0] = *(u_long128 *) texture_coord[i + 1][j];
562 vertex[1] = *(u_long128 *) point[i][j];
563 vertex += 2;
564 normal[1] = *(u_long128 *) normal_grid[i][j];
565 normal += 2;
566 uv[1] = *(u_long128 *) texture_coord[i][j];
567 uv += 2;
568 }
569 } else {
570 for (j = 0; j < vertex_count >> 1; j++) {
571 vertex[0] = *(u_long128 *) point[i][j];
572 normal[0] = *(u_long128 *) normal_grid[i][j];
573 uv[0] = *(u_long128 *) texture_coord[i][j];
574 vertex[1] = *(u_long128 *) point[i + 1][j];
575 vertex += 2;
576 normal[1] = *(u_long128 *) normal_grid[i + 1][j];
577 normal += 2;
578 uv[1] = *(u_long128 *) texture_coord[i + 1][j];
579 uv += 2;
580 }
581 }
582
583 word += vertex_count * 3 * 4;
584 qwc += vertex_count * 3;
585 packet[header_word] |= qwc << 16;
586
587 if (started == 0) {
588 *(u_long128 *) &packet[word] = *(u_long128 *) first_kick;
589 started = true;
590 } else {
591 *(u_long128 *) &packet[word] = *(u_long128 *) kick;
592 }
593
594 word += 4;
595 }
596
597 *(u_long128 *) &packet[word] = *(u_long128 *) end_tag;
598 return ((word + 4) >> 2) + ((word + 4) % 4 != 0);
599}
600
609 float side_follow = 0.9f;
610 num_i = 16;
611 num_j = 16;
612 pitch = 1.0f;
613 init_20 = 0;
614 vu_block[1] = NULL;
615 vu_block[0] = NULL;
616 frame = NULL;
617 init_40 = 0;
618 flags = 0;
619 wind = NULL;
620 wind_effect = 1.0f;
621 floor_y = 0.0f;
622 last_position[0] = 0.0f;
623 last_position[1] = 0.0f;
624 last_position[2] = 0.0f;
625 stiffness[0] = 0.1f;
626 stiffness[1] = 0.1f;
627 stiffness[2] = 0.1f;
628 follow[0] = side_follow;
629 follow[1] = 0.4f;
630 follow[2] = side_follow;
631 gravity[0] = 0.0f;
632 gravity[1] = -0.1f;
633 gravity[2] = 0.0f;
634 normal_scale = 1.0f;
635 stop = false;
636 floor_on = true;
637 sceVu0FVECTOR zero = {0.0f, 0.0f, 0.0f, 0.0f};
638
639 for (int i = 0; i < num_i; i++) {
640 for (int j = 0; j < num_j; j++) {
641 mask[i][j] = 0xFFFF;
642 sceVu0CopyVector(home[i][j], zero);
643 sceVu0CopyVector(point[i][j], zero);
644 sceVu0CopyVector(last[i][j], zero);
645 sceVu0CopyVector(rest[i][j], zero);
646 sceVu0CopyVector(speed[i][j], zero);
647 sceVu0CopyVector(normal_grid[i][j], zero);
648 sceVu0CopyVector(texture_coord[i][j], zero);
649 }
650 }
651
652 bound = NULL;
653 material.texture[0] = 0;
654}
655
659CCloth::CCloth(int grid_i, int grid_j, float grid_pitch) {
660 InitParam();
661 num_i = grid_i;
662 num_j = grid_j;
663 pitch = grid_pitch;
664}
665
674 int i;
675 int j;
676
677 if (alloc == NULL) {
678 alloc = &VisualData;
679 }
680
681 alloc->Align64();
682 vu_block[0] = (u_int *) (alloc->base + alloc->used * 16);
683 vu_size = CreateVUData(vu_block[0]);
684 alloc->Alloc(vu_size);
685 vu_block[1] = (u_int *) alloc->Alloc64(vu_size);
686 vu_size = CreateVUData(vu_block[1]);
687
688 for (i = 0; i < num_i; i++) {
689 polygon_divide[i] = 0;
690
691 for (j = 0; j < num_j; j++) {
692 sceVu0FVECTOR zero = {0.0f, 0.0f, 0.0f, 0.0f};
693 sceVu0CopyVector(last[j][i], zero);
694 sceVu0CopyVector(speed[j][i], zero);
695 sceVu0CopyVector(normal_grid[j][i], zero);
696 sceVu0CopyVector(rest[j][i], zero);
697 point[j][i][3] = 1.0f;
698 last[j][i][3] = 1.0f;
699 }
700 }
701
702 for (i = 0; i < num_j; i++) {
703 for (j = 0; j < num_i; j++) {
704 sceVu0CopyVector(last[j][i], point[j][i]);
705 sceVu0CopyVector(home[j][i], point[j][i]);
706 }
707 }
708
709 sceVu0FVECTOR centre = {0.0f, 0.0f, 0.0f, 0.0f};
710
711 for (i = 0; i < num_i; i++) {
712 sceVu0AddVector(centre, centre, home[0][i]);
713 }
714
715 position[0] = centre[0] / (float) num_i;
716 position[1] = centre[1] / (float) num_i;
717 position[2] = centre[2] / (float) num_i;
718 position[3] = 1.0f;
719
720 // Record each vertex's rest distance to its neighbours down and across the grid.
721 sceVu0FVECTOR edge;
722
723 for (i = 0; i < num_j; i++) {
724 for (j = 0; j < num_i; j++) {
725 int next_j = j + 1;
726 int prev_j = j - 1;
727 int prev_i = i - 1;
728 int next_i = i + 1;
729
730 if (prev_j > 0) {
731 sceVu0SubVector(edge, point[j][i], point[prev_j][i]);
732 } else if (next_j >= num_i) {
733 sceVu0SubVector(edge, point[j][i], point[prev_j][i]);
734 } else {
735 sceVu0SubVector(edge, point[j][i], point[next_j][i]);
736 }
737
738 rest[j][i][0] = vuabs(edge);
739
740 if (next_i >= num_j) {
741 sceVu0SubVector(edge, point[j][i], point[j][prev_i]);
742 } else if (prev_i < 0) {
743 sceVu0SubVector(edge, point[j][i], point[j][next_i]);
744 } else {
745 sceVu0SubVector(edge, point[j][i], point[j][next_i]);
746 }
747
748 rest[j][i][1] = vuabs(edge);
749 }
750 }
751}
752
761 int *strip;
762
763 if (header == NULL) {
764 return;
765 }
766
767 sceVu0FVECTOR *vertices = (sceVu0FVECTOR *) ((u_char *) header + header->vertex_ofs);
768 sceVu0FVECTOR *uvs = (sceVu0FVECTOR *) ((u_char *) header + header->uv[1]);
769 MDT_MATERIAL *materials = (MDT_MATERIAL *) ((u_char *) header + header->info_ofs);
770 int *mesh = (int *) ((u_char *) header + header->mesh_ofs);
771 strip = mesh + 4;
772 int *strips = strip;
773 int strip_count = mesh[2];
774 int match_count = 0;
775
776 for (int i = 0; i < num_i; i++) {
777 for (int j = 0; j < num_j; j++) {
778 int vertex_no = j + i * num_j;
779 sceVu0CopyVector(point[i][j], vertices[vertex_no]);
780 strip = strips;
781
782 for (int strip_no = 0; strip_no < strip_count; strip_no++) {
783 int corner_count = strip[1];
784 memcpy(&material, &materials[strip[2]], sizeof(MDT_MATERIAL));
785 strip += 3;
786 int *corner = strip;
787
788 for (int corner_no = 0; corner_no < corner_count; corner_no++) {
789 if (corner[0] == vertex_no) {
790 match_count++;
791 sceVu0CopyVector(texture_coord[i][j], uvs[corner[2]]);
792 }
793
794 corner += 3;
795 }
796
797 strip += corner_count * 3;
798 }
799 }
800 }
801
802 Initialize(alloc);
803}
CBound * next
Definition bound.hpp:29
void UpDate()
Definition bound.cpp:276
virtual int InCheck(float *point, float *result)
Definition bound.cpp:25
float friction
Definition bound.hpp:34
s32 mask_bit
Definition bound.hpp:30
void Clear()
Definition cloth.cpp:61
u_int * vu_block[2]
Definition cloth.hpp:24
int floor_on
Definition cloth.hpp:32
float normal_scale
Definition cloth.hpp:36
int init_40
Definition cloth.hpp:30
u_int * vu_data
Definition cloth.hpp:21
sceVu0FVECTOR point[16][16]
Definition cloth.hpp:44
MDT_MATERIAL material
Definition cloth.hpp:37
float pitch
Definition cloth.hpp:27
sceVu0FVECTOR stiffness
Definition cloth.hpp:40
int num_i
Definition cloth.hpp:25
sceVu0FVECTOR world_home[16][16]
Definition cloth.hpp:52
CCloth(int grid_i=16, int grid_j=16, float grid_pitch=1.0f)
Definition cloth.cpp:659
sceVu0FVECTOR speed[16][16]
Definition cloth.hpp:47
virtual int DrawVu1(u_int *packet, float(*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2)
Definition cloth.cpp:463
sceVu0FVECTOR home[16][16]
Definition cloth.hpp:43
sceVu0FVECTOR normal_grid[16][16]
Definition cloth.hpp:48
sceVu0FVECTOR last_position
Definition cloth.hpp:41
float floor_y
Definition cloth.hpp:33
float wind_effect
Definition cloth.hpp:35
void Draw()
Definition cloth.cpp:19
int init_20
Definition cloth.hpp:23
void Step(int step)
Definition cloth.cpp:144
int num_j
Definition cloth.hpp:26
int polygon_divide[16]
Definition cloth.hpp:50
int stop
Definition cloth.hpp:28
void InitParam()
Definition cloth.cpp:608
sceVu0FVECTOR last[16][16]
Definition cloth.hpp:45
sceVu0FVECTOR rest[16][16]
Definition cloth.hpp:46
u_int vu_size
Definition cloth.hpp:22
int mask[16][16]
Definition cloth.hpp:51
sceVu0FVECTOR gravity
Definition cloth.hpp:38
void * wind
Definition cloth.hpp:34
CFrame * frame
Definition cloth.hpp:29
sceVu0FVECTOR follow
Definition cloth.hpp:39
CBound * bound
Definition cloth.hpp:31
sceVu0FVECTOR texture_coord[16][16]
Definition cloth.hpp:49
sceVu0FVECTOR position
Definition cloth.hpp:42
u_char * base
Definition dataalloc.hpp:24
char clip_enable
Definition frame.hpp:29
char program_option
Definition frame.hpp:32
char fog_enable
Definition frame.hpp:33
void SetVisual(CVisualVu1 *visual)
Definition frame.cpp:1333
sceVu0FVECTOR corner[8]
Definition frame.hpp:64
sceVu0FVECTOR min
Definition frame.hpp:63
sceVu0FVECTOR max
Definition frame.hpp:62
u_long tex1
Definition texture.hpp:58
u_long tex0
Definition texture.hpp:57
virtual int DrawVu1(u_int *packet, float(*matrix)[4], RenderInfo *info, VU1_PROGRAM program, u_long128 *draw_state, int unknown1, int unknown2)
virtual void Initialize()
virtual void Initialize()
Definition wind.hpp:12
int uv[3]
Definition mdt.hpp:20
int vertex_ofs
Definition mdt.hpp:14
int mesh_ofs
Definition mdt.hpp:19
int info_ofs
Definition mdt.hpp:21
sceVu0FVECTOR diffuse
Definition mdt.hpp:28
char texture[44]
Definition mdt.hpp:32
sceVu0FVECTOR specular
Definition mdt.hpp:30
sceVu0FVECTOR ambient
Definition mdt.hpp:29