Python C4D 笔记5 - c4d.utils (工具篇-Rad)

  1. 介绍C4D的utils模块,首先看下Rad()

c4d.utils.Rad(d)¶
Convert a degrees value into radians.
Parameters: r (number) – Input value in degrees.
Return type: number
Returns: Converted value in radians.

字面意思看是将角度转为弧度,要求输入的值是角度(如sin cos等)?

  1. 正巧,utils工具类里,有个SinCos()函数,该函数的作用是将任意值转为Sine和Cosine值。

c4d.utils.SinCos(w)¶
Get sine and cosine of w:
sn, cs = SinCos(80)
Parameters: w (float) – Value.
Return type: list
Returns: Sine and Cosine.

  1. 先撇开上面的工具函数,写一个没有用到Rad的例子,只是让物体的左边根据当前帧(用到笔记四)进行移动,代码如下:

import c4d
from c4d.utils import *

#Welcome to the world of Python

def main():
    # 获取当前立方体的handle
    obj = op.GetObject() 
    # 获取当前帧 (笔记四讲的)
    current_frame = doc.GetTime().GetFrame(doc.GetFps())    
    # 设置物体位置,并绑定当前帧
    obj.SetRelPos(c4d.Vector(current_frame,current_frame,current_frame))
    print(c4d.Vector(current_frame,current_frame,current_frame))

效果如下动图所示,可以看出来动作比较僵硬哦,不够柔和。
在这里插入图片描述
4. 然后我们用下工具,让物体移动过程中,带有点柔美弧度的旋转,代码如下:

import c4d
from c4d.utils import *
# -*- coding: UTF-8 -*-

#Welcome to the world of Python

def main():
    # 获取当前立方体的handle
    obj = op.GetObject() 
    # 获取当前帧 (笔记四讲的)
    current_frame = doc.GetTime().GetFrame(doc.GetFps())    
    # 设置物体位置,并绑定当前帧
    obj.SetRelPos(c4d.Vector(current_frame,current_frame,current_frame))
    print('current_frame: ',c4d.Vector(current_frame,current_frame,current_frame))
    # -----------使用utils的 Rad-------------
    # 将当前帧值转为弧度值    
    rcF = Rad(current_frame)    
    # 设置物体的旋转,并绑定弧度值
    obj.SetRelRot(c4d.Vector(rcF,rcF,rcF))
    print('Rad(current_frame): ',c4d.Vector(rcF,rcF,rcF))

结果:
在这里插入图片描述
在这里插入图片描述嗯,要柔和很多,可以看出,原本很大的帧数值,转为弧度后,数值小了很多,所以用作旋转看起来要舒服很多,当然,也可以把帧值当旋转输入,但那样会旋转太快了,看着不适。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值