3D传染媒介(X,Y,Z)看传染媒介 [英] 3D Vector (X, Y, Z) look at Vector

查看:186
本文介绍了3D传染媒介(X,Y,Z)看传染媒介的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用源sdk(使用c ++),我想旋转实体的角度,所以它看起来在另一个实体。

Im working with the source sdk (Which uses c++) and I want to rotate a entity's angle so it looks at another entity.

一个实体可以看作为一个游戏对象或类似的,在世界上有一个位置(矢量)以及一个角度(矢量)。

A entity can be looked at as a gameobject or similar and has a position (Vector) in the world as well as a angle (Vector).

我可以使用SetAbsAngles旋转实体, QAngle(基本上是一个向量)作为参数。

I can rotate the entity by using SetAbsAngles which takes a QAngle (Basically a Vector) as parameter.

推荐答案

这里是一些伪代码:

vec3 p = entity2->getPosition();
vec3 r = entity1->getPosition();
float xdistance = p[0] - r[0];
float ydistance = p[1] - r[1];
float zdistance = p[2] - r[2];
float xzdistance = sqrt(xdistance * xdistance + zdistance * zdistance);
entitity1->setHeading(atan2(xdistance, zdistance)); // rotation around y
entitity1->setPitch(-atan2(ydistance, xzdistance)); // rotation around x
entitity1->setBank(0); // rotation around z

z旋转设置为0,因为无法确定。

The z-rotation is set to 0 because it cannot be determined. You can set it freely if you like.

这是一个坐标系统,z面向前,y向上,x向右。如果您使用的是其他系统,您可能需要调整一些迹象。

This works in a coordinate system with z facing forward, y up and x to the right. If you are using a different system you may have to adjust some signs.

这篇关于3D传染媒介(X,Y,Z)看传染媒介的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