- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
目标:使用 OpenSceneGraph (OSG) 创建第三人称 View ,其中包括控制模型。该模型可以使用 WASD 和鼠标移动。单击鼠标右键时,相机和 View 应该会发生变化。按住鼠标右键时,模型和相机的方向应该相同。
我在这方面的工作已经有一段时间了,我可以同时改变模型和相机的方向,但我只能让相机显示俯 View 。我希望相机也能以其他角度(与世界平面成 0 - 90 度)渲染世界。
bool EventHandlerMouse::performMovementRightMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
) {
// Read in the mouse movement to determine if the user is turning left
// or right. Then set the bool attribute of this->_screen_model to true
// for the direction that the user is moving and then sets the other to
// false. The else statement turns them both off.
if ( dx < -0.01 ) {
this->_screen_model->turn_left();
this->_screen_model->stop_turn_right();
}
else if ( dx > 0.01 ) {
this->_screen_model->turn_right();
this->_screen_model->stop_turn_left();
}
else {
this->_screen_model->stop_turn_right();
this->_screen_model->stop_turn_left();
}
// Get the model's orientation. Orientation is a float between 0.0 and
// 360.0 representing the models orientation. 0.0 and 360.0 are true
// north.
float local_o = this->_screen_model->get_orientation();
// Create the OSG variable to hold the camera manipulator's current and
// future rotation.
osg::Quat rotation, new_rotation;
osg::Vec3d eye;
// Retrieve the camera's current rotation and eye.
this->getTransformation( eye, rotation );
// Retrieve the camera's rotation matrix.
osg::Matrixd rotation_matrix;
rotation.get( rotation_matrix );
new_rotation = rotation_matrix.getRotate();
// I don't really know what makeRotate does. I couldn't find good
// documentation. From what I'm seeing, it takes the current attitude
// ( rotation ) and changes it to what you have specified. I think this
// is where my problem/solution will be. Here, I set the angle to the
// orientation of the model. I am then setting that angle to the z axis in
// the Vec3d. I think that this is what is giving me the top down view,
// but it does turn with the model. I don't know how I can change this so
// that it gives a view that would be at an over the shoulder type of
// angle similar to a typical 3rd person view.
new_rotation.makeRotate(
osg::DegreesToRadians( local_o ), Vec3d( 0.0, 0.0, 1.0 )
);
// Setting the camera's eye and rotation to the newly calculated
// perspective.
this->setTransformation( eye, new_rotation );
}
我对使用 OSG 还是很陌生。我正在阅读书籍并完成教程。我也一直在寻找如何做我想做的事,但我一直没有成功。如有任何帮助,我将不胜感激。如果我可以提供我的初出茅庐的应用程序的任何其他部分的代码片段,请告诉我您想看到的内容。
最佳答案
我最终通过相当简单的 NodeTrackManipulator 实现获得了预期的结果。我刚刚多写了一些鼠标处理,它符合我的需要。
event_handler_mouse.hpp
#ifndef EVENT_HANDLER_MOUSE_H
#define EVENT_HANDLER_MOUSE_H
#include <osgGA/GUIEventHandler>
#include <osgGA/NodeTrackerManipulator>
#include <osgViewer/View>
#include <iostream>
#include "../headers/client_obj_char.hpp"
using std::cout;
using std::endl;
class EventHandlerMouse : public osgGA::NodeTrackerManipulator {
public:
virtual bool performMovementLeftMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
);
virtual bool performMovementRightMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
);
virtual bool performMovementMiddleMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
);
EventHandlerMouse( ClientObjChar* sm ) :
_client_char( sm ),
_distance( 1.0 )
{}
protected:
virtual ~EventHandlerMouse() {}
osg::Vec3 _center;
double _distance;
ClientObjChar* _client_char;
osg::observer_ptr<osg::Node> _target;
};
#endif
event_handler_mouse.cpp
#include "../headers/event_handler_mouse.hpp"
bool EventHandlerMouse::performMovementLeftMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
) {
rotateWithFixedVertical( dx, dy );
return true;
}
bool EventHandlerMouse::performMovementRightMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
) {
if ( true ) {
if ( dx < -0.01 ) {
this->_client_char->turn_left();
this->_client_char->stop_turn_right();
}
else if ( dx > 0.01 ) {
this->_client_char->turn_right();
this->_client_char->stop_turn_left();
}
else {
this->_client_char->stop_turn_right();
this->_client_char->stop_turn_left();
}
}
return true;
}
bool EventHandlerMouse::performMovementMiddleMouseButton(
const double eventTimeDelta,
const double dx,
const double dy
) {
return false;
}
关于c++ - OpenSceneGraph:第三人称视角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47145362/
首先我看了官方对比OpenSG和 OpenSceneGraph .我目前的目标是创建一个用于学习目的的小型游戏引擎。我从纯 OpenGL 开始,但后来我发现那些看起来非常不错的场景图形库。 我想知道这
我正尝试按照 README 文件中的说明为 iOS 构建 OpenSceneGraph。 cmake -G Xcode \ -D OSG_BUILD_PLATFORM_IPHONE:BOOL=ON \
我正在使用 OpenSceneGraph 和 Qt 来开发模拟软件。模拟可能涉及同一虚拟世界中的多个机器人。我对 View 的要求如下: 能够显示静态世界相机 能够显示机器人摄像头 能够移动这些 Vi
目标:使用 OpenSceneGraph (OSG) 创建第三人称 View ,其中包括控制模型。该模型可以使用 WASD 和鼠标移动。单击鼠标右键时,相机和 View 应该会发生变化。按住鼠标右键时
我最近开始使用 OpenSceneGraph。我想知道它如何处理内存管理(如果有的话)。例如,我们有几何类。正如您所期望的,几何类接受顶点、颜色、纹理坐标的数组。除了,它期望这些东西作为指向对象的指针
我有一个应用程序是针对 OpenSceneGraph (2.6.1) 构建的,因此是间接的 OpenGL。应用程序初始化并开始运行,但随后我在 OpenGL32.dll 中收到以下异常“尝试执行无效的
我正尝试在 OSG 中创建逼真的场景,但我遇到了尺寸问题。 假设我总是在同一个屏幕上玩我的小游戏,因此我准确地知道它的分辨率和像素密度。 现在,在现实生活中,一个 1x1x1 米的盒子放在离您 10
我正在尝试使用 OpenSceneGraph。我已经使用 CMake 和 Visual Studio 2013 X64 编译了源代码。现在我正准备构建一个项目,但出现以下错误: Error 1
我需要在我的场景图中添加一堵墙,并让它正常工作,这样我的相机就不能越过墙。我正在创建一个实验室场景,但我对一般的 3d 编程不熟悉。我一直在使用 OpensceneGraph 3.0 Beginner
我是 OpenSceneGraph 的新手,希望能帮助我确定我需要使用哪些现有的 CameraManipulator 类,甚至任何其他类来进行步行/运行/慢跑模拟。到目前为止,我已经检查了大约 10
所以我有一个继承自 osg::Geode 的类 Label,我在 OpenSceneGraph 的世界空间中绘制它。显示每一帧后,我想读取屏幕空间坐标每个标签,这样我就可以找出它们在屏幕空间中的重叠程
我是第一次使用 OpenSceneGraph,我有点迷茫,因为文档真的不是那么清楚... 所以,我有这段代码可以加载一个带有房子的 obj 文件,并且我已经淹没了一个小盒子,我希望“人”所在的位置。所
正在编写一个小型的 openscenegraph 应用程序,并且需要一种更改相机高度的方法。本质上,眼睛直视着空间中的球。我想要做的是能够降低摄像机高度,以便我能够从下方 catch ,并在需要时提高
下面的代码来自一本书。当我尝试运行它时,它在线上失败了 osg::ref_ptr geom = new osg::Geometry(); 而且,输出窗口似乎没有包含太多关于崩溃原因的信息,除了告诉我它
我需要从我的查看器中捕获图像,并需要进行一些后期处理并将其显示回其上。 现在我对它的第一部分更感兴趣。即从查看器中捕获图像。 在浏览 OSG 时,我遇到了 ScreenCaptureHandler。
我有一个最小的应用程序,它使用集成了 OpenGL 包装器库 (OpenSceneGraph) 的 QOpenGLWidget。我试图弄清楚在处理我使用的 OpenGL 内容时如何正确使用 Qt5.6
我正在尝试使用我从文件中读入的笛卡尔坐标(X、Y、Z)和欧拉角(Yaw、Pitch、Roll)来控制 osg::Camera。 第 1 部分 出于某种原因,设置我的滚动将导致相机围绕 z 轴而不是预期
我正在尝试从这里编译一个 ROS OSG 项目 https://github.com/uji-ros-pkg/visualization_osg并不断收到以下错误: CMakeFiles/os
我花了很多时间试图搞清楚 OSG 的内存管理。我有一个包含几个 child 的场景图(实际上是一个基于八叉树的 LOD)。 但是,当我需要重置场景时(我只想从场景中删除所有节点并删除内存),我使用 /
我尝试将片段着色器程序添加到 OSG::Geometry 节点,如下所示。 osg::ref_ptr node = new osg::Geometry(); osg::ref_ptr
我是一名优秀的程序员,十分优秀!