summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt6
-rw-r--r--bowshock/include/bow/bs.h2
-rw-r--r--bowshock/include/bow/lgc.h7
-rw-r--r--bowshock/source/bs/loop.c59
-rw-r--r--bowshock/source/gfx/drw.c31
-rw-r--r--bowshock/source/lgc/grav.c35
-rw-r--r--bowshock/source/lgc/mv.c4
7 files changed, 106 insertions, 38 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index e51b7ab..beada9c 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,9 @@
+# 0.8.1
+
+* Update renderer;
+* Add canister to simulation;
+* Update mechanical functions;
+
# 0.8.0
* Make code more modular;
diff --git a/bowshock/include/bow/bs.h b/bowshock/include/bow/bs.h
index 72c4d3e..f03c0e4 100644
--- a/bowshock/include/bow/bs.h
+++ b/bowshock/include/bow/bs.h
@@ -44,7 +44,7 @@ static_assert(sizeof (double) == 0x8u);
constexpr zap_i04 bow_vermaj = 0x0u;
constexpr zap_i04 bow_vermin = 0x8u;
-constexpr zap_i04 bow_verpat = 0x0u;
+constexpr zap_i04 bow_verpat = 0x1u;
#define bow_cmdrnmlen ((zap_sz)0xEu)
diff --git a/bowshock/include/bow/lgc.h b/bowshock/include/bow/lgc.h
index 585ea8f..acf796b 100644
--- a/bowshock/include/bow/lgc.h
+++ b/bowshock/include/bow/lgc.h
@@ -92,7 +92,8 @@ constexpr double bow_gravconst = 0x1.2589EFFFp-34/(bow_tmmod*bow_tmmod); // grav
bow_obj * bow_addobj( bow_objroot * root,bow_obj const * obj);
void bow_freeobjs(bow_objroot const * root);
-void bow_grav( bow_obj * obj, bow_obj * par);
-void bow_gravobjs(bow_objroot const * root);
+void bow_grav( bow_obj * obj, bow_obj * par);
+void bow_gravsys( bow_objroot const * sys);
+void bow_gravobjs(bow_objroot const * sys,bow_objroot const * objs);
void bow_mv( bow_obj * obj);
-void bow_mvobjs( bow_obj * objs);
+void bow_mvobjs( bow_objroot const * root);
diff --git a/bowshock/source/bs/loop.c b/bowshock/source/bs/loop.c
index d8339ea..7bcf07a 100644
--- a/bowshock/source/bs/loop.c
+++ b/bowshock/source/bs/loop.c
@@ -20,7 +20,7 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
bow_objroot sysroot = { // For stellar bodies.
.objs = nullptr,
};
- [[maybe_unused]] bow_objroot objroot = { // For miscellaneous objects (canisters, ships...).
+ bow_objroot objroot = { // For miscellaneous objects (canisters, ships...).
.objs = nullptr,
};
bow_obj objtmp = {
@@ -49,7 +49,7 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
.startyp = bow_star_g,
// next will be overwritten anyways.
};
- bow_obj * const sol = bow_addobj(&sysroot,&objtmp);
+ bow_addobj(&sysroot,&objtmp);
objtmp = (bow_obj) {
.typ = bow_objtyp_wrld,
.pos = {
@@ -75,7 +75,32 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
.mass = 0x4'F0A9'9C58'8848'32A0'0000p0,
.wrldtyp = bow_wrld_rck,
};
- bow_obj * const ter = bow_addobj(&sysroot,&objtmp);
+ bow_addobj(&sysroot,&objtmp);
+ objtmp = (bow_obj) {
+ .typ = bow_objtyp_can,
+ .pos = {
+ .x = 0x20'0000'0000p0,
+ .y = 0x20'0000'0000p0,
+ .z = 0x0p0,
+ },
+ .rot = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .posvel = {
+ .x = 0x16A.09E667F4p0*0x20p0/bow_tmmod,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .rotvel = {
+ .x = 0x0p0,
+ .y = 0x0p0,
+ .z = 0x0p0,
+ },
+ .mass = 0x1p0,
+ };
+ bow_addobj(&objroot,&objtmp);
for (;;++playdat.tm) {
glfwPollEvents();
if (bow_gotintr) {
@@ -84,31 +109,13 @@ bow_stat bow_loop(bow_gfxdat * gfxdatptr,bow_playdat * playdatptr) {
}
if (glfwWindowShouldClose(gfxdat.win)) break;
// Calculate gravitations:
- //bow_gravobjs(&sysroot);
- bow_grav(ter,sol);
+ bow_gravsys(&sysroot);
+ bow_gravobjs(&sysroot,&objroot);
// Move objects:
- bow_mvobjs(sysroot.objs);
+ bow_mvobjs(&sysroot);
+ bow_mvobjs(&objroot);
// Render:
- int frmbufw;
- int frmbufh;
- glfwGetFramebufferSize(gfxdat.win,&frmbufw,&frmbufh);
- GLdouble const vrat = (GLdouble)frmbufh/(GLdouble)frmbufw;
- glViewport(0x0,0x0,frmbufw,frmbufh);
- glOrtho(-0x1p0,0x1p0,-0x1p0,0x1p0,0x0p0,0x0p0);
- double const frm = 0x22'3F8B'93C0p0*0x3p0/0x2p0;
- GLfloat const solposx = (GLfloat)(sol->pos.x/frm);
- GLfloat const solposy = (GLfloat)(sol->pos.y/frm/vrat);
- GLfloat const terposx = (GLfloat)(ter->pos.x/frm);
- GLfloat const terposy = (GLfloat)(ter->pos.y/frm/vrat);
- glClear(GL_COLOR_BUFFER_BIT);
- glPointSize(0x4p0);
- glBegin(GL_POINTS);
- glColor3f(0x1p0,0x0p0,0x0p0);
- glVertex2f(solposx,solposy);
- glColor3f(0x0p0,0x1p0,0x0p0);
- glVertex2f(terposx,terposy);
- glEnd();
- glfwSwapBuffers(gfxdat.win);
+ bow_drw(&gfxdat,&sysroot,&objroot);
}
bow_freeobjs(&sysroot);
zap_cp(gfxdatptr, &gfxdat, sizeof (gfxdat));
diff --git a/bowshock/source/gfx/drw.c b/bowshock/source/gfx/drw.c
index 33cb159..570735b 100644
--- a/bowshock/source/gfx/drw.c
+++ b/bowshock/source/gfx/drw.c
@@ -4,6 +4,33 @@
#include <bow/lgc.h>
#include <GLFW/glfw3.h>
+#include <zap/mem.h>
-/*void bow_drw(bow_gfxdat * gfxdatptr,bow_objroot * const sys,bow_objroot * const objs) {
-}*/
+static void bow_drwobjs(bow_objroot * const root) {
+ double const frm = 0x22'3F8B'93C0p0*0x6p0;
+ for (bow_obj * obj = root->objs;obj != nullptr;obj = obj->next) {
+ GLfloat const posx = (GLfloat)obj->pos.x/frm;
+ GLfloat const posy = (GLfloat)obj->pos.y/frm;
+ GLfloat const posz = (GLfloat)obj->pos.z/frm;
+ glColor3f(0x1p0,0x1p0,0x1p0);
+ glVertex3f(posx,posy,posz);
+ }
+}
+
+void bow_drw(bow_gfxdat * gfxdatptr,bow_objroot * const sys,bow_objroot * const objs) {
+ bow_gfxdat gfxdat;
+ zap_cp(&gfxdat,gfxdatptr,sizeof (gfxdat));
+ int frmbufw;
+ int frmbufh;
+ glfwGetFramebufferSize(gfxdat.win,&frmbufw,&frmbufh);
+ glViewport(0x0,0x0,frmbufw,frmbufh);
+ glOrtho(-0x1p0,0x1p0,-0x1p0,0x1p0,0x0p0,0x0p0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glPointSize(0x4p0);
+ glBegin(GL_POINTS);
+ bow_drwobjs(sys);
+ bow_drwobjs(objs);
+ glEnd();
+ glfwSwapBuffers(gfxdat.win);
+ zap_cp(gfxdatptr,&gfxdat,sizeof (gfxdat));
+}
diff --git a/bowshock/source/lgc/grav.c b/bowshock/source/lgc/grav.c
index 3c4e394..ab86289 100644
--- a/bowshock/source/lgc/grav.c
+++ b/bowshock/source/lgc/grav.c
@@ -5,7 +5,28 @@
#include <math.h>
#include <zap/mem.h>
-void bow_grav(bow_obj * obj0ptr,bow_obj * obj1ptr) {
+void bow_grav1(bow_obj * objptr,bow_obj * parptr) {
+ bow_obj obj;
+ bow_obj par;
+ zap_cp(&obj,objptr,sizeof (obj));
+ zap_cp(&par,parptr,sizeof (par));
+ double const distx = par.pos.x-obj.pos.x;
+ double const disty = par.pos.y-obj.pos.y;
+ double const distz = par.pos.z-obj.pos.z;
+ double const dist = sqrt(distx*distx+disty*disty+distz*distz);
+ double const angy = atan2(disty,distx);
+ double const angz = atan2(distz,distx);
+ double acc = par.mass/pow(dist,2.0)*bow_gravconst;
+ double const vx = cos(angy)*acc;
+ double const vy = sin(angy)*acc;
+ double const vz = sin(angz)*acc;
+ obj.posvel.x += vx;
+ obj.posvel.y += vy;
+ obj.posvel.z += vz;
+ zap_cp(objptr,&obj,sizeof (obj));
+}
+
+void bow_grav2(bow_obj * obj0ptr,bow_obj * obj1ptr) {
bow_obj obj0;
bow_obj obj1;
zap_cp(&obj0,obj0ptr,sizeof (obj0));
@@ -38,8 +59,14 @@ void bow_grav(bow_obj * obj0ptr,bow_obj * obj1ptr) {
zap_cp(obj1ptr,&obj1,sizeof (obj1));
}
-void bow_gravobjs(bow_objroot const * const root) {
- for (bow_obj * obj0 = root->objs;obj0 != nullptr;obj0 = obj0->next)
+void bow_gravsys(bow_objroot const * const sys) {
+ for (bow_obj * obj0 = sys->objs;obj0 != nullptr;obj0 = obj0->next)
for (bow_obj * obj1 = obj0->next;obj1 != nullptr;obj1 = obj1->next)
- bow_grav(obj0,obj1);
+ bow_grav2(obj0,obj1);
+}
+
+void bow_gravobjs(bow_objroot const * const sys,bow_objroot const * const objs) {
+ for (bow_obj * obj = objs->objs;obj != nullptr;obj = obj->next)
+ for (bow_obj * par = sys->objs;par != nullptr;par = par->next)
+ bow_grav1(obj,par);
}
diff --git a/bowshock/source/lgc/mv.c b/bowshock/source/lgc/mv.c
index a039913..1385123 100644
--- a/bowshock/source/lgc/mv.c
+++ b/bowshock/source/lgc/mv.c
@@ -17,7 +17,7 @@ void bow_mv(bow_obj * objptr) {
zap_cp(objptr,&obj,sizeof (obj));
}
-void bow_mvobjs(bow_obj * obj) {
- for (;obj != nullptr;obj = obj->next)
+void bow_mvobjs(bow_objroot const * root) {
+ for (bow_obj * obj = root->objs;obj != nullptr;obj = obj->next)
bow_mv(obj);
}