如何做網(wǎng)站的源碼23歲老牌網(wǎng)站
前言
AIS_ManipulatorOwner
是OpenCascade中的一個類,主要用于操縱對象的交互控制。AIS_ManipulatorOwner
結(jié)合AIS_Manipulator
類,允許用戶通過可視化工具(如旋轉(zhuǎn)、平移、縮放等)來操縱幾何對象。
以下是AIS_ManipulatorOwner
的基本用法介紹:
1. 包含必要的頭文件
首先,確保在代碼中包含必要的OpenCascade頭文件:
#include <AIS_ManipulatorOwner.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Manipulator.hxx>
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <V3d_View.hxx>
2. 創(chuàng)建幾何對象和上下文
創(chuàng)建一個幾何對象,并初始化一個AIS_InteractiveContext
:
Handle(AIS_InteractiveContext) context = ...; // 已初始化的交互上下文
TopoDS_Shape aShape = BRepPrimAPI_MakeBox(100.0, 100.0, 100.0).Shape();
Handle(AIS_Shape) aShapeAIS = new AIS_Shape(aShape);
context->Display(aShapeAIS, Standard_True);
3. 創(chuàng)建和設(shè)置Manipulator
創(chuàng)建一個Manipulator,并將其與幾何對象關(guān)聯(lián):
Handle(AIS_Manipulator) aManipulator = new AIS_Manipulator();
aManipulator->SetComponent(aShapeAIS);
context->Display(aManipulator, Standard_True);
4. 創(chuàng)建ManipulatorOwner
創(chuàng)建一個AIS_ManipulatorOwner
,并將其與Manipulator關(guān)聯(lián):
Handle(AIS_ManipulatorOwner) aManipulatorOwner = new AIS_ManipulatorOwner(aManipulator, context);
5. 操縱幾何對象
通過ManipulatorOwner,可以對幾何對象進行旋轉(zhuǎn)、平移和縮放等操作。例如:
gp_Trsf transformation;
transformation.SetTranslation(gp_Vec(10.0, 0.0, 0.0)); // 平移10單位
aManipulatorOwner->SetLocalTransformation(transformation);
context->Redisplay(aShapeAIS, Standard_True);
6. 交互操作
用戶可以通過鼠標操作與幾何對象進行交互。AIS_InteractiveContext
提供了許多方法來處理鼠標事件并相應(yīng)地更新幾何對象的位置。
// 示例:處理鼠標點擊事件
void OnMouseClick(const Handle(V3d_View)& aView, Standard_Integer x, Standard_Integer y) {context->MoveTo(x, y, aView);if (context->HasDetected()) {Handle(AIS_InteractiveObject) detectedObj = context->DetectedInteractive();if (!detectedObj.IsNull() && detectedObj == aShapeAIS) {// 選中了幾何對象context->StartTransformation(aView, x, y);}}
}
總結(jié)
AIS_ManipulatorOwner
是一個強大的工具,可以幫助用戶通過圖形界面與幾何對象進行交互。通過設(shè)置適當(dāng)?shù)淖儞Q矩陣,可以實現(xiàn)對對象的各種操作,從而極大地增強了用戶的交互體驗。
AIS_MediaPlayer
視頻播放演示。
方法
1
空構(gòu)造函數(shù)。
Standard_EXPORT AIS_MediaPlayer();
2
析構(gòu)函數(shù)。
Standard_EXPORT virtual ~AIS_MediaPlayer();
3
設(shè)置回調(diào)函數(shù),用于在隊列進度時調(diào)用(例如,當(dāng)需要顯示新幀時)。
void SetCallback (Graphic3d_MediaTextureSet::CallbackOnUpdate_t theCallbackFunction, void* theCallbackUserPtr)
{
myFramePair->SetCallback (theCallbackFunction, theCallbackUserPtr);
}
4
打開指定文件。
Standard_EXPORT void OpenInput (const TCollection_AsciiString& thePath,
Standard_Boolean theToWait);
5
顯示新幀。
Standard_EXPORT bool PresentFrame (const Graphic3d_Vec2i& theLeftCorner,
const Graphic3d_Vec2i& theMaxSize);
6
返回播放器上下文。
const Handle(Media_PlayerContext)& PlayerContext() const { return myFramePair->PlayerContext(); }
7
切換播放狀態(tài)。
Standard_EXPORT void PlayPause();
8
安排關(guān)閉播放器。
void SetClosePlayer()
{
myToClosePlayer = true;
myFramePair->Notify();
}
9
返回持續(xù)時間。
double Duration() const { return myFramePair->Duration(); }
//! @name AIS_InteractiveObject 接口
protected:
10
僅接受顯示模式0。
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
11
計算演示文稿。
Standard_EXPORT virtual void Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode) Standard_OVERRIDE;
12
計算選擇。
Standard_EXPORT virtual void ComputeSelection (const Handle(SelectMgr_Selection)& theSel,
const Standard_Integer theMode) Standard_OVERRIDE;
13
更新幀大小。
Standard_EXPORT bool updateSize (const Graphic3d_Vec2i& theLeftCorner,
const Graphic3d_Vec2i& theMaxSize);
參考