mirror of
https://github.com/PoetryInCode/simple-rigid-sim.git
synced 2026-08-13 11:24:39 -04:00
general/encorporate phys_obj into main
This commit is contained in:
parent
82169f744c
commit
fe8f42c119
10
Makefile
10
Makefile
@ -1,11 +1,11 @@
|
||||
CC = clang
|
||||
LINK = -lstdc++ -lSDL2
|
||||
DBG = -Wall
|
||||
DBG = -Wall -O3
|
||||
CC += $(DBG)
|
||||
|
||||
all: build ;
|
||||
|
||||
goals = bin/main.o bin/Color.o bin/Quad.o bin/Vector.o
|
||||
goals = bin/main.o bin/Color.o bin/Quad.o bin/Vector.o bin/phys_obj.o bin/BoundingBox.o
|
||||
|
||||
define pro =
|
||||
$(CC) -c $^ -o $@
|
||||
@ -13,14 +13,16 @@ endef
|
||||
|
||||
bin/main.o: src/main.cpp
|
||||
$(pro)
|
||||
#bin/Cube.o: src/Cube.cpp
|
||||
# $(pro)
|
||||
bin/BoundingBox.o: src/BoundingBox.cpp
|
||||
$(pro)
|
||||
bin/Color.o: src/Color.cpp
|
||||
$(pro)
|
||||
bin/Quad.o: src/Quad.cpp
|
||||
$(pro)
|
||||
bin/Vector.o: src/Vector.cpp
|
||||
$(pro)
|
||||
bin/phys_obj.o: src/phys_obj.cpp
|
||||
$(pro)
|
||||
|
||||
#targets = $(patsubst bin/%.o,src/%.cpp,$(goals))
|
||||
#$(goals): $(targets) ;
|
||||
|
||||
@ -26,5 +26,4 @@ int Window::initUI() {
|
||||
-1,
|
||||
SDL_RENDERER_ACCELERATED
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
30
src/main.cpp
30
src/main.cpp
@ -1,8 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_timer.h>
|
||||
#include <vector>
|
||||
#include "Quad.h"
|
||||
#include "phys_obj.h"
|
||||
|
||||
SDL_Window *win = NULL;
|
||||
SDL_Renderer *rend = NULL;
|
||||
@ -51,6 +50,10 @@ bool clamp(float *value, float val) {
|
||||
}
|
||||
}
|
||||
|
||||
void gravity(phys_obj &obj) {
|
||||
obj.velocity = Vector(0,obj.velocity.y--);
|
||||
}
|
||||
|
||||
int main() {
|
||||
init();
|
||||
cc = Color(BLACK);
|
||||
@ -78,8 +81,8 @@ int main() {
|
||||
|
||||
Quad rect;
|
||||
|
||||
Quad *grav_objs = (Quad *)malloc(0);
|
||||
std::vector<Quad> objs;
|
||||
std::vector<phys_obj> objs;
|
||||
//std::vector<int> yvalues;
|
||||
|
||||
while(run) {
|
||||
if(modified) {
|
||||
@ -103,7 +106,7 @@ int main() {
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
printf("Mouse released at %i,%i\n",x2,y2);
|
||||
trackmouse = false;
|
||||
objs.push_back(rect);
|
||||
objs.push_back(phys_obj(rect, Vector(0,0)));
|
||||
//grav_objs = (Quad *)calloc(1,sizeof(Quad));
|
||||
//grav_objs[sizeof(grav_objs)/sizeof(grav_objs[0])] = rect;
|
||||
//printf("grav objs: %lu\n",(sizeof(grav_objs)/sizeof(grav_objs[0])));
|
||||
@ -158,6 +161,13 @@ int main() {
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch(event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
SDL_GetWindowSize(win,&w,&h);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//change_vector[0] = clamp(&buffer.x,clamp_min);
|
||||
@ -167,12 +177,11 @@ int main() {
|
||||
rect.setColor(Color(GREEN));
|
||||
rect.render(rend);
|
||||
}
|
||||
/*for(int i=0; i<sizeof(grav_objs)/sizeof(grav_objs[0]); i++) {
|
||||
grav_objs[i].setColor(Color(WHITE));
|
||||
grav_objs[i].render(rend);
|
||||
}*/
|
||||
for(int i=0; i<objs.size(); i++) {
|
||||
objs[i].render(rend);
|
||||
if(!(objs[0].bounds.max.y >= h)) {
|
||||
gravity(objs[i]);
|
||||
}
|
||||
objs[0].render(rend);
|
||||
}
|
||||
if(change_vector[0]) {
|
||||
if(buffer.x != 0.0) {
|
||||
@ -193,7 +202,6 @@ int main() {
|
||||
quad.translate(buffer);
|
||||
quad.render(rend);
|
||||
SDL_RenderPresent(rend);
|
||||
SDL_GetWindowSize(win,&w,&h);
|
||||
SDL_Delay(1000/60);
|
||||
}
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user