首页 > 编程语言 >opencascade AIS_WalkDelta、AIS_ViewInputBuffer源码学习工作

opencascade AIS_WalkDelta、AIS_ViewInputBuffer源码学习工作

时间:2024-09-30 23:00:44浏览次数:1  
标签:ViewInputBuffer inputBuffer false AIS 旋转 Graphic3d 源码 bool

opencascade AIS_WalkDelta

前言

运行
在这里插入图片描述

方法

1.

空构造函数。
AIS_WalkDelta()
: myIsDefined(false), myIsJumping(false), myIsCrouching(false), myIsRunning(false) {}

2.

返回平移组件。
const AIS_WalkPart& operator[] (AIS_WalkTranslation thePart) ;

3.

返回平移组件。
AIS_WalkPart& operator[] (AIS_WalkTranslation thePart)

4.

返回旋转组件。
const AIS_WalkPart& operator[] (AIS_WalkRotation thePar

5.

返回旋转组件。
AIS_WalkPart& operator[] (AIS_WalkRotation thePart)

6.

返回跳跃状态。
bool IsJumping()

7.

设置跳跃状态。
void SetJumping(bool theIsJumping)

8.

返回蹲下状态。
bool IsCrouching()

9.

设置蹲下状态。
void SetCrouching(bool theIsCrouching)

10.

返回运行状态。
bool IsRunning() const { return myIsRunning; }

11.

设置运行状态。
void SetRunning(bool theIsRunning)

12.

如果即使从上一帧的增量为空,导航键仍被按下,则返回 TRUE。
bool IsDefined()

13.

设置是否有任何导航键被按下。
void SetDefined(bool theIsDefined) { myIsDefined = theIsDefined; }

14.

当旋转和平移增量都为空时返回 TRUE。
bool IsEmpty() const { return !ToMove() && !ToRotate(); }

15.

如果平移增量被定义则返回 TRUE。
bool ToMove()

16.

如果旋转增量被定义则返回 TRUE。
bool ToRotate()

使用示例

AIS_WalkDelta 是 OpenCASCADE 库的一部分,用于处理 3D 视图中步行导航的状态和动作。虽然 OpenCASCADE 的文档中可能没有明确的示例,但我们可以根据 AIS_WalkDelta 类的功能,编写一个假想的使用示例,展示如何在应用程序中设置和获取步行状态。

下面是一个简单的代码示例,演示如何使用 AIS_WalkDelta 来管理步行的状态:

#include <AIS_WalkDelta.hxx>
#include <AIS_WalkPart.hxx>
#include <iostream>

// 模拟一个函数来检查和打印步行状态
void PrintWalkState(const AIS_WalkDelta& walkDelta) {
    std::cout << "Jumping: " << (walkDelta.IsJumping() ? "Yes" : "No") << std::endl;
    std::cout << "Crouching: " << (walkDelta.IsCrouching() ? "Yes" : "No") << std::endl;
    std::cout << "Running: " << (walkDelta.IsRunning() ? "Yes" : "No") << std::endl;
    
    if (walkDelta.ToMove()) {
        std::cout << "Moving: Yes" << std::endl;
    } else {
        std::cout << "Moving: No" << std::endl;
    }

    if (walkDelta.ToRotate()) {
        std::cout << "Rotating: Yes" << std::endl;
    } else {
        std::cout << "Rotating: No" << std::endl;
    }
}

int main() {
    // 创建一个 AIS_WalkDelta 对象
    AIS_WalkDelta walkDelta;

    // 设置运行状态
    walkDelta.SetJumping(true);
    walkDelta.SetCrouching(false);
    walkDelta.SetRunning(true);

    // 模拟一些平移和旋转设置
    AIS_WalkPart translationPart;
    translationPart.SetDelta(1.0); // 假设有一个增量
    walkDelta[AIS_WalkTranslation_Forward] = translationPart;

    AIS_WalkPart rotationPart;
    rotationPart.SetDelta(0.5); // 假设有一个旋转增量
    walkDelta[AIS_WalkRotation_Yaw] = rotationPart;

    // 打印当前的步行状态
    PrintWalkState(walkDelta);

    return 0;
}

示例说明

  1. 创建 AIS_WalkDelta 实例:我们创建了一个 AIS_WalkDelta 对象 walkDelta 来管理步行的状态。

  2. 设置状态:使用 SetJumpingSetCrouchingSetRunning 函数来设置步行的状态。

  3. 设置平移和旋转:使用 AIS_WalkTranslationAIS_WalkRotation 设置对象的平移和旋转状态。这里,我们为每个状态分配了一个假想的增量。

  4. 打印状态:通过调用 PrintWalkState 函数,打印当前的步行状态,包括是否在跳跃、蹲下、奔跑,以及是否有平移和旋转的增量。

参考

opencascade AIS_ViewInputBuffer

前言

定义查看器事件的辅助结构
在这里插入图片描述

方法

1

bool IsNewGesture; //!< 从一个动作过渡到另一个动作

2

NCollection_Sequence<Aspect_ScrollDelta> ZoomActions; //!< 缩放操作队列

3

struct _orientation
{
bool ToFitAll; //!< 执行 FitAll 操作
bool ToSetViewOrient; //!< 设置新的视图方向
V3d_TypeOfOrientation ViewOrient; //!< 新的视图方向
_orientation() : ToFitAll(false), ToSetViewOrient(false), ViewOrient(V3d_Xpos) {}
} Orientation;

4

struct _highlighting
{
bool ToHilight; //!< 在指定点执行动态高亮
Graphic3d_Vec2i Point; //!< 动态高亮的新点
_highlighting() : ToHilight(false) {}
} MoveTo;

5

struct _selection
{
AIS_ViewSelectionTool Tool; //!< 执行选择
AIS_SelectionScheme Scheme; //!< 选择方案
NCollection_Sequence<Graphic3d_Vec2i>
Points; //!< 选择点
bool ToApplyTool; //!< 应用橡皮筋选择工具
_selection() : Tool(AIS_ViewSelectionTool_Picking), Scheme(AIS_SelectionScheme_UNKNOWN), ToApplyTool(false) {}
} Selection;

6

struct _panningParams
{
bool ToStart; //!< 开始平移
Graphic3d_Vec2i PointStart; //!< 平移起点
bool ToPan; //!< 执行平移
Graphic3d_Vec2i Delta; //!< 平移增量
_panningParams() : ToStart(false), ToPan(false) {}
} Panning;

7

struct _draggingParams
{
bool ToStart; //!< 开始拖动
bool ToMove; //!< 执行拖动
bool ToStop; //!< 停止拖动
bool ToAbort; //!< 中止拖动(恢复之前的位置)
Graphic3d_Vec2i PointStart; //!< 拖动起点
Graphic3d_Vec2i PointTo; //!< 拖动终点
_draggingParams() : ToStart(false), ToMove(false), ToStop(false), ToAbort(false) {}
} Dragging;

8

struct _orbitRotation
{
bool ToStart; //!< 开始轨道旋转
Graphic3d_Vec2d PointStart; //!< 轨道旋转起点
bool ToRotate; //!< 执行轨道旋转
Graphic3d_Vec2d PointTo; //!< 轨道旋转终点
_orbitRotation() : ToStart(false), ToRotate(false) {}
} OrbitRotation;

9

struct _viewRotation
{
bool ToStart; //!< 开始视图旋转
Graphic3d_Vec2d PointStart; //!< 视图旋转起点
bool ToRotate; //!< 执行视图旋转
Graphic3d_Vec2d PointTo; //!< 视图旋转终点
_viewRotation() : ToStart(false), ToRotate(false) {}
} ViewRotation;

10

struct _zrotateParams
{
Graphic3d_Vec2i Point; //!< Z 轴旋转起点
double Angle; //!< Z 轴旋转角度
bool ToRotate; //!< 开始 Z 轴旋转
_zrotateParams() : Angle(0.0), ToRotate(false) {}
} ZRotate;

11

重置事件缓冲区。
void Reset()

示例:使用 AIS_ViewInputBuffer

这个例子演示了如何在 OpenCASCADE 应用程序中使用 AIS_ViewInputBuffer 来处理 3D 查看器的用户输入事件。

#include <AIS_InteractiveContext.hxx>
#include <V3d_View.hxx>
#include <AIS_ViewInputBuffer.hxx>
#include <AIS_ViewController.hxx>
#include <Aspect_Handle.hxx>
#include <Aspect_VKeyMouse.hxx>
#include <Aspect_VKeyFlags.hxx>
#include <Graphic3d_Vec2.hxx>
#include <iostream>

// Function to simulate handling events
void HandleViewerEvents(AIS_ViewInputBuffer& inputBuffer, const Handle(AIS_InteractiveContext)& context, const Handle(V3d_View)& view)
{
    // Example: Check if a new gesture has started
    if (inputBuffer.IsNewGesture)
    {
        std::cout << "New gesture started!" << std::endl;
        inputBuffer.IsNewGesture = false; // Reset the gesture flag after handling
    }

    // Example: Handle zoom actions
    for (const auto& zoomDelta : inputBuffer.ZoomActions)
    {
        std::cout << "Zooming by delta: " << zoomDelta.Delta << std::endl;
        view->SetZoom(zoomDelta.Delta);
    }
    inputBuffer.ZoomActions.Clear(); // Clear zoom actions after processing

    // Example: Handle panning
    if (inputBuffer.Panning.ToPan)
    {
        std::cout << "Panning with delta: (" << inputBuffer.Panning.Delta.x() << ", " << inputBuffer.Panning.Delta.y() << ")" << std::endl;
        view->Pan(inputBuffer.Panning.Delta.x(), inputBuffer.Panning.Delta.y());
        inputBuffer.Panning.ToPan = false; // Reset panning flag after handling
    }

    // Example: Handle rotation
    if (inputBuffer.ViewRotation.ToRotate)
    {
        std::cout << "Rotating view from: (" << inputBuffer.ViewRotation.PointStart.x() << ", " << inputBuffer.ViewRotation.PointStart.y()
                  << ") to (" << inputBuffer.ViewRotation.PointTo.x() << ", " << inputBuffer.ViewRotation.PointTo.y() << ")" << std::endl;
        view->Rotate(inputBuffer.ViewRotation.PointStart.x(), inputBuffer.ViewRotation.PointStart.y(),
                     inputBuffer.ViewRotation.PointTo.x(), inputBuffer.ViewRotation.PointTo.y());
        inputBuffer.ViewRotation.ToRotate = false; // Reset rotation flag after handling
    }

    // Example: Handle selection
    if (inputBuffer.Selection.ToApplyTool)
    {
        std::cout << "Applying selection tool" << std::endl;
        context->Select(true); // Assume some selection mechanism
        inputBuffer.Selection.ToApplyTool = false; // Reset selection tool flag after handling
    }
}

int main()
{
    // Initialize application components
    Handle(V3d_Viewer) viewer; // Assume this is properly initialized
    Handle(AIS_InteractiveContext) context = new AIS_InteractiveContext(viewer);
    Handle(V3d_View) view = viewer->CreateView();

    // Create input buffer
    AIS_ViewInputBuffer inputBuffer;

    // Simulate some inputs
    inputBuffer.IsNewGesture = true;

    // Simulate a zoom action
    Aspect_ScrollDelta zoomDelta;
    zoomDelta.Delta = 1.1;
    inputBuffer.ZoomActions.Append(zoomDelta);

    // Simulate a panning action
    inputBuffer.Panning.ToPan = true;
    inputBuffer.Panning.Delta = Graphic3d_Vec2i(5, 10);

    // Simulate a rotation
    inputBuffer.ViewRotation.ToRotate = true;
    inputBuffer.ViewRotation.PointStart = Graphic3d_Vec2d(100, 100);
    inputBuffer.ViewRotation.PointTo = Graphic3d_Vec2d(150, 150);

    // Handle the simulated events
    HandleViewerEvents(inputBuffer, context, view);

    return 0;
}

代码解释

  • 初始化:在示例中,初始化了必要的 OpenCASCADE 组件,如 V3d_ViewerAIS_InteractiveContextV3d_View。创建了一个 AIS_ViewInputBuffer 来存储事件数据。

  • 事件处理

    • 手势:代码检查是否开始了新的手势,并通过打印消息进行处理。
    • 缩放:遍历 ZoomActions 中的每个缩放增量,并将其应用于视图。
    • 平移:检查是否请求平移,并将平移增量应用于视图。
    • 旋转:处理视图旋转,使用起始点和终止点进行操作。
    • 选择:检查是否需要应用选择工具,并执行选择操作。
  • 模拟输入:示例中模拟了一些用户输入,如缩放、平移和旋转操作,以展示如何使用 AIS_ViewInputBuffer

这个示例提供了一个基本框架,演示了如何使用 AIS_ViewInputBuffer 在 OpenCASCADE 中处理各种查看器交互。

参考
参考

标签:ViewInputBuffer,inputBuffer,false,AIS,旋转,Graphic3d,源码,bool
From: https://www.cnblogs.com/yzxxty/p/18440793

相关文章