Skip to content

Commit fe43dcd

Browse files
committed
Basic moon added.
1 parent cdc07cd commit fe43dcd

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

source/client/graphics/Sun.cpp renamed to source/client/graphics/CelestialObject.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@
2424
*
2525
* =====================================================================================
2626
*/
27+
#include <gk/core/GameClock.hpp>
2728
#include <gk/gl/GLCheck.hpp>
28-
#include <gk/graphics/Color.hpp>
2929

30-
#include "Sun.hpp"
30+
#include "CelestialObject.hpp"
3131
#include "Vertex.hpp"
3232

33-
Sun::Sun() {
33+
CelestialObject::CelestialObject() {
3434
updateVertexBuffer();
3535
}
3636

37-
void Sun::updateVertexBuffer() const {
37+
void CelestialObject::updateVertexBuffer() const {
3838
float width = 20.f;
3939
float height = 20.f;
4040
Vertex vertices[4] = {
@@ -45,21 +45,21 @@ void Sun::updateVertexBuffer() const {
4545
{{0, width, height, -1}},
4646
};
4747

48-
gk::Color color = gk::Color::Yellow;
4948
for (u8 i = 0 ; i < 4 ; ++i) {
50-
vertices[i].color[0] = color.r;
51-
vertices[i].color[1] = color.g;
52-
vertices[i].color[2] = color.b;
53-
vertices[i].color[3] = color.a;
49+
vertices[i].color[0] = m_color.r;
50+
vertices[i].color[1] = m_color.g;
51+
vertices[i].color[2] = m_color.b;
52+
vertices[i].color[3] = m_color.a;
5453
}
5554

5655
gk::VertexBuffer::bind(&m_vbo);
5756
m_vbo.setData(sizeof(vertices), vertices, GL_STATIC_DRAW);
5857
gk::VertexBuffer::bind(nullptr);
5958
}
6059

61-
void Sun::draw(gk::RenderTarget &target, gk::RenderStates states) const {
62-
// states.transform *= getTransform();
60+
void CelestialObject::draw(gk::RenderTarget &target, gk::RenderStates states) const {
61+
states.transform.rotate(fmod(gk::GameClock::getInstance().getTicks(true) / 1000.f, 360), {0, 1, 0});
62+
states.transform *= getTransform();
6363

6464
states.vertexAttributes = VertexAttribute::All;
6565

source/client/graphics/Sun.hpp renamed to source/client/graphics/CelestialObject.hpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,28 @@
2424
*
2525
* =====================================================================================
2626
*/
27-
#ifndef SUN_HPP_
28-
#define SUN_HPP_
27+
#ifndef CELESTIALOBJECT_HPP_
28+
#define CELESTIALOBJECT_HPP_
2929

3030
#include <gk/gl/Drawable.hpp>
3131
#include <gk/gl/Transformable.hpp>
3232
#include <gk/gl/VertexBuffer.hpp>
33+
#include <gk/graphics/Color.hpp>
3334

34-
class Sun : public gk::Drawable, public gk::Transformable {
35+
class CelestialObject : public gk::Drawable, public gk::Transformable {
3536
public:
36-
Sun();
37+
CelestialObject();
3738

38-
void updateVertexBuffer() const;
39+
void setColor(const gk::Color &color) { m_color = color; updateVertexBuffer(); }
3940

4041
private:
42+
void updateVertexBuffer() const;
43+
4144
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
4245

4346
gk::VertexBuffer m_vbo;
47+
48+
gk::Color m_color = gk::Color::White;
4449
};
4550

46-
#endif // SUN_HPP_
51+
#endif // CELESTIALOBJECT_HPP_

source/client/graphics/Skybox.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,23 @@
2424
*
2525
* =====================================================================================
2626
*/
27-
#include <gk/gl/GLCheck.hpp>
28-
#include <gk/graphics/Color.hpp>
29-
30-
#include <gk/core/GameClock.hpp>
31-
3227
#include "Skybox.hpp"
3328
#include "Vertex.hpp"
3429

3530
Skybox::Skybox(gk::Camera &camera) : m_camera(camera) {
36-
setPosition(150, -10, 0);
31+
m_sun.setColor(gk::Color::Yellow);
32+
m_sun.setPosition(150, -10, 0);
33+
34+
m_moon.setColor(gk::Color::White);
35+
m_moon.setPosition(-150, -10, 0);
3736
}
3837

3938
void Skybox::draw(gk::RenderTarget &target, gk::RenderStates states) const {
4039
// Subtract the camera position - see comment in ClientWorld::draw()
4140
gk::Vector3d cameraPosition = m_camera.getDPosition();
42-
states.transform.rotate(fmod(gk::GameClock::getInstance().getTicks(true) / 1000.f, 360), {0, 1, 0});
43-
states.transform.translate(getPosition().x - cameraPosition.x, getPosition().y - cameraPosition.y, getPosition().z - cameraPosition.z);
41+
states.transform.translate(-cameraPosition.x, -cameraPosition.y, -cameraPosition.z);
4442

4543
target.draw(m_sun, states);
44+
target.draw(m_moon, states);
4645
}
4746

source/client/graphics/Skybox.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
#include <gk/gl/Camera.hpp>
3131

32-
#include "Sun.hpp"
32+
#include "CelestialObject.hpp"
3333

3434
class Skybox : public gk::Drawable, public gk::Transformable {
3535
public:
@@ -42,7 +42,8 @@ class Skybox : public gk::Drawable, public gk::Transformable {
4242

4343
gk::VertexBuffer m_sunVBO;
4444

45-
Sun m_sun;
45+
CelestialObject m_sun;
46+
CelestialObject m_moon;
4647
};
4748

4849
#endif // SKYBOX_HPP_

0 commit comments

Comments
 (0)