1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 11:22:45 +01:00

Use ObjectRenderer to draw Goals and Arrows

This commit is contained in:
Daniel Evans 2016-09-12 00:15:22 +01:00
parent 462479b992
commit e1ab5b1f69
3 changed files with 50 additions and 126 deletions

View File

@ -210,40 +210,6 @@ GameRenderer::GameRenderer(Logger* log, GameData* _data)
ssRectSize = glGetUniformLocation(ssRectProgram, "size"); ssRectSize = glGetUniformLocation(ssRectProgram, "size");
ssRectOffset = glGetUniformLocation(ssRectProgram, "offset"); ssRectOffset = glGetUniformLocation(ssRectProgram, "offset");
const static int cylsegments = 16;
std::vector<Model::GeometryVertex> cylverts;
for (int s = 0; s < cylsegments; ++s) {
float theta = (2.f * glm::pi<float>() / cylsegments) * (s + 0);
float gamma = (2.f * glm::pi<float>() / cylsegments) * (s + 1);
glm::vec2 p0(glm::sin(theta), glm::cos(theta));
glm::vec2 p1(glm::sin(gamma), glm::cos(gamma));
p0 *= 0.5f;
p1 *= 0.5f;
cylverts.push_back({glm::vec3(p0, 2.f), glm::vec3(),
glm::vec2(0.45f, 0.6f),
glm::u8vec4(255, 255, 255, 50)});
cylverts.push_back({glm::vec3(p0, -1.f), glm::vec3(),
glm::vec2(0.45f, 0.4f),
glm::u8vec4(255, 255, 255, 150)});
cylverts.push_back({glm::vec3(p1, 2.f), glm::vec3(),
glm::vec2(0.55f, 0.6f),
glm::u8vec4(255, 255, 255, 50)});
cylverts.push_back({glm::vec3(p0, -1.f), glm::vec3(),
glm::vec2(0.45f, 0.4f),
glm::u8vec4(255, 255, 255, 150)});
cylverts.push_back({glm::vec3(p1, -1.f), glm::vec3(),
glm::vec2(0.55f, 0.4f),
glm::u8vec4(255, 255, 255, 150)});
cylverts.push_back({glm::vec3(p1, 2.f), glm::vec3(),
glm::vec2(0.55f, 0.6f),
glm::u8vec4(255, 255, 255, 50)});
}
cylinderGeometry.uploadVertices<Model::GeometryVertex>(cylverts);
cylinderBuffer.addGeometry(&cylinderGeometry);
cylinderBuffer.setFaceType(GL_TRIANGLES);
} }
GameRenderer::~GameRenderer() { GameRenderer::~GameRenderer() {
@ -343,6 +309,50 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
for (auto object : world->allObjects) { for (auto object : world->allObjects) {
objectRenderer.buildRenderList(object, renderList); objectRenderer.buildRenderList(object, renderList);
} }
// Area indicators
/// @todo this shouldn't be static here
/// @todo what are zonecyla / zonecylb for?
static auto sphereModel = world->data->loadClump("zonecyla.dff");
for (auto& i : world->getAreaIndicators()) {
glm::mat4 m(1.f);
m = glm::translate(m, i.position);
m = glm::scale(
m, glm::vec3(i.radius +
0.15f * glm::sin(_renderWorld->getGameTime() * 5.f)));
objectRenderer.renderFrame(sphereModel, sphereModel->frames[0], m,
nullptr, 1.f, renderList);
}
// Render arrows above anything that isn't radar only (or hidden)
/// @todo this shouldn't be static here
static auto arrowModel = world->data->loadClump("arrow.dff");
for (auto& blip : world->state->radarBlips) {
auto dm = blip.second.display;
if (dm == BlipData::Hide || dm == BlipData::RadarOnly) {
continue;
}
glm::mat4 model;
if (blip.second.target > 0) {
auto object = world->getBlipTarget(blip.second);
if (object) {
model = object->getTimeAdjustedTransform(_renderAlpha);
}
} else {
model = glm::translate(model, blip.second.coord);
}
float a = world->getGameTime() * glm::pi<float>();
model = glm::translate(model,
glm::vec3(0.f, 0.f, 2.5f + glm::sin(a) * 0.5f));
model = glm::rotate(model, a, glm::vec3(0.f, 0.f, 1.f));
model = glm::scale(model, glm::vec3(1.5f, 1.5f, 1.5f));
objectRenderer.renderFrame(arrowModel, arrowModel->frames[0], model,
nullptr, 1.f, renderList);
}
RW_PROFILE_END(); RW_PROFILE_END();
renderer->pushDebugGroup("Objects"); renderer->pushDebugGroup("Objects");
@ -366,59 +376,6 @@ void GameRenderer::renderWorld(GameWorld* world, const ViewCamera& camera,
RW_PROFILE_END(); RW_PROFILE_END();
/// @todo this shouldn't be static here
static auto arrowModel = world->data->loadClump("arrow.dff");
// Render arrows above anything that isn't radar only (or hidden)
if (arrowModel) {
auto arrowTex = world->data->textures[{"copblue", ""}];
auto arrowFrame = arrowModel->findFrame("arrow");
for (auto& blip : world->state->radarBlips) {
auto dm = blip.second.display;
if (dm == BlipData::Hide || dm == BlipData::RadarOnly) {
continue;
}
glm::mat4 model;
if (blip.second.target > 0) {
auto object = world->getBlipTarget(blip.second);
if (object) {
model = object->getTimeAdjustedTransform(_renderAlpha);
}
} else {
model = glm::translate(model, blip.second.coord);
}
float a = world->getGameTime() * glm::pi<float>();
model = glm::translate(
model, glm::vec3(0.f, 0.f, 2.5f + glm::sin(a) * 0.5f));
model = glm::rotate(model, a, glm::vec3(0.f, 0.f, 1.f));
model = glm::scale(model, glm::vec3(1.5f, 1.5f, 1.5f));
Renderer::DrawParameters dp;
dp.textures = {arrowTex->getName()};
dp.ambient = 1.f;
dp.colour = glm::u8vec4(255, 255, 255, 255);
auto geom = arrowModel->geometries[arrowFrame->getGeometries()[0]];
Model::SubGeometry& sg = geom->subgeom[0];
dp.start = sg.start;
dp.count = sg.numIndices;
dp.diffuse = 1.f;
renderer->draw(model, &geom->dbuff, dp);
}
}
// Draw goal indicators
glDepthMask(GL_FALSE);
renderer->useProgram(particleProg);
for (auto& i : world->getAreaIndicators()) {
renderAreaIndicator(&i);
}
glDepthMask(GL_TRUE);
renderer->pushDebugGroup("Water"); renderer->pushDebugGroup("Water");
water.render(this, world); water.render(this, world);
@ -582,33 +539,6 @@ void GameRenderer::renderGeometry(Model* model, size_t g,
} }
} }
#define GOAL_RINGS 3
void GameRenderer::renderAreaIndicator(const AreaIndicatorInfo* info) {
glm::mat4 m(1.f);
m = glm::translate(m, info->position);
glm::vec3 scale =
info->radius + 0.15f * glm::sin(_renderWorld->getGameTime() * 5.f);
Renderer::DrawParameters dp;
dp.textures = {data->findTexture("cloud1")->getName()};
dp.ambient = 1.f;
dp.colour = glm::u8vec4(50, 100, 255, 128);
dp.start = 0;
dp.count = cylinderGeometry.getCount();
dp.diffuse = 1.f;
for (int i = 0; i < GOAL_RINGS; i++) {
glm::mat4 mt = m;
glm::vec3 final = scale * glm::pow(0.9f, i + 1.0f);
mt = glm::scale(mt, glm::vec3(final.x, final.y, 1.0f + i * 0.1f));
int reverse = (i % 2 ? 1 : -1);
mt = glm::rotate(mt, reverse * _renderWorld->getGameTime() * 0.5f,
glm::vec3(0.f, 0.f, 1.f));
renderer->drawArrays(mt, &cylinderBuffer, dp);
}
}
void GameRenderer::renderEffects(GameWorld* world) { void GameRenderer::renderEffects(GameWorld* world) {
renderer->useProgram(particleProg); renderer->useProgram(particleProg);

View File

@ -117,9 +117,6 @@ public:
DrawBuffer skyDbuff; DrawBuffer skyDbuff;
GeometryBuffer skyGbuff; GeometryBuffer skyGbuff;
DrawBuffer cylinderBuffer;
GeometryBuffer cylinderGeometry;
GameData* getData() const { GameData* getData() const {
return data; return data;
} }
@ -164,9 +161,6 @@ public:
void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix, void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix,
float opacity, GameObject* = nullptr); float opacity, GameObject* = nullptr);
/** Renders the area indicator */
void renderAreaIndicator(const AreaIndicatorInfo* info);
/** method for rendering AI debug information */ /** method for rendering AI debug information */
void renderPaths(); void renderPaths();

View File

@ -35,6 +35,12 @@ public:
*/ */
void buildRenderList(GameObject* object, RenderList& outList); void buildRenderList(GameObject* object, RenderList& outList);
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix,
GameObject* object, float opacity, RenderList& outList);
void renderGeometry(Model* model, size_t g, const glm::mat4& modelMatrix,
float opacity, GameObject* object, RenderList& outList);
private: private:
GameWorld* m_world; GameWorld* m_world;
const ViewCamera& m_camera; const ViewCamera& m_camera;
@ -47,12 +53,6 @@ private:
void renderPickup(PickupObject* pickup, RenderList& outList); void renderPickup(PickupObject* pickup, RenderList& outList);
void renderCutsceneObject(CutsceneObject* cutscene, RenderList& outList); void renderCutsceneObject(CutsceneObject* cutscene, RenderList& outList);
void renderProjectile(ProjectileObject* projectile, RenderList& outList); void renderProjectile(ProjectileObject* projectile, RenderList& outList);
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix,
GameObject* object, float opacity, RenderList& outList);
void renderGeometry(Model* model, size_t g, const glm::mat4& modelMatrix,
float opacity, GameObject* object, RenderList& outList);
}; };
#endif #endif