mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-08 16:53:49 +08:00
Creating the opportunity to change camera attributes from python layer
This commit is contained in:
parent
ecc5a359c1
commit
869361d126
@ -1,6 +1,7 @@
|
|||||||
// Released under the MIT License. See LICENSE for details.
|
// Released under the MIT License. See LICENSE for details.
|
||||||
|
|
||||||
#include "ballistica/python/methods/python_methods_graphics.h"
|
#include "ballistica/python/methods/python_methods_graphics.h"
|
||||||
|
#include "ballistica/graphics/camera.h"
|
||||||
|
|
||||||
#include "ballistica/game/game.h"
|
#include "ballistica/game/game.h"
|
||||||
#include "ballistica/graphics/graphics.h"
|
#include "ballistica/graphics/graphics.h"
|
||||||
@ -16,6 +17,84 @@ namespace ballistica {
|
|||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma ide diagnostic ignored "hicpp-signed-bitwise"
|
#pragma ide diagnostic ignored "hicpp-signed-bitwise"
|
||||||
|
|
||||||
|
auto PyGetCameraPosition(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
|
-> PyObject* {
|
||||||
|
BA_PYTHON_TRY;
|
||||||
|
Platform::SetLastPyCall("get_camera_position");
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
float z = 0.0f;
|
||||||
|
Camera* cam = g_graphics->camera();
|
||||||
|
cam->get_position(&x, &y, &z);
|
||||||
|
return Py_BuildValue("(fff)", x, y, z);
|
||||||
|
BA_PYTHON_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PyGetCameraTarget(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
|
-> PyObject* {
|
||||||
|
BA_PYTHON_TRY;
|
||||||
|
Platform::SetLastPyCall("get_camera_target");
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
float z = 0.0f;
|
||||||
|
Camera* cam = g_graphics->camera();
|
||||||
|
cam->target_smoothed(&x, &y, &z);
|
||||||
|
return Py_BuildValue("(fff)", x, y, z);
|
||||||
|
BA_PYTHON_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PySetCameraPosition(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
|
-> PyObject* {
|
||||||
|
BA_PYTHON_TRY;
|
||||||
|
Platform::SetLastPyCall("set_camera_position");
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
float z = 0.0f;
|
||||||
|
static const char* kwlist[] = {"x", "y", "z", nullptr};
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, keywds, "fff",
|
||||||
|
const_cast<char**>(kwlist), &x, &y, &z)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
assert(g_game);
|
||||||
|
g_graphics->camera()->SetPosition(x, y, z);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
BA_PYTHON_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PySetCameraTarget(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
|
-> PyObject* {
|
||||||
|
BA_PYTHON_TRY;
|
||||||
|
Platform::SetLastPyCall("set_camera_target");
|
||||||
|
float x = 0.0f;
|
||||||
|
float y = 0.0f;
|
||||||
|
float z = 0.0f;
|
||||||
|
static const char* kwlist[] = { "x", "y", "z", nullptr };
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, keywds, "fff",
|
||||||
|
const_cast<char**>(kwlist), &x, &y, &z)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
assert(g_game);
|
||||||
|
g_graphics->camera()->SetTarget(x, y, z);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
BA_PYTHON_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto PySetCameraManual(PyObject* self, PyObject* args, PyObject* keywds)
|
||||||
|
-> PyObject* {
|
||||||
|
BA_PYTHON_TRY;
|
||||||
|
Platform::SetLastPyCall("set_camera_manual");
|
||||||
|
bool value = false;
|
||||||
|
static const char* kwlist[] = {"value", nullptr};
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, keywds, "b",
|
||||||
|
const_cast<char**>(kwlist), &value)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
assert(g_game);
|
||||||
|
g_graphics->camera()->SetManual(value);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
BA_PYTHON_CATCH;
|
||||||
|
}
|
||||||
|
|
||||||
auto PyCharStr(PyObject* self, PyObject* args, PyObject* keywds) -> PyObject* {
|
auto PyCharStr(PyObject* self, PyObject* args, PyObject* keywds) -> PyObject* {
|
||||||
BA_PYTHON_TRY;
|
BA_PYTHON_TRY;
|
||||||
Platform::SetLastPyCall("charstr");
|
Platform::SetLastPyCall("charstr");
|
||||||
@ -232,6 +311,36 @@ auto PythonMethodsGraphics::GetMethods() -> std::vector<PyMethodDef> {
|
|||||||
"Return the currently selected display resolution for fullscreen\n"
|
"Return the currently selected display resolution for fullscreen\n"
|
||||||
"display. Returns None if resolutions cannot be directly set."},
|
"display. Returns None if resolutions cannot be directly set."},
|
||||||
|
|
||||||
|
{"get_camera_position", (PyCFunction)PyGetCameraPosition,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
"get_camera_position() -> tuple[float, float, float]\n"
|
||||||
|
"\n"
|
||||||
|
"(internal)"},
|
||||||
|
|
||||||
|
{"get_camera_target", (PyCFunction)PyGetCameraTarget,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
"get_camera_target() -> tuple[float, float, float]\n"
|
||||||
|
"\n"
|
||||||
|
"(internal)"},
|
||||||
|
|
||||||
|
{"set_camera_position", (PyCFunction)PySetCameraPosition,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
"set_camera_position(x: float, y: float, z: float) -> None\n"
|
||||||
|
"\n"
|
||||||
|
"(internal)"},
|
||||||
|
|
||||||
|
{"set_camera_target", (PyCFunction)PySetCameraTarget,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
"set_camera_target(x: float, y: float, z: float) -> None\n"
|
||||||
|
"\n"
|
||||||
|
"(internal)"},
|
||||||
|
|
||||||
|
{"set_camera_manual", (PyCFunction)PySetCameraManual,
|
||||||
|
METH_VARARGS | METH_KEYWORDS,
|
||||||
|
"set_camera_manual(value: bool) -> None\n"
|
||||||
|
"\n"
|
||||||
|
"(internal)"},
|
||||||
|
|
||||||
{"has_gamma_control", PyHasGammaControl, METH_VARARGS,
|
{"has_gamma_control", PyHasGammaControl, METH_VARARGS,
|
||||||
"has_gamma_control() -> bool\n"
|
"has_gamma_control() -> bool\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user