1

我正在尝试创造的是一个火箭,它将沿直线方向拥抱轨道。ie) 火箭沿直线方向行进,并且可以根据其局部 x 轴进行定向。这样它就可以上/下坡道而永远不会撞到地面。

目前我正在使用 PhysX opengl 和 C++。

这是我现在正在尝试的方法: 1. 从导弹前方投射光线(向下投射光线) 2. 如果光线投射小于预期的光线投射长度,那么我必须向上定向。3. 如果光线投射大于预期的光线投射长度,那么我必须向下定向。

现在我遇到的问题是我的导弹以任意角度定向(我给它 1 度。)虽然我认为这是一种不好的方法,因为游戏中的帧数没有我想的那么多认为会有。所以火箭会撞上坡道。

我的主要问题是:有没有更好的方法来解决这个问题以及如何解决?

NxVec3 frontRayLoc = m_rocketConfig->getValueForKey<NxVec3>("r_frontRayCastLocation");
float threshhold = m_rocketConfig->getValueForKey<float>("r_angleThreshhold");
float predRayCastHeight = m_rocketConfig->getValueForKey<float>("r_predRayCastHeight");

NxVec3 rayGlobalPos_1 = m_actor->getGlobalPosition() + m_actor->getGlobalOrientation() * frontRayLoc;
NxVec3 dir = m_actor->getGlobalOrientation() * NxVec3(0,-1.0,0);
NxReal dist1 = castRay(rayGlobalPos_1, dir);

// Get the percentage difference
float actualFrontHeight = abs(1 - (dist1/predRayCastHeight));

// See if the percentage difference is greater then threshold
// Also check if we are being shot off track
if ((actualFrontHeight > threshhold) && (dist1 != m_rayMaxDist)){
    // Dip Down
    if (dist1 > predRayCastHeight){
        printf("DOWN - Distance 1: %f\n", dist1);
        // Get axis of rotation
        NxVec3 newAxis = m_actor->getGlobalOrientation() * NxVec3(1.0,0,0.0);
        // Rotate based on that axis
        m_orientateAngle = -1.0 * m_orientateAngle; // For rotating clockwise
        NxQuat newOrientation(m_orientateAngle, newAxis);
        NxMat33 orientation(newOrientation);
        m_orientation = m_orientation * orientation;
        // Orientate the linear velocity to keep speed of rocket and direct away from road
        NxVec3 linVel = m_actor->getLinearVelocity();
        m_actor->setLinearVelocity(m_orientation * linVel);
    }
    // Go Up
    else if (dist1 < predRayCastHeight){
        printf("UP - Distance 1: %f\n", dist1);
        // Get axis of rotation
        NxVec3 newAxis = m_actor->getGlobalOrientation() * NxVec3(1.0,0,0.0);
        // Rotate around axis
        NxQuat newOrientation(m_orientateAngle, newAxis);
        m_actor->setGlobalOrientationQuat(newOrientation);
        NxMat33 orientation(newOrientation);
        m_orientation = m_orientation * orientation;
        // Orientate the linear velocity to keep speed of rocket and direct away from road
        NxVec3 linVel = m_actor->getLinearVelocity();
        m_actor->setLinearVelocity(m_orientation*linVel);
    }
        m_actor->setGlobalOrientation(m_orientation);
}

感谢您的支持 :)

4

2 回答 2

3

如果你的光线追踪可以确定前方某个点的地形高度,为什么不能只确定火箭当前水平坐标处的地形高度,然后将火箭渲染到高于该高度的固定高度?

即,您似乎正在尝试为火箭发明一个制导系统,而听起来您真正需要的只是弄清楚在哪里绘制它。

实际上,您可能可以通过使其与下方地形的坡度相匹配来获得火箭的方向,这样它就不会一直显示为死水平。如果在明显的斜坡上追踪时它是水平的,它看起来会有点奇怪。

于 2010-03-12T23:55:01.813 回答
0

像军队对地形跟随的方式那样做怎么样:

向前看距离,找到飞船和 . 将所需的地面以上高度添加到此值,您就有了火箭应该处于的高度。如果它低于这个爬升,如果它高于这个下降。

选择以获得所需的火箭行为。它可能非常小。

很有可能可以预先计算高度,因此这可以简化为简单的数组查找。(即使您有近乎无限分辨率的地形,您也不需要高度数据中的完美粒度。)

于 2010-03-13T01:01:08.813 回答