Unity 基础函数

Mathf:

        //1.π-PI
        print(Mathf.PI);
        //2.取绝对值-Abs
        print(Mathf.Abs(-10));
        print(Mathf.Abs(-20));
        print(Mathf.Abs(1));
        //3.向上取整-Ce il To In t
        float f = 1.3f;
        int i = (int)f;
        print(i);
        print(Mathf.CeilToInt(f));
        print(Mathf.CeilToInt(1.00001f));
        //4.向下取整-FloorToInt
        print(Mathf.FloorToInt(9.6f));
        //5.钳制函数-clamp 限制大小
        print(Mathf.Clamp(10, 11, 20));//10
        print(Mathf.Clamp(22, 11, 20));//20
        print(Mathf.Clamp(15, 11, 20));//15
        //6.获取最大值-Max
        print(Mathf.Max(10, 11, 20));//取最大数
        //7.获取最小值-Min
        print(Mathf.Pow(10, 2));//10的2次方
        //8.一个数的n次幕-Pow
        print(Mathf.FloorToInt(9.6f));
        //9.四舍五入-RoundToInt
        print(Mathf.RoundToInt(9.6f));
        //10.返回一个数的平方根-Sqrt
        print(Mathf.Sqrt(4f));//2
        //11.判断一个数是否是2的n次方-IsPowerofTwo
        print(Mathf.IsPowerOfTwo(9));//false
        //12.判断正负数-Sign
        print(Mathf.Sign(9.6f));//正数返回1

三角函数:

         // 弧度转角度
        float rad = 1;
        float anger = rad * Mathf.Rad2Deg;
        print(anger);
        // 角度转弧度
        anger = 1;
        rad = anger * Mathf.Deg2Rad;
        print(rad);

        //注意:Mathf中的三角函数相关函数,传入的参数需要时弧度值
        print(Mathf.Sin(30 * Mathf.Deg2Rad));
        print(Mathf.Cos(60 * Mathf.Deg2Rad));

        //注意:反三角函数得到的结果是正弦或者余弦值对应的弧度
        rad = Mathf.Asin(0.5f);
        print(rad * Mathf.Rad2Deg);
        rad = Mathf.Acos(0.5f);
        print(rad * Mathf.Rad2Deg);

坐标系转换:

        //世界坐标系
        //目前学习的和世界坐标系相关的
        //this.transform.position;
        //this.transform.rotation;
        //this.transform.eulerAngles;
        //this.transform.lossyScale;
        //修改他们会是相对世界坐标系的变化

        //相对坐标系
        //相对父对象的物体坐标系的位置本地坐标相对坐标
        //this.transform.localPosition;
        //this.transform.localEulerAngles;
        //this.transform.localRotation;
        //this.transform.localscale;
        //修改他们会是相对父对象物体坐标系的变化

        //三屏幕坐标系
        //Input.mouse Position
        //screen.width;
        //screen.height;

        //坐标转换相关
        //世界转本地
        //this.transform.InverseTransformDirection
        //this.transform.InverseTransformPoint
        //this.transform.InverseTransformVector
        //本地转世界
        //this.transform.TransformDirection
        //this.transform.TransformPoint
        //this.transform.TransformVector
        //世界转屏幕
        //Camera.main.WorldToscreenPoint
        //屏幕转世界
        //Camera.main.ScreenToworldPoint;

        //世界转视口
        //Camera.main.WorldToViewportPoint
        //视口转世界
        //Camera.main.ViewportToworldPoint
        //视口转屏幕
        //Camera.main.ViewportToScreenPoint
        //屏幕转视口
        //Camera.main.ScreenToViewportPoint;

向量:

