大学のプロジェクトで C++ を使用して Unreal Engine 4 でこの太陽系シミュレーターを作成していますが、C++ と UE4 は初めてで、数学が苦手なので、少し助けが必要でした。オイラー積分器は今のところ、いくつかの基本的な物理学を取り入れて月を地球の周りを周回させ、次におそらく速度ベルレ法を使用して太陽系全体をそのように構築することに進みます。ただし、現時点では、Euler 統合でさえ機能しません。これが Moon.cpp のコードです
//Declare the masses
float MMass = 109.456;
float EMass = 1845.833;
//New velocities
float NewMVelX = 0.0;
float NewMVelY = 0.0;
float NewMVelZ = 0.0;
//Distance
float DistanceX = 0.0;
float DistanceY = 0.0;
float DistanceZ = 0.0;
//Earth's velocity
float EVelocityX = 0.0;
float EVelocityY = 0.0;
float EVelocityZ = 0.0;
//Moon's base velocity
float MVelocityX = 0.1;
float MVelocityY = 0.0;
float MVelocityZ = 0.0;
//Moon's acceleration
float MForceX = 0.0;
float MForceY = 0.0;
float MForceZ = 0.0;
//New position
float MPositionX = 0.0;
float MPositionY = 0.0;
float MPositionZ = 0.0;
// Called every frame
void AMoon::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//Get Earth Location
FVector EPosition = FVector(0.0, 0.0, 0.0);
//Get Moon Location
FVector MPosition = GetActorLocation();
//Get the distance between the 2 bodies
DistanceX = (MPosition.X - EPosition.X) / 100;
DistanceY = (MPosition.Y - EPosition.Y) / 100;
//DistanceZ = MPosition.Z - EPosition.Z / 100;
//Get the acceleration/force for every axis
MForceX = G * MMass * EMass / (DistanceX * DistanceX);
MForceY = G * MMass * EMass / (DistanceY * DistanceY);
//MForceZ = G * MMass * EMass / (DistanceZ * DistanceZ);
//Get the new velocity
NewMVelX = MVelocityX + MForceX;
NewMVelY = MVelocityY + MForceY;
//NewMVelZ = MVelocityZ + MForceZ * DeltaTime;
//Get the new location
MPositionX = (MPosition.X) + NewMVelX;
MPositionY = (MPosition.Y) + NewMVelY;
//MPositionZ = MPosition.Z * (MVelocityZ + NewMVelZ) * 0.5 * DeltaTime;
//Set the new velocity on the old one
MVelocityX = NewMVelX;
MVelocityY = NewMVelY;
//MVelocityZ = NewMVelZ;
//Assign the new location
FVector NewMPosition = FVector(MPositionX, MPositionY, MPositionZ);
//Set the new location
SetActorLocation(NewMPosition);
}
値が正しくない可能性があります。この時点でテストを行っていました。このコードは、Google や複数の Web サイトで得たさまざまな情報に基づいていますが、この時点ではかなり混乱しています。何が起こっているかというと、月は一方向に進み始め、止まることはありません。私の問題は、地球の力/加速度/実際の重力にあることを知っています。月を押しのけるのではなく、引き離す必要があります。とにかく、誰かが私が間違っていることを知っているなら、あなたが言わなければならないことを聞いてとても感謝しています! ありがとう