Smooth movement to ascend through the atmosphere

前端 未结 4 1944
耶瑟儿~
耶瑟儿~ 2021-01-24 06:41

I\'m moving through the atmosphere with Microsoft Virtual Earth 3D and I can descend smoothly, but I don\'t know the math to ascend smoothly.

I\'m descending like this:<

4条回答
  •  爱一瞬间的悲伤
    2021-01-24 07:16

    It depends on what you want to achive by smoothly ascending. You could limit the altitude to some maximum value maxAlt and approach that value smoothly in the same way as you do with the ground.

    curAlt += (maxAlt - curAlt) / 150
    

    But if the maximum altitude is unbounded, you have to clearify what you exactly want to be smooth.

    Also note that your code works only by some side effects. You are close to an infinite loop. I would suggest the folowing.

    epsilon = 0.1; // A small value that fits your needs
    
    curAlt = startAlt;
    
    while (curAlt > endAlt + epsilon)
    {
       curAlt -= (curAlt - endAlt) / 150;
    }
    

    The iteration of curAlt -= (curAlt - endAlt) / 150 will never reach endAlt in theory and in real at most by rouding errors. Your code only works because you subtract one additional height unit per iteration. I am not sure if this is by design or a error that prevents a bug. Adding the epsilon threshold breaks the loop in a more logical way.

提交回复
热议问题