//知识点一向量//三维向量-Vector3//Vector3有两种几何意义//1.位置一代表一个点print(this.transform.position);//2.方向一代表一个方向print(this.transform.forward);print(this.transform.up);//知识点二两点决定一向量//A和B此时几何意义是两个点Vector3 A = new Vector3(1, 2, 3);Vector3 B = new Vector3(5, 1, 5);//求向量//此时AB和BA他们的几何意义是两个向量Vector3 AB = B - A;Vector3 BA = A - B;//知识点三零向量和负向量print(Vector3.zero);print(Vector3.forward);print(Vector3.forward);//知识点四向量的模长//Vector3中提供了获取向量模长的成员属性//magnitudeprint(AB.magnitude);Vector3 c = new Vector3(5, 6, 7);print(c.magnitude);//知识点五单位向量print(AB.normalized);//向量加法//this.transform.position += new Vector3(1, 2, 3);this.transform.Translate(Vector3.forward * 5);      //向量减法//this.transform.position -= new Vector3(1, 2, 3);this.transform.Translate(-Vector3.forward * 5);//向量乘除标量this.transform.localScale *= 2;this.transform.localScale /= 2;//补充知识调试画线//画线段//前两个参数分别是起点终点Debug.DrawLine(this.transform.position, this.transform.position + this.transform.forward, Color.red);//画射线// 前两个参数分别是起点方向Debug.DrawRay(this.transform.position,transform.right, Color.green);//通过点乘判断对象方位//Vector3提供了计算点乘的方法Debug.DrawRay(this.transform.position, this.transform.forward, Color.red);//得到两个向量的点乘结果//向量a点乘AB的结果float dotResult = Vector3.Dot(this.transform.forward, target.position - this.transform.position);if (dotResult >= 0)print("它在我前方");elseprint("它在我后方");

 

//通过点乘推导公式算出夹角//步骤//1.用单位向量算出点乘结果//dot Result = Vector3.Dot(this.transform.forward, (target.position - this.transform.position).normalized);//2.用反三角函数得出角度print("角度" + Mathf.Acos(dotResult) * Mathf.Rad2Deg);//Vector3中提供了得到两个向量之间夹角的方法print("角度2" + Vector3.Angle(this.transform.forward, target.position - this.transform.position));

//叉乘计算print(Vector3.Cross(AA.position, BB.position));//叉乘几何意义//假设向量A和B都在X Z平面上//向量A叉乘向量B//y大于0证明B在A右侧//y小于0证明B在A左侧Vector3 vec = Vector3.Cross(BB.position, AA.position);if (vec.y > 0)print("AA在BB的右侧");elseprint("AA在BB的左侧");

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/30445.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

GCLIB动态代理

