DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
healeffect.cpp
1#include "healeffect.hpp"
2
3#include <libvu0.h>
4
5#include <cmath>
6#include <cstdio>
7#include <cstdlib>
8
9#include "character.hpp"
10#include "dun/gameloop.hpp"
11#include "hitmark.hpp"
12#include "shot_freefuncs.hpp"
13#include "texture.hpp"
14
15void CHealEffect::Set(float *world) {
16 sceVu0CopyVector(this->position, world);
17 this->active = true;
18
19 for (int i = 0; i < 32; i++) {
20 this->radius[i] = 3.0f + 6.0f * (float) rand() / 2.1474836e9f;
21 this->angle[i] = TWO_PI * (float) rand() / 2.1474836e9f - PI;
22 this->angular_velocity[i] = 0.034906585f * (5.0f * (float) rand() / 2.1474836e9f);
23 this->size[i] = 0.4f + 0.6f * (float) rand() / 2.1474836e9f;
24 this->alpha[i] = 0.0f;
25 // The drawn phase is the one below; the value rolled here is discarded.
26 this->phase[i] = 0.1f * (float) rand() / 2.1474836e9f;
27 this->phase[i] = 0.0f;
28 this->particle_offset[i][1] = 2.0f + 10.0f * (float) rand() / 2.1474836e9f;
29 }
30}
31
33 if (this->active != 0) {
34 float offset[4] = {0.0f, 0.0f, 1.0f, 1.0f};
35 sceVu0FMATRIX unit;
36 sceVu0FMATRIX rotation;
37 int expired = 0;
38
39 for (int i = 0; i < 32; i++) {
40 if (this->phase[i] < PI) {
41 // The phase runs a half sine, so the particle rises and fades once.
42 float rise = sinf(this->phase[i]);
43
44 this->phase[i] += 0.052359879f;
45 this->alpha[i] = 128.0f * rise - 32.0f;
46
47 if (this->alpha[i] <= 0.0f) {
48 this->alpha[i] = 0.0f;
49 }
50
51 this->angle[i] += this->angular_velocity[i];
52
53 if (this->angle[i] > PI) {
54 this->angle[i] -= TWO_PI;
55 }
56
57 if (this->angle[i] < -PI) {
58 this->angle[i] += TWO_PI;
59 }
60
61 offset[0] = 0.0f;
62 offset[1] = this->particle_offset[i][1] + 0.3f * (float) rand() / 2.1474836e9f;
63 offset[2] = rise * this->radius[i];
64 sceVu0UnitMatrix(unit);
65 sceVu0RotMatrixY(rotation, unit, this->angle[i]);
66 sceVu0ApplyMatrix(offset, rotation, offset);
67 sceVu0CopyVector(this->particle_offset[i], offset);
68 } else {
69 expired++;
70
71 if (expired == 32) {
72 this->active = false;
73 printf("emd!!\n");
74 }
75 }
76 }
77 }
78}
79
81 if (this->active != 0) {
82 float world[4];
83 // Unread; Step builds its particle offsets from the same template.
84 float offset[4] = {0.0f, 0.0f, 1.0f, 1.0f};
85 CTexture *texture = TexManager.GetTexture(HealEffectTextureName, -1);
86
87 sceVu0CopyVector(this->position, CharaMain.pos);
88
89 for (int i = 0; i < 32; i++) {
90 if (this->phase[i] < PI) {
91 world[0] = this->position[0] + this->particle_offset[i][0];
92 world[1] = this->position[1] + this->particle_offset[i][1];
93 world[2] = this->position[2] + this->particle_offset[i][2];
94 BtSet3DCellModel(world, texture, this->size[i], 0x10, 0, 0x20, 0x20, (int) this->alpha[i]);
95 }
96 }
97 }
98}
float radius[32]
float size[32]
float angular_velocity[32]
float angle[32]
float phase[32]
float alpha[32]
float particle_offset[32][4]
float position[4]
void Set(float *world)
float pos[4]
Definition object.hpp:18
char HealEffectTextureName[]