鸟语天空
Open CASCADE 动画
post by:追风剑情 2025-3-18 10:40

open cascade 中与动画相关的头文件有:

示例:旋转立方体

此示例,基于官方示例工程中的 OCCTProxy.cpp 改写。

 //是否播放动画
bool playing = false;
NCollection_Haft<Handle(AIS_Animation)> ais_animation;

//创建动画
void CreateAnimation()
{
    const TCollection_AsciiString theAnimationName = "Rotation Box";
    //创建一个立方体
    TopoDS_Shape box = BRepPrimAPI_MakeBox(100, 100, 100).Shape();
    //为立方体添加交互功能
    Handle(AIS_Shape) aisBox = new AIS_Shape(box);
    //显示立方体
    myAISContext()->Display(aisBox, Standard_True);
    //获取立方体本地变换对象作为起始变换
    gp_Trsf sTrsf = aisBox->LocalTransformation();

    //定义终止变换
    gp_Trsf eTrsf;
    //将旋转轴定义在立方体的中心点位置
    gp_Ax1 ax1(gp_Pnt(50, 50, 50), gp_Dir(0, 1, 0));
    Standard_Real radians = M_PI_2;
    eTrsf.SetRotation(ax1, radians);

    //创建动画对象
    Handle(AIS_AnimationObject) ani_object = new AIS_AnimationObject(theAnimationName, myAISContext(), aisBox, sTrsf, eTrsf);
    //设置动画播放时长
    ani_object->SetOwnDuration(5);

    //将AIS_AnimationObject对象添加到AIS_Animation对象中
    ais_animation() = new AIS_Animation(theAnimationName);
    ais_animation()->Add(ani_object);
}

//开始播放动画
void PlayAnimation()
{
    playing = true;
    const Standard_Real theStartPts = 0;
    const Standard_Real thePlaySpeed = 1.0;
    //启动动画计时器
    ais_animation()->StartTimer(theStartPts, thePlaySpeed, true);
}

//每帧更新动画,此方法需要每帧调用
void UpdateAnimation()
{
    if (!playing)
        return;

    if (ais_animation().IsNull())
        return;

    while (!ais_animation()->IsStopped())
    {
        //每帧更新动画
        ais_animation()->UpdateTimer();
        //每帧更新视图
        myAISContext()->UpdateCurrentViewer();
    }
}  

11111116.gif

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容