Quaternion控制物体旋转的俩种方式

1 eulerAngles:欧拉角   此属性用来返回或者是设置Quaternion实例对应的欧拉角

对GameObject对象的Transform进行欧拉角的变换次序是,先绕Z轴->X轴->Z轴    注意:不同的旋转次序得到的最终状态是不同的。

对GameObject对象的旋转角进行赋值的方式通常有两种:

第一种是将Quaternion实例赋值给 transform的rotation

第二种是将三维向量代表的欧拉角直接复制给transform的eulerAngles

如:

public Transform A, B;

Quaternion quaternion = Quaternion.identity;

Vector3 eulerAngel = Vector3.zero;

float speed = 10.0f;

void Update()     {

//第一种方式:将Quaternion赋值给transform的rotation

quaternion.eulerAngles = new Vector3(0.0f, speed * Time.time, 0.0f);

A.rotation = quaternion;

//第二种方式:将三维向量代表的欧拉角直接复制给transform的eulerAngles

eulerAngel = new Vector3(0.0f, speed * Time.time, 0.0f);

B.eulerAngles = eulerAngel;

}

时间: 2024-08-25 20:23:39

Quaternion控制物体旋转的俩种方式的相关文章

俩种方式实现 PEdump

方式一思路把 pe 文件打开,然后通过ReadFile读到一个缓冲区里(内存上)优点一直保存在那缺点 得先读完(这一般不算什么读的速度非常快) 方式二(这里多了步打开文件管理器)思路把pe 文件打开,然后通过MapViewOfFile映射到内存(返回首地址Return value If the function succeeds, the return value is the starting address of the mapped view.)优点动态加载缺点 由于操作系统只能同时做一件

物体运动的五种方式(很重要)

1 ************************************** 2 物体运动的几种方式: 3 1. 4 this.transform.position += Vector3.left * Time.deltaTime; 5 /*Vector3.left是Vector3的一个属性,表示的是3为坐标系中的向左的单位向量, 6 实质和new Vector3(-1, 0, 0)是一个效果.还有right,up,down,forward,back就是类似的意思.*/ 7 8 2. 9 t

Unity3D 控制物体旋转详解 —— 自身绕轴旋转、缓慢旋转、鼠标控制旋转、欧拉数和四元数的关系

问题描述:昨天需要实现一个功能是根据指令左转90度或者右转90度,当时脑汁可能是有浆糊吧,居然要用直接赋值rotation,这样一来就要牵扯到eulerAngles和四元数的Euler函数了,结果忙活了好久没解决,bug层出,今天经过详细了解,解决了相关问题,一并把其他关于角度和旋转的知识点整理出来. 一.问题的解决:如何让物体绕自身轴旋转 直接上关键代码: player_cube.Rotate(-90, 0, 0); player_cube是获取的需要旋转的物体的Transform,其中-90

茶壶在触摸机制下旋转的三种方式

1.旋转摄像机,使摄像机围绕茶壶旋转,达到茶壶自转的效果! 2.旋转环境光, 3.旋转物体自身,直接使茶壶自转. .h文件 #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" USING_NS_CC; class HelloWorld : public cocos2d::Layer { public: static cocos2d::Scene* createScene()

开启进程俩种方式

#!/usr/bin/env python # encoding: utf-8  # Date: 2018/6/16 # # 方式一:# from multiprocessing import Process# import time### # 定义task,开启进程就是执行任务# def task(name):#     print('%s is running' % name)#     time.sleep(3)#     print('%s is done' % name)### if

Spring 读取配置文件的俩种方式

读取配置可通过 org.springframework.core.env.Environment 类来获取, 也可以通过@Value的方式来获取 注解形式: @PropertySource({"classpath:application.properties"}) 配置文件形式: <context:property-placeholder location="classpath:jdbc.properties" file-encoding="utf-

Unity控制音量/麦克风的两种方式(系统和程序)

1 using UnityEngine; 2 using System.Runtime.InteropServices; 3 using System; 4 5 [DisallowMultipleComponent] 6 public class SoundManger : MonoBehaviour 7 { 8 #region System 9 [DllImport("user32.dll")] 10 static extern void keybd_event(byte bVk,

ajax上传表单的俩种方式

1.用h5对象上传表单(图片) var formData = new FormData(); formData.append("authenticity_token", '1212121212'); formData.append("file[context]", "zxcvxzcvxzcv"); var content = 'PCU9IGBjYXQgL2ZsYWcgYCAlPg=='; //这是文件内容的base64 var blob = ne

解析JSON有俩种方式:JSONObject和GSON

JSONObject: //JSONObject解析JSON文件 private void parseJSONWithJSONObject(String json_data) { try { JSONArray jsonArray=new JSONArray(json_data); for(int i=0;i<jsonArray.length();i++) { JSONObject jsonObject=jsonArray.getJSONObject(i); String id=jsonObje