1.创建要代理的类 public class Boy {public void eat() {System.out.println("eat");} } 2.创建拦截器 public class MyMethodInterceptor implements MethodInterceptor {Overridepublic Object intercept(Object o, Method method, Object[] objects, MethodPr…

如何在群辉NAS系统下安装cpolar套件,并使用cpolar内网穿透?

如何在群辉NAS系统下安装cpolar套件,并使用cpolar内网穿透? 文章目录 如何在群辉NAS系统下安装cpolar套件,并使用cpolar内网穿透?前言1. 在群辉NAS系统下安装cpolar套件2. 管理隧道列表3. 创建固定数据隧道 前言 群晖作为大容量存储系统,既可…

git rebase

git rebase 详解git rebase,让你走上git大神之路 - 知乎 git练习 Learn Git Branching

AIGC之stable diffusion(SD)炼丹总结

1 stable diffusion技术介绍 2 常用资源 社区: civitai : 主流的AI绘画模型分享网站, 可以看大家分享出来的模型和生成的图像。 但是国内用户要访问这个网站, 需要科学上网。 aigccafe 这个是civitai的国内镜像网站,推荐使用这个。 代码…

bootloader跳转APP注意事项

在gd32f427 时跳转异常 参考文章: https://club.rt-thread.org/ask/question/425321.html%20https:/club.rt-thread.org/ask/question/eab19452583b5959.html https://club.rt-thread.org/ask/question/eab19452583b5959.html 关闭全部中断,并且清除中…

springcloud3 springcloud stream的学习以及案例

一 springcloud stream的作用 1.1 springcloud stream作用 stream屏蔽底层消息中间件的差异,降低切换成本,统一消息的编程模型。 stream中的消息通信模式遵循了“发布-订阅”模式。 1.2 Binder作用 通过定义绑定器Binder作为中间层,实现…

力扣hot100刷题记录

二刷hot100&#xff0c;坚持每天打卡&#xff01;&#xff01;&#xff01;Today&#xff1a;2023-8-10 1. 两数之和 // 先求差&#xff0c;再查哈希表 public int[] twoSum(int[] nums, int target) {Map<Integer,Integer> map new HashMap<>();for(int i 0;i&…

深度ip转换器:一键更换ip地址方法

很多网友问小编有关深度ip转换器怎么用&#xff1f;最新深度ip转换器手机版app&#xff1f;下面小编整理了深度ip转换器怎么修改ip地址的技巧和诀窍&#xff0c; 让我们来详细的了解一下深度id转换器&#xff0c; 一、深度ip转换器怎么用 1.深度ip转换器怎么用&#xff0c;深度…

JavaScript:深入探索async/await的使用

在JavaScript的异步编程领域&#xff0c;ES8引入的async/await语法是一项重要的创新。它让异步代码看起来更像同步代码&#xff0c;使得处理异步操作变得更加清晰和简洁。本文将深入探索async/await的使用&#xff0c;帮助你充分发挥这项技术的优势。 1. 什么是async/await&…

SpringBoot 升级内嵌Tomcat

SpringBoot 更新 Tomcat 最近公司的一个老项目需要升级下Tomcat&#xff0c;由于这个项目我完全没有参与&#xff0c;所以一开始我以为是一个老的Tomcat项目&#xff0c;升级它的Tomcat依赖或者是Tomcat容器镜像&#xff0c;后面发现是一个SpringBoot项目&#xff0c;升级的是…

Dockerfile 简单实战

将flask项目打包成镜像 1. 准备flask文件 创建 app.py 文件&#xff0c;内容如下 from flask import Flask app Flask(__name__)app.route(/) def hello_world():return Hello Worldif __name__ __main__:app.run(host0.0.0.0, port8000, debugTrue) 并开启外网访问&#xf…

vue消息订阅与发布,实现任意组件间通讯

第一步&#xff1a;下载第三方消息订阅与发布库&#xff0c;例如常用的pubsub.js,他可以在任何框架中使用包括vue、react、anglar等等。 命令&#xff1a;npm i pubsub-js 注意是pubsub-js(不是点); 第二步&#xff1a;引入库&#xff1b; import pubsub from pubsub-js 第…

美国服务器有哪些类型?

美国服务器有哪些类型?常见的服务器可分为虚拟主机、云服务器、物理服务器以及高防服务器&#xff0c;在海外服务器之中&#xff0c;使 用较多的属于美国服务器&#xff0c;下面我们就一起看看美国服务器有哪些及常见的美国服务器。 美国服务器有哪些? 与服务器一样&am…

Java并发编程(二)并发理论[JMM/重排序/内存屏障/Happens-Before 规则]

JMM(Java内存模型) 概述 JMM即Java内存模型(Java Memory Model),是一种抽象的概念,并不真实存在,JMM描述的是一组规则或规范,通过这组规范定义了程序中各个变量的访问方式Java内存模型中规定所有变量都存储在主内存,主内存是共享内存区域,所有线程都可以访问,但线程对变量的操…

Android AOSP源码编译——AOSP下载(一)

一、电脑配置 Ubuntu16.04 16G&#xff0c;硬盘的大小最好大于300G (我这边是找了个win电脑装了双系统 没有使用虚拟机的方式) 二、基础环境配置 1、安装git sudo apt install git配置git email和name git config --global user.email "youexample.com" git conf…

python 批量下载m3u8的视频

方法&#xff1a; 解析m3u8&#xff0c;获取其中的ts列表&#xff0c;多线程下载所有ts文件。 全部下完之后&#xff0c;用ffmpeg合并成mp4 代码&#xff1a; import requests import os import threadingtnum 64class Downloader(threading.Thread):def __init__(self, i…

数据结构—树和二叉树

5.树和二叉树 5.1树和二叉树的定义 树形结构&#xff08;非线性结构&#xff09;&#xff1a;结点之间有分支&#xff0c;具有层次关系。 5.1.1树的定义 树&#xff08;Tree&#xff09;是n&#xff08;n≥0&#xff09;个结点的有限集。 若n0&#xff0c;称为空树&#x…

LVS工作环境配置

一、LVS-DR工作模式配置 模拟环境如下&#xff1a; 1台客户机 1台LVS负载调度器 2台web服务器 1、环境部署 &#xff08;1&#xff09;LVS负载调度器 yum install -y ipvsadm # 在LVS负载调度器上进行环境安装 ifconfig ens33:200 192.168.134.200/24 # 配置LVS的VIP…

Java自学网站推荐,专业教学快速提升

Java自学网站可以是学习Java的有用资源之一。它们通常提供了丰富的教学材料、在线课程、编程练习和实例项目&#xff0c;帮助初学者系统地学习Java编程语言和相关技术。 动力节点是一家专业的Java培训机构&#xff0c;他们提供在线视频学习平台&#xff0c;你可以参考他们的官方…

数据结构----结构--线性结构--链式存储--链表

数据结构----结构–线性结构–链式存储–链表 1.链表的特点 空间可以不连续&#xff0c;长度不固定&#xff0c;相对于数组灵活自由 搜索&#xff1a; 时间复杂度O(n) 增删: 头增头删时间复杂度O(1) 其他时间复杂度为O(n) 扩展&#xff1a;单向循环链表的特性 从任意节…