Made cursor work

This commit is contained in:
2025-12-07 20:09:41 +03:00
parent 44896ed0d9
commit 33fc237793
12 changed files with 136 additions and 30 deletions

View File

@@ -30,6 +30,7 @@ target_link_libraries(editor PRIVATE
OgreMain
GameData
)
target_include_directories(editor PUBLIC .)
add_executable(Editor main.cpp)
target_link_libraries(Editor PRIVATE

View File

@@ -21,6 +21,8 @@ createVertexColorNoDepthMaterial(const std::string &materialName)
// Disable dynamic lighting, so only vertex colors are used
pass->setLightingEnabled(false);
pass->setCullingMode(Ogre::CULL_NONE);
pass->setPolygonModeOverrideable(false);
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
// Set the material to use vertex colors for diffuse, ambient, and specular components
pass->setVertexColourTracking(Ogre::TVC_DIFFUSE | Ogre::TVC_AMBIENT |
@@ -28,11 +30,11 @@ createVertexColorNoDepthMaterial(const std::string &materialName)
// Disable depth checking (so it renders regardless of what's already in the depth buffer)
// pass->setDepthCheckEnabled(false);
pass->setDepthCheckEnabled(true);
pass->setDepthCheckEnabled(false);
// Disable depth writing (so subsequent objects are not occluded by this one)
// pass->setDepthWriteEnabled(false);
pass->setDepthWriteEnabled(true);
pass->setDepthWriteEnabled(false);
// Optional: Set scene blending to alpha blending if you use vertex alpha
// pass->setSceneBlending(Ogre::SBT_ALPHA_BLEND);
@@ -56,19 +58,21 @@ EditorGizmoModule::EditorGizmoModule(flecs::world &ecs)
ecs.observer<const EditorDebugMaterial, EditorGizmo>("SetupGizmo")
.event(flecs::OnSet)
.each([](const EditorDebugMaterial &mdbg, EditorGizmo &gizmo) {
const int size = 20;
gizmo.gizmo->setBufferUsage(Ogre::HBU_CPU_TO_GPU);
gizmo.gizmo->begin(mdbg.material,
Ogre::RenderOperation::OT_LINE_LIST);
gizmo.gizmo->position(Ogre::Vector3(0, 0, 0));
gizmo.gizmo->colour(Ogre::ColourValue(0, 0, 1, 1));
gizmo.gizmo->position(Ogre::Vector3(0, 0, 1));
gizmo.gizmo->position(Ogre::Vector3(0, 0, size));
gizmo.gizmo->colour(Ogre::ColourValue(0, 0, 1, 1));
gizmo.gizmo->position(Ogre::Vector3(0, 0, 0));
gizmo.gizmo->colour(Ogre::ColourValue(0, 1, 0, 1));
gizmo.gizmo->position(Ogre::Vector3(0, 1, 0));
gizmo.gizmo->position(Ogre::Vector3(0, size, 0));
gizmo.gizmo->colour(Ogre::ColourValue(0, 1, 0, 1));
gizmo.gizmo->position(Ogre::Vector3(0, 0, 0));
gizmo.gizmo->colour(Ogre::ColourValue(1, 0, 0, 1));
gizmo.gizmo->position(Ogre::Vector3(1, 0, 0));
gizmo.gizmo->position(Ogre::Vector3(size, 0, 0));
gizmo.gizmo->colour(Ogre::ColourValue(1, 0, 0, 1));
gizmo.gizmo->end();
});

View File

@@ -2,6 +2,8 @@
#include <Ogre.h>
#include "Components.h"
#include "GameData.h"
#include "PhysicsModule.h"
#include "EditorGizmoModule.h"
#include "EditorInputModule.h"
namespace ECS
@@ -115,6 +117,73 @@ EditorInputModule::EditorInputModule(flecs::world &ecs)
input.fast = true;
else
input.fast = false;
if (input.control & 256) {
/* click */
std::vector<Ogre::MovableObject *> objects;
Ogre::Viewport *viewport =
ECS::get<Camera>()
.mCamera->getViewport();
Ogre::Real nx =
static_cast<Ogre::Real>(
input.mouse_abs.x) /
(float)viewport->getActualWidth();
Ogre::Real ny =
static_cast<Ogre::Real>(
input.mouse_abs.y) /
(float)viewport->getActualHeight();
Ogre::Ray ray =
ECS::get<Camera>()
.mCamera->getCameraToViewportRay(
nx, ny);
Ogre::Vector3 position;
Ogre::Plane horizontalZeroPlane(
Ogre::Vector3::UNIT_Y, 0.0f);
std::cout << "ray: " << ray.getOrigin() << " "
<< ray.getDirection() << std::endl;
Ogre::RayTestResult ogreResult =
ray.intersects(horizontalZeroPlane);
if (ogreResult.first) {
position =
ray.getPoint(ogreResult.second);
Ogre::Vector3 position2;
bool hit = PhysicsModule::raycastQuery(
ray.getOrigin(),
ray.getPoint(2000.0f),
position2);
if (hit) {
float d1 =
ray.getOrigin()
.squaredDistance(
position);
float d2 =
ray.getOrigin()
.squaredDistance(
position2);
if (d2 < d1)
position = position2;
}
std::cout << "HIT!: " << position
<< std::endl;
ECS::get<EditorGizmo>()
.sceneNode->_setDerivedPosition(
position);
} else {
bool hit = PhysicsModule::raycastQuery(
ray.getOrigin(),
ray.getPoint(2000.0f),
position);
if (hit) {
std::cout
<< "HIT!: " << position
<< std::endl;
ECS::get<EditorGizmo>()
.sceneNode
->_setDerivedPosition(
position);
}
}
}
if (input.control & 512) {
if (input.mouse_moved) {
updateCameraGoal(camera,

View File

@@ -162,7 +162,7 @@ class KeyboardListener : public OgreBites::InputListener {
App *mApp;
uint32_t control;
ECS::Vector2 mouse;
ECS::Vector2 mouse, mouse_abs;
float wheel_y;
bool mouse_moved, wheel_moved;
float mInitDelay;
@@ -176,6 +176,7 @@ public:
, fast(false)
, control(0)
, mouse({ 0, 0 })
, mouse_abs({ 0, 0 })
, wheel_y(0.0f)
, mouse_moved(false)
, wheel_moved(false)
@@ -255,6 +256,8 @@ public:
{
mouse.x = evt.xrel;
mouse.y = evt.yrel;
mouse_abs.x = evt.x;
mouse_abs.y = evt.y;
mouse_moved = true;
/* no special mouse handling */
return true;
@@ -627,6 +630,7 @@ public:
mScnMgr->getRootSceneNode()->createChildSceneNode(
"EditorGizmoNode");
gizmoNode->attachObject(manualObj.get());
manualObj->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
ECS::get().set<ECS::EditorGizmo>({ manualObj, gizmoNode });
#if 0
ECS::get()
@@ -758,6 +762,7 @@ void KeyboardListener::frameRendered(const Ogre::FrameEvent &evt)
ECS::Input &input = ECS::get().get_mut<ECS::Input>();
input.control = control;
input.mouse = mouse;
input.mouse_abs = mouse_abs;
mouse.x = 0;
mouse.y = 0;
input.wheel_y = wheel_y;
@@ -769,6 +774,7 @@ void KeyboardListener::frameRendered(const Ogre::FrameEvent &evt)
ECS::Input &input = ECS::get().get_mut<ECS::Input>();
input.control = control;
input.mouse = mouse;
input.mouse_abs = mouse_abs;
mouse.x = 0;
mouse.y = 0;
input.wheel_y = wheel_y;