Added debugDrawCircle and refactored debugDrawSphere
parent
3e7c7d3acd
commit
7ce0b3c000
|
@ -66,6 +66,8 @@ CharacterEntity::~CharacterEntity() {
|
||||||
entity = nullptr;
|
entity = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float cur_time = 0.0f;
|
||||||
|
|
||||||
void CharacterEntity::update(float dt) {
|
void CharacterEntity::update(float dt) {
|
||||||
Vector3f controller_acceleration (
|
Vector3f controller_acceleration (
|
||||||
controller.direction[0] * cGroundAcceleration,
|
controller.direction[0] * cGroundAcceleration,
|
||||||
|
@ -105,7 +107,9 @@ void CharacterEntity::update(float dt) {
|
||||||
|
|
||||||
entity->mesh.updateMatrices(entity->transform.toMatrix());
|
entity->mesh.updateMatrices(entity->transform.toMatrix());
|
||||||
|
|
||||||
// gRenderer->drawDebugSphere (Vector3f (0.f, 0.f, 0.f), 0.2f);
|
cur_time += dt;
|
||||||
|
|
||||||
|
gRenderer->drawDebugSphere (Vector3f (0.f, 1.3 + sin(cur_time * 2.f), 0.f), 2.2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowCharacterPropertiesWindow (CharacterEntity* character) {
|
void ShowCharacterPropertiesWindow (CharacterEntity* character) {
|
||||||
|
|
|
@ -1621,46 +1621,29 @@ void Renderer::paintGL() {
|
||||||
line.colors.push_back(debugCommands[i].color);
|
line.colors.push_back(debugCommands[i].color);
|
||||||
|
|
||||||
line.UpdateBuffers();
|
line.UpdateBuffers();
|
||||||
} else if (debugCommands[i].type == DebugCommand::Sphere) {
|
} else if (debugCommands[i].type == DebugCommand::Circle) {
|
||||||
line.points.clear();
|
line.points.clear();
|
||||||
line.colors.clear();
|
line.colors.clear();
|
||||||
|
float radius = debugCommands[i].radius;
|
||||||
float radius = debugCommands[i].to[0];
|
|
||||||
float c,s,angle;
|
float c,s,angle;
|
||||||
const int cNumSegments = 64;
|
|
||||||
|
|
||||||
// circle in X-Y plane
|
// construct an orthogonal vector from the normal.
|
||||||
|
Vector3f plane1 (
|
||||||
|
debugCommands[i].to[1] - debugCommands[i].to[2],
|
||||||
|
debugCommands[i].to[0],
|
||||||
|
-debugCommands[i].to[0]
|
||||||
|
);
|
||||||
|
plane1.normalize();
|
||||||
|
Vector3f plane2 = debugCommands[i].to.cross(plane1);
|
||||||
|
|
||||||
|
const int cNumSegments = 64;
|
||||||
for (uint32_t j = 0; j < cNumSegments; j++) {
|
for (uint32_t j = 0; j < cNumSegments; j++) {
|
||||||
angle = M_PI * 0.5f + 2. * M_PI * static_cast<float>(j) / static_cast<float>(cNumSegments - 1);
|
angle = M_PI * 0.5f + 2. * M_PI * static_cast<float>(j) / static_cast<float>(cNumSegments - 1);
|
||||||
|
|
||||||
s = sin(angle) * radius;
|
s = sin(angle) * radius;
|
||||||
c = cos(angle) * radius;
|
c = cos(angle) * radius;
|
||||||
|
|
||||||
line.points.push_back(Vector3f(s, c, 0));
|
line.points.push_back(debugCommands[i].from + plane1 * s + plane2 * c);
|
||||||
line.colors.push_back(debugCommands[i].color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// circle in X-Z plane (note: we draw the circle an
|
|
||||||
// additional 90 degrees so that we can directly start
|
|
||||||
// the last circle.
|
|
||||||
for (uint32_t j = 0; j < cNumSegments; j++) {
|
|
||||||
angle = M_PI * 0.5f + 2.5 * M_PI * static_cast<float>(j) / static_cast<float>(cNumSegments - 1);
|
|
||||||
|
|
||||||
s = sin(angle) * radius;
|
|
||||||
c = cos(angle) * radius;
|
|
||||||
|
|
||||||
line.points.push_back(Vector3f(s, 0, c));
|
|
||||||
line.colors.push_back(debugCommands[i].color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// circle in Y-Z plane
|
|
||||||
for (uint32_t j = 0; j < cNumSegments; j++) {
|
|
||||||
angle = M_PI + 2. * M_PI * static_cast<float>(j) / static_cast<float>(cNumSegments - 1);
|
|
||||||
|
|
||||||
s = sin(angle) * radius;
|
|
||||||
c = cos(angle) * radius;
|
|
||||||
|
|
||||||
line.points.push_back(Vector3f(0, s, c));
|
|
||||||
line.colors.push_back(debugCommands[i].color);
|
line.colors.push_back(debugCommands[i].color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1832,6 +1815,7 @@ void Renderer::drawDebugLine (
|
||||||
const Vector3f &to,
|
const Vector3f &to,
|
||||||
const Vector3f &color) {
|
const Vector3f &color) {
|
||||||
DebugCommand cmd;
|
DebugCommand cmd;
|
||||||
|
|
||||||
cmd.type = DebugCommand::Line;
|
cmd.type = DebugCommand::Line;
|
||||||
cmd.from = from;
|
cmd.from = from;
|
||||||
cmd.to = to;
|
cmd.to = to;
|
||||||
|
@ -1850,17 +1834,40 @@ void Renderer::drawDebugAxes (
|
||||||
drawDebugLine (pos, pos + Vector3f (orientation.block<3,1>(0,2)) * scale, Vector3f (0.f, 0.f, 1.f));
|
drawDebugLine (pos, pos + Vector3f (orientation.block<3,1>(0,2)) * scale, Vector3f (0.f, 0.f, 1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawDebugSphere (
|
void Renderer::drawDebugCircle (
|
||||||
const Vector3f &pos,
|
const Vector3f &pos,
|
||||||
float radius,
|
const Vector3f &normal,
|
||||||
|
const float radius,
|
||||||
const Vector4f &color) {
|
const Vector4f &color) {
|
||||||
DebugCommand cmd;
|
DebugCommand cmd;
|
||||||
cmd.type = DebugCommand::Sphere;
|
cmd.type = DebugCommand::Circle;
|
||||||
cmd.from = pos;
|
cmd.from = pos;
|
||||||
cmd.to[0] = radius;
|
cmd.to = normal;
|
||||||
cmd.color = color;
|
cmd.color = color;
|
||||||
|
cmd.radius = radius;
|
||||||
|
|
||||||
debugCommands.push_back(cmd);
|
debugCommands.push_back(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::drawDebugSphere (
|
||||||
|
const Vector3f &pos,
|
||||||
|
float radius,
|
||||||
|
const Vector4f &color) {
|
||||||
|
drawDebugCircle (
|
||||||
|
pos,
|
||||||
|
Vector3f (1.0f, 0.0f, 0.0f),
|
||||||
|
radius,
|
||||||
|
color);
|
||||||
|
drawDebugCircle (
|
||||||
|
pos,
|
||||||
|
Vector3f (0.0f, 1.0f, 0.0f),
|
||||||
|
radius,
|
||||||
|
color);
|
||||||
|
drawDebugCircle (
|
||||||
|
pos,
|
||||||
|
Vector3f (0.0f, 0.0f, 1.0f),
|
||||||
|
radius,
|
||||||
|
color);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -333,12 +333,14 @@ struct DebugCommand {
|
||||||
enum CommandType {
|
enum CommandType {
|
||||||
Line,
|
Line,
|
||||||
Axes,
|
Axes,
|
||||||
Sphere
|
Circle,
|
||||||
|
Invalid
|
||||||
};
|
};
|
||||||
|
|
||||||
CommandType type;
|
CommandType type;
|
||||||
|
|
||||||
Vector3f from;
|
Vector3f from;
|
||||||
|
float radius;
|
||||||
Vector3f to;
|
Vector3f to;
|
||||||
Vector4f color = Vector4f(1.f, 1.f, 1.f, 1.f);
|
Vector4f color = Vector4f(1.f, 1.f, 1.f, 1.f);
|
||||||
};
|
};
|
||||||
|
@ -413,9 +415,15 @@ struct Renderer {
|
||||||
const Matrix33f &orientation,
|
const Matrix33f &orientation,
|
||||||
const float &scale);
|
const float &scale);
|
||||||
|
|
||||||
|
void drawDebugCircle (
|
||||||
|
const Vector3f &pos,
|
||||||
|
const Vector3f &normal,
|
||||||
|
const float radius,
|
||||||
|
const Vector4f &color = Vector4f (1.f, 1.f, 1.f, 1.f));
|
||||||
|
|
||||||
void drawDebugSphere (
|
void drawDebugSphere (
|
||||||
const Vector3f &pos,
|
const Vector3f &pos,
|
||||||
float radius,
|
const float radius,
|
||||||
const Vector4f &color = Vector4f(1.f, 1.f, 1.f, 1.f));
|
const Vector4f &color = Vector4f(1.f, 1.f, 1.f, 1.f));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue