19 #include "RelativeIHudDrawable.h" 23 relativeTo(relativeTo), toDraw(toDraw), worldCamera(worldCamera) {}
25 void RelativeIHudDrawable::render(
ShaderProgram *shaderProgram, chag::float4x4 *projectionMatrix) {
27 chag::float3 drawableRelativePosition = toDraw->relativePosition;
28 chag::float4x4 screenPos = worldCamera->getProjectionMatrix()
29 * worldCamera->getViewMatrix()
30 * relativeTo->getModelMatrix();
32 int w = Globals::get(Globals::WINDOW_WIDTH);
33 int h = Globals::get(Globals::WINDOW_HEIGHT);
35 float x = (screenPos.c4.x / screenPos.c4.w + 1.0f) * w / 2.0f;
36 float y = h - (screenPos.c4.y / screenPos.c4.w + 1.0f) * h / 2.0f;
38 chag::float3 tempRelativeVector = drawableRelativePosition + chag::make_vector(roundf(x), -roundf(y), 0.0f);
40 toDraw->relativePosition = tempRelativeVector;
41 toDraw->render(shaderProgram, projectionMatrix);
42 toDraw->relativePosition = drawableRelativePosition;
Class for maintaining OpenGL shader programs.
A class for containing all information about a object in the game world.