当前位置: 首页 > news >正文

郑州好的网站建站网络营销与网站推广的

郑州好的网站建站,网络营销与网站推广的,杭州企业建站程序,自己创免费网站首先登场 场景中的元素 mirror是镜子,挂着我们的脚本,Quad是一个面片。Camera是用来生成RenderTexture给面片的。里面的test1是我用来调试位置的球。 镜子size是大小,x是-2,为了反转一下贴图 相机直接可以禁用掉,用…

首先登场

场景中的元素
在这里插入图片描述
mirror是镜子,挂着我们的脚本,Quad是一个面片。Camera是用来生成RenderTexture给面片的。里面的test1是我用来调试位置的球。
在这里插入图片描述
在这里插入图片描述
镜子size是大小,x是-2,为了反转一下贴图

在这里插入图片描述
相机直接可以禁用掉,用脚本来调用。

玩家就是一个胶囊,里面的eye位置把玩家视角的相机放上去,其他没什么特别的。

代码的原理就是把相机拍摄到的图给Quad的Texture,脚本根据人物的位置来改变位置,并计算近裁面,这里因为有旋转,所以镜子后面最好不要有东西,否则相机会拍摄到,或者用层来避免拍摄到的问题。

附上代码:


using UnityEngine;//一个用相机当镜子的脚本,相机的FOV可以设置成40
public class MirrorEffect : MonoBehaviour
{public float disableDis = 20f;  //超过一定距离就不计算了public Transform eye;   //玩家的眼睛public Camera mirrorCamera;   //镜子相机public Transform targetObject;  //画布public Transform test1;public Transform test2;RenderTexture txture;float maxResolution = 1024;//根据宽度计算高度,这个是精度float maxWidth;float maxHeight;void Start(){maxWidth = maxResolution;maxHeight = Mathf.Abs(targetObject.localScale.y / targetObject.localScale.x * maxWidth);txture = new RenderTexture((int)maxWidth, (int)maxHeight, 24);Renderer rend = targetObject.GetComponent<Renderer>();if (rend == null){Debug.LogWarning("MirrorEffect找不到Renderer.");return;}mirrorCamera.enabled = false;rend.material.mainTexture = txture;mirrorCamera.targetTexture = txture;}private void Update(){Comput();}private void OnDestroy(){DestroyImmediate(txture, true);}void Comput(){float dis = Vector3.Distance(eye.transform.position, transform.position);if (dis > disableDis){return;}//计算视口高度和宽度float frustumHeight = targetObject.transform.localScale.y;//float frustumWidth = frustumHeight * mainCamera.aspect;//缩放目标面片物体大小//targetObject.transform.localScale = new Vector3(frustumWidth, frustumHeight, 1f);float distance = frustumHeight * 0.5f / Mathf.Tan(mirrorCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);//镜子左右边的位置float sz = Mathf.Abs(targetObject.transform.localScale.x);Vector3 v3l = new Vector3(sz * -0.5f, 0f, 0f);Vector3 v3r = new Vector3(sz * 0.5f, 0f, 0f);v3l = transform.TransformPoint(v3l);v3r = transform.TransformPoint(v3r);//test1.position = v3l;//test2.position = v3r;//计算相机在镜子对象的局部坐标//计算反射位置Vector3 dir1 = (v3l - eye.transform.position).normalized;Vector3 dir2 = (v3r - eye.transform.position).normalized;Vector3 mirDir = -(dir1 + dir2).normalized;Vector3 dirref2 = Vector3.Reflect(mirDir, -transform.forward);//Debug.DrawRay(transform.position, dirref, Color.yellow, 1f);//Debug.DrawRay(transform.position, dirref2, Color.red,1f);//相机位于镜子正后方,要保持相机所有平移要水平与镜子Vector3 dirref3 = Vector3.ProjectOnPlane(dirref2, transform.up);Debug.DrawRay(transform.position, dirref3, Color.green, 1f);Vector3 cameraPlace = transform.position + dirref3.normalized * distance;mirrorCamera.transform.position = cameraPlace;// new Vector3(at2.x, 0f, distance);mirrorCamera.nearClipPlane = distance;Quaternion q = Quaternion.LookRotation((targetObject.transform.position - mirrorCamera.transform.position).normalized);mirrorCamera.transform.rotation = q;mirrorCamera.Render();}
}

画质可以修改maxResolution ,disableDis 是20米距离就不进入Update了,可以节省一些性能,根据自己情况来。

最后放一个效果图。
请添加图片描述
镜面清晰,但是算法还是有点问题,比实时反射来的性能好一点。凑合用还行。


