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
|
CC = clang
|
||||||
LINK = -lstdc++ -lSDL2
|
LINK = -lstdc++ -lSDL2
|
||||||
DBG = -Wall
|
DBG = -Wall -O3
|
||||||
CC += $(DBG)
|
CC += $(DBG)
|
||||||
|
|
||||||
all: build ;
|
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 =
|
define pro =
|
||||||
$(CC) -c $^ -o $@
|
$(CC) -c $^ -o $@
|
||||||
@ -13,14 +13,16 @@ endef
|
|||||||
|
|
||||||
bin/main.o: src/main.cpp
|
bin/main.o: src/main.cpp
|
||||||
$(pro)
|
$(pro)
|
||||||
#bin/Cube.o: src/Cube.cpp
|
bin/BoundingBox.o: src/BoundingBox.cpp
|
||||||
# $(pro)
|
$(pro)
|
||||||
bin/Color.o: src/Color.cpp
|
bin/Color.o: src/Color.cpp
|
||||||
$(pro)
|
$(pro)
|
||||||
bin/Quad.o: src/Quad.cpp
|
bin/Quad.o: src/Quad.cpp
|
||||||
$(pro)
|
$(pro)
|
||||||
bin/Vector.o: src/Vector.cpp
|
bin/Vector.o: src/Vector.cpp
|
||||||
$(pro)
|
$(pro)
|
||||||
|
bin/phys_obj.o: src/phys_obj.cpp
|
||||||
|
$(pro)
|
||||||
|
|
||||||
#targets = $(patsubst bin/%.o,src/%.cpp,$(goals))
|
#targets = $(patsubst bin/%.o,src/%.cpp,$(goals))
|
||||||
#$(goals): $(targets) ;
|
#$(goals): $(targets) ;
|
||||||
|
|||||||
@ -26,5 +26,4 @@ int Window::initUI() {
|
|||||||
-1,
|
-1,
|
||||||
SDL_RENDERER_ACCELERATED
|
SDL_RENDERER_ACCELERATED
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
30
src/main.cpp
30
src/main.cpp
@ -1,8 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
#include <vector>
|
#include "phys_obj.h"
|
||||||
#include "Quad.h"
|
|
||||||
|
|
||||||
SDL_Window *win = NULL;
|
SDL_Window *win = NULL;
|
||||||
SDL_Renderer *rend = 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() {
|
int main() {
|
||||||
init();
|
init();
|
||||||
cc = Color(BLACK);
|
cc = Color(BLACK);
|
||||||
@ -78,8 +81,8 @@ int main() {
|
|||||||
|
|
||||||
Quad rect;
|
Quad rect;
|
||||||
|
|
||||||
Quad *grav_objs = (Quad *)malloc(0);
|
std::vector<phys_obj> objs;
|
||||||
std::vector<Quad> objs;
|
//std::vector<int> yvalues;
|
||||||
|
|
||||||
while(run) {
|
while(run) {
|
||||||
if(modified) {
|
if(modified) {
|
||||||
@ -103,7 +106,7 @@ int main() {
|
|||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
printf("Mouse released at %i,%i\n",x2,y2);
|
printf("Mouse released at %i,%i\n",x2,y2);
|
||||||
trackmouse = false;
|
trackmouse = false;
|
||||||
objs.push_back(rect);
|
objs.push_back(phys_obj(rect, Vector(0,0)));
|
||||||
//grav_objs = (Quad *)calloc(1,sizeof(Quad));
|
//grav_objs = (Quad *)calloc(1,sizeof(Quad));
|
||||||
//grav_objs[sizeof(grav_objs)/sizeof(grav_objs[0])] = rect;
|
//grav_objs[sizeof(grav_objs)/sizeof(grav_objs[0])] = rect;
|
||||||
//printf("grav objs: %lu\n",(sizeof(grav_objs)/sizeof(grav_objs[0])));
|
//printf("grav objs: %lu\n",(sizeof(grav_objs)/sizeof(grav_objs[0])));
|
||||||
@ -158,6 +161,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
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);
|
//change_vector[0] = clamp(&buffer.x,clamp_min);
|
||||||
@ -167,12 +177,11 @@ int main() {
|
|||||||
rect.setColor(Color(GREEN));
|
rect.setColor(Color(GREEN));
|
||||||
rect.render(rend);
|
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++) {
|
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(change_vector[0]) {
|
||||||
if(buffer.x != 0.0) {
|
if(buffer.x != 0.0) {
|
||||||
@ -193,7 +202,6 @@ int main() {
|
|||||||
quad.translate(buffer);
|
quad.translate(buffer);
|
||||||
quad.render(rend);
|
quad.render(rend);
|
||||||
SDL_RenderPresent(rend);
|
SDL_RenderPresent(rend);
|
||||||
SDL_GetWindowSize(win,&w,&h);
|
|
||||||
SDL_Delay(1000/60);
|
SDL_Delay(1000/60);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user