#include #include #include #include #include "engine.c" unsigned short int video_rate = 60; unsigned int video_length = 60; unsigned long simulation_rate = 60000; unsigned short int resolution_x = 1920; unsigned short int resolution_y = 1080; void frame_render(char* _o) { unsigned int _index=0; for(int y=resolution_y/2;y>-resolution_y/2;y--){ for(int x=-resolution_x/2;xlocation)+distance_vec2vecs(camera.location,pixel_location)-distance_vec2vecs(pixel_location,entityarray.entity[i]->location))/(2*distance_vec2vec(camera.location,pixel_location)*distance_vec2vec(camera.location,entityarray.entity[i]->location)); if(cosangle<0){ continue; } long double angle = acosl(cosangle); if(entityarray.entity[i]->rlocation)*sinl(angle)){ continue; } long double _a = cosangle*distance_vec2vec(camera.location,entityarray.entity[i]->location)-sqrtl(pow(entityarray.entity[i]->r,2)-distance_vec2vecs(camera.location,entityarray.entity[i]->location)*pow(sinl(angle),2)); if(render_length<=0||_ax=0; entity->y=0; entity->z=0; entity_acceleration[i]=entity; } for(int i=0;ilocation.x-entityarray.entity[j]->location.x),2)+pow((entityarray.entity[i]->location.y-entityarray.entity[j]->location.y),2)+pow((entityarray.entity[i]->location.z-entityarray.entity[j]->location.z),2); long double d = sqrtl(ds); long double F = G*(entityarray.entity[i]->mass*entityarray.entity[j]->mass)/ds; entity_acceleration[i]->x += (F*(entityarray.entity[j]->location.x-entityarray.entity[i]->location.x)/d)/entityarray.entity[i]->mass; entity_acceleration[i]->y += (F*(entityarray.entity[j]->location.y-entityarray.entity[i]->location.y)/d)/entityarray.entity[i]->mass; entity_acceleration[i]->z += (F*(entityarray.entity[j]->location.z-entityarray.entity[i]->location.z)/d)/entityarray.entity[i]->mass; entity_acceleration[j]->x += (F*(entityarray.entity[i]->location.x-entityarray.entity[j]->location.x)/d)/entityarray.entity[j]->mass; entity_acceleration[j]->y += (F*(entityarray.entity[i]->location.y-entityarray.entity[j]->location.y)/d)/entityarray.entity[j]->mass; entity_acceleration[j]->z += (F*(entityarray.entity[i]->location.z-entityarray.entity[j]->location.z)/d)/entityarray.entity[j]->mass; } entityarray.entity[i]->velocity.x+=entity_acceleration[i]->x/simulation_rate; entityarray.entity[i]->velocity.y+=entity_acceleration[i]->y/simulation_rate; entityarray.entity[i]->velocity.z+=entity_acceleration[i]->z/simulation_rate; entityarray.entity[i]->location.x+=entityarray.entity[i]->velocity.x/simulation_rate; entityarray.entity[i]->location.y+=entityarray.entity[i]->velocity.y/simulation_rate; entityarray.entity[i]->location.z+=entityarray.entity[i]->velocity.z/simulation_rate; free(entity_acceleration[i]); } free(entity_acceleration); return; } int main() { entityarray_initialize(); struct entity* sun = entity_initialize(); sun->mass=1000000; sun->r=20; sun->coluor.r=255; sun->coluor.g=192; sun->coluor.b=32; struct entity* earth = entity_initialize(); earth->mass=15000; earth->location.x=200; earth->location.y=10; earth->velocity.z=150; earth->coluor.r=16; earth->coluor.g=64; earth->coluor.b=255; struct entity* mars = entity_initialize(); mars->mass=10000; mars->location.x=-300; mars->location.y=15; mars->velocity.z=-100; mars->coluor.r=255; mars->coluor.g=64; mars->coluor.b=64; add_entity(sun); add_entity(earth); add_entity(mars); world_initialize(); camera.location.x=200; camera.location.y=1; camera.location.z=200; camera.focal_length=1; struct vector light = {-1,-1,-1}; change_light(light); char cmd[512]; snprintf(cmd, sizeof(cmd),"ffmpeg -y -f rawvideo -pixel_format rgb24 -video_size %dx%d -framerate %d -i pipe:0 -c:v libx264 -preset fast -crf 23 -pix_fmt yuv420p output.mp4",resolution_x, resolution_y, video_rate); FILE *ffmpeg = popen(cmd, "w"); if (!ffmpeg) { perror("popen failed"); return 1; } size_t frame_size = resolution_x * resolution_y * 3; unsigned char *frame = malloc(frame_size); if (!frame) { perror("malloc failed"); pclose(ffmpeg); return 1; } for (int i = 0; i < video_rate*video_length; i++) { frame_render(frame); video_render(frame,frame_size,ffmpeg); for(int j=0;j