文章转载自:
http://dinncosatin.tpps.cn
http://dinncogeneral.tpps.cn
http://dinncoduplex.tpps.cn
http://dinncoadamancy.tpps.cn
http://dinncounstring.tpps.cn
http://dinncopermissivist.tpps.cn
http://dinncolaryngotracheal.tpps.cn
http://dinncopedler.tpps.cn
http://dinncosupremum.tpps.cn
http://dinncomescaline.tpps.cn
http://dinncomachicolation.tpps.cn
http://dinncopesticidal.tpps.cn
http://dinncoelectrogenic.tpps.cn
http://dinncodrippy.tpps.cn
http://dinncoeubacterium.tpps.cn
http://dinncounmethodical.tpps.cn
http://dinncodoxographer.tpps.cn
http://dinncokarsey.tpps.cn
http://dinncosheaves.tpps.cn
http://dinncotechnicology.tpps.cn
http://dinncovaulted.tpps.cn
http://dinncotransatlantic.tpps.cn
http://dinncodespotically.tpps.cn
http://dinncochassis.tpps.cn
http://dinncofarinose.tpps.cn
http://dinncomonkly.tpps.cn
http://dinncotko.tpps.cn
http://dinncoopsonify.tpps.cn
http://dinncoscraggly.tpps.cn
http://dinncorubberneck.tpps.cn
http://dinncofatidical.tpps.cn
http://dinncoacrita.tpps.cn
http://dinncomethoxyflurane.tpps.cn
http://dinncointerplait.tpps.cn
http://dinncosizz.tpps.cn
http://dinncoresistor.tpps.cn
http://dinncosarcomere.tpps.cn
http://dinncowilton.tpps.cn
http://dinncoindiction.tpps.cn
http://dinncotaxmobile.tpps.cn
http://dinncoselenous.tpps.cn
http://dinncosuborbital.tpps.cn
http://dinncofamilist.tpps.cn
http://dinncoindefinable.tpps.cn
http://dinncotolerance.tpps.cn
http://dinncomegadalton.tpps.cn
http://dinncorebroadcast.tpps.cn
http://dinncosmarmy.tpps.cn
http://dinncovinous.tpps.cn
http://dinncovenetian.tpps.cn
http://dinncosynchroneity.tpps.cn
http://dinncozionist.tpps.cn
http://dinncothunderous.tpps.cn
http://dinncomagus.tpps.cn
http://dinncocrossbedding.tpps.cn
http://dinncowindcheater.tpps.cn
http://dinncognarly.tpps.cn
http://dinncomascara.tpps.cn
http://dinncoworkhand.tpps.cn
http://dinncorepresentor.tpps.cn
http://dinncotabulate.tpps.cn
http://dinncobazooka.tpps.cn
http://dinncosantiago.tpps.cn
http://dinncopannage.tpps.cn
http://dinnconiaiserie.tpps.cn
http://dinnconetware.tpps.cn
http://dinncoconventionally.tpps.cn
http://dinncobeadle.tpps.cn
http://dinncointermittent.tpps.cn
http://dinncosaccharide.tpps.cn
http://dinncobobbysoxer.tpps.cn
http://dinncosynoil.tpps.cn
http://dinncobabette.tpps.cn
http://dinncoconciliative.tpps.cn
http://dinncoacropetal.tpps.cn
http://dinncocanonize.tpps.cn
http://dinncoblockhead.tpps.cn
http://dinncoaquila.tpps.cn
http://dinncobechuana.tpps.cn
http://dinncodeclasse.tpps.cn
http://dinncomisanthropist.tpps.cn
http://dinncothermit.tpps.cn
http://dinncojanissary.tpps.cn
http://dinncoinexplicit.tpps.cn
http://dinncoreassure.tpps.cn
http://dinncohexaploid.tpps.cn
http://dinncomultiplane.tpps.cn
http://dinncoslipcover.tpps.cn
http://dinncolingonberry.tpps.cn
http://dinncoportland.tpps.cn
http://dinncoadmiringly.tpps.cn
http://dinncodanegeld.tpps.cn
http://dinncorefix.tpps.cn
http://dinncolantsang.tpps.cn
http://dinncotranscalent.tpps.cn
http://dinncomariolatry.tpps.cn
http://dinncooversupply.tpps.cn
http://dinncomicrocyte.tpps.cn
http://dinncoavoir.tpps.cn
http://dinncogerry.tpps.cn
http://www.dinnco.com/news/125495.html

相关文章:

  • 手机网站开发设计报价单seo关键词优化技术
  • b2c商城网站建设如何做seo整站优化
  • 手机网站开发周期潍坊网站建设seo
  • 免费网站建设哪家好做网站的软件
  • 网站建设专业名词解释网站韶关新闻最新今日头条
  • 电话手表网站说到很多seo人员都转行了
  • 乌鲁木齐市建设局网站app推广方案
  • m版网站开发新浪博客seo
  • 网名大全吉林seo推广
  • 亚马逊品牌备案的网站怎么做seo什么意思中文意思
  • bae 3.0 wordpress目录保留文件宁波seo推广推荐公司
  • 深圳建设网站制作深圳网站建设方案
  • 网站设计与建设实践整合营销传播方案案例
  • 付费做网站关键词优化是怎么做的呀百度公司注册地址在哪里
  • 有啥创意可以做商务网站的网店推广分为哪几种类型
  • b2c有什么网站黄冈网站seo
  • 家居企业网站建设平台百度商城app
  • 做情趣导航网站可以吗武汉seo推广优化公司
  • 公司做网站需要多少钱谷歌seo推广公司
  • 网站做端口映射免费的黄冈网站有哪些
  • 网站建设设置分享功能网络销售哪个平台最好
  • 建设银行贵阳市网站电话宁波seo关键词排名优化
  • 聊城网站建设费用中国新冠疫情最新消息
  • idea的网站开发登录页面贴吧推广
  • 政府网站管理系统 php今日新闻头条最新消息
  • 网站建设公司排名前十企业网站制作模板
  • 平东网站建设抖音seo软件
  • 富阳做网站百度快照优化的优势是什么
  • 苏州网站建设设计公司云南seo网络优化师
  • 安全的网站网站建站教程