加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.cpp 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
找不到服务器 提交于 2022-08-19 16:43 . 08.19 1637
#include "orbitalsim.hpp"
#include "utils.h"
#include "tracelog.h"
int main(void) {
/*初始化场景*/
Camera camera;
SetTraceLogLevel(LOG_WARNING);
SetConfigFlags(FLAG_MSAA_4X_HINT);
SetConfigFlags(FLAG_FULLSCREEN_MODE);
SetTargetFPS(60);
// InitGraph(1024, 768, "RayLib-3D");
InitGraph(1920, 1200, "RayLib-3D");
Init_Camera(&camera);
Init_Skybox();
/*加载卫星*/
Orbital_Object satellites[3];
satellites[0].Set_initRV(Vector3{15, 0, 0}, Vector3{0, 20, 0});
satellites[1].Set_initRV(Vector3{15, 0, 5}, Vector3{0, 21, 0});
satellites[2].Set_initRV(Vector3{15, 1, -5}, Vector3{0, 20, 0});
for (int i = 0; i < 3; i++) {
satellites[i].Set_ID(i);
satellites[i].Load_Model("resources/satellite.obj", "resources/satellite.png");
satellites[i].Set_Scale(0.01);
}
/*加载地球模型和纹理*/
Model modelEarth = LoadModel("resources/sphere.obj");
Texture2D imgEarth = LoadTexture("resources/earth.png");
modelEarth.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = imgEarth;
/*添加全局变量*/
Vector3 ShuttleVelocity[3];
Vector3 vec3d;
int cnt = 30;
int showfps=0, showcpu=0;
/*场景循环*/
while (!WindowShouldClose()) {
for (int i = 0; i < 3; i++) {
satellites[i].Simulate(10);
vec3d = satellites[i].Get_V();
ShuttleVelocity[i].x = vec3d.x;
ShuttleVelocity[i].y = vec3d.z;
ShuttleVelocity[i].z = vec3d.y;
}
Update_Camera(&camera);
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
Update_Skybox();
DrawModel(modelEarth, (Vector3){ 0.0f, 0.0f, 0.0f }, 10.0f, WHITE);
for (int i = 0; i < 3; i++)
satellites[i].Update_Model(MatrixRotateXYZ((Vector3){0, atan2f(-ShuttleVelocity[i].x, ShuttleVelocity[i].z), 0}));
EndMode3D();
cnt++;
if (cnt>=30) {
cnt = 0;
showfps = GetFPS();
showcpu = GetCPUusage();
}
DrawText(TextFormat("%2i FPS", showfps), 0, 0, 20, LIME);
DrawText(TextFormat("%2i %%", showcpu), 0, 30, 20, LIME);
EndDrawing();
}
CloseGraph();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化