Compare commits
2 commits
de7778b147
...
b9a48a85b0
| Author | SHA1 | Date | |
|---|---|---|---|
| b9a48a85b0 | |||
| 3ce7de6134 |
6 changed files with 28 additions and 12 deletions
|
|
@ -247,30 +247,30 @@ struct mat4 {
|
|||
// Perspective projection matrix
|
||||
// fov: vertical field of view in radians
|
||||
// aspect: width / height
|
||||
// near, far: clipping planes
|
||||
static mat4 perspective(float fov, float aspect, float near, float far) {
|
||||
// nearPlane, farPlane: clipping planes
|
||||
static mat4 perspective(float fov, float aspect, float nearPlane, float farPlane) {
|
||||
mat4 result;
|
||||
float tanHalfFov = std::tan(fov / 2.0f);
|
||||
|
||||
result.at(0, 0) = 1.0f / (aspect * tanHalfFov);
|
||||
result.at(1, 1) = 1.0f / tanHalfFov;
|
||||
result.at(2, 2) = -(far + near) / (far - near);
|
||||
result.at(2, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
|
||||
result.at(2, 3) = -1.0f;
|
||||
result.at(3, 2) = -(2.0f * far * near) / (far - near);
|
||||
result.at(3, 2) = -(2.0f * farPlane * nearPlane) / (farPlane - nearPlane);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Orthographic projection matrix
|
||||
static mat4 ortho(float left, float right, float bottom, float top, float near, float far) {
|
||||
static mat4 ortho(float left, float right, float bottom, float top, float nearPlane, float farPlane) {
|
||||
mat4 result = identity();
|
||||
|
||||
result.at(0, 0) = 2.0f / (right - left);
|
||||
result.at(1, 1) = 2.0f / (top - bottom);
|
||||
result.at(2, 2) = -2.0f / (far - near);
|
||||
result.at(2, 2) = -2.0f / (farPlane - nearPlane);
|
||||
result.at(3, 0) = -(right + left) / (right - left);
|
||||
result.at(3, 1) = -(top + bottom) / (top - bottom);
|
||||
result.at(3, 2) = -(far + near) / (far - near);
|
||||
result.at(3, 2) = -(farPlane + nearPlane) / (farPlane - nearPlane);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ PyObject* VoxelPoint::get_bool_member(PyVoxelPointObject* self, void* closure)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
long member = reinterpret_cast<long>(closure);
|
||||
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||
bool value = false;
|
||||
|
||||
switch (member) {
|
||||
|
|
@ -82,7 +82,7 @@ int VoxelPoint::set_bool_member(PyVoxelPointObject* self, PyObject* value, void*
|
|||
}
|
||||
|
||||
bool newValue = PyObject_IsTrue(value);
|
||||
long member = reinterpret_cast<long>(closure);
|
||||
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||
|
||||
switch (member) {
|
||||
case VOXEL_WALKABLE:
|
||||
|
|
@ -111,7 +111,7 @@ PyObject* VoxelPoint::get_float_member(PyVoxelPointObject* self, void* closure)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
long member = reinterpret_cast<long>(closure);
|
||||
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||
float value = 0.0f;
|
||||
|
||||
switch (member) {
|
||||
|
|
@ -146,7 +146,7 @@ int VoxelPoint::set_float_member(PyVoxelPointObject* self, PyObject* value, void
|
|||
return -1;
|
||||
}
|
||||
|
||||
long member = reinterpret_cast<long>(closure);
|
||||
intptr_t member = reinterpret_cast<intptr_t>(closure);
|
||||
|
||||
switch (member) {
|
||||
case VOXEL_HEIGHT:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
// McRogueFace version string (#164)
|
||||
#define MCRFPY_VERSION "0.2.4-prerelease-7drl2026"
|
||||
#define MCRFPY_VERSION "0.2.5-prerelease-7drl2026"
|
||||
|
|
|
|||
|
|
@ -503,6 +503,10 @@ public:
|
|||
size_ = Vector2u(256, 256);
|
||||
return true;
|
||||
}
|
||||
bool loadFromImage(const Image& image) {
|
||||
size_ = image.getSize();
|
||||
return true;
|
||||
}
|
||||
Vector2u getSize() const { return size_; }
|
||||
void setSmooth(bool smooth) {}
|
||||
bool isSmooth() const { return false; }
|
||||
|
|
|
|||
|
|
@ -1100,6 +1100,17 @@ bool Texture::loadFromMemory(const void* data, size_t size) {
|
|||
return textureId_ != 0;
|
||||
}
|
||||
|
||||
bool Texture::loadFromImage(const Image& image) {
|
||||
if (textureId_) {
|
||||
SDL2Renderer::getInstance().deleteTexture(textureId_);
|
||||
}
|
||||
auto imgSize = image.getSize();
|
||||
size_ = imgSize;
|
||||
textureId_ = SDL2Renderer::getInstance().createTexture(
|
||||
imgSize.x, imgSize.y, image.getPixelsPtr());
|
||||
return textureId_ != 0;
|
||||
}
|
||||
|
||||
void Texture::setSmooth(bool smooth) {
|
||||
smooth_ = smooth;
|
||||
if (textureId_) {
|
||||
|
|
|
|||
|
|
@ -669,6 +669,7 @@ public:
|
|||
bool create(unsigned int width, unsigned int height); // Implemented in SDL2Renderer.cpp
|
||||
bool loadFromFile(const std::string& filename); // Implemented in SDL2Renderer.cpp
|
||||
bool loadFromMemory(const void* data, size_t size); // Implemented in SDL2Renderer.cpp
|
||||
bool loadFromImage(const Image& image); // Implemented in SDL2Renderer.cpp
|
||||
|
||||
Vector2u getSize() const { return size_; }
|
||||
void setSize(unsigned int width, unsigned int height) { size_ = Vector2u(width, height); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue