Skip to content
Browse files

Many modifications, bug fix the pivot point for texture.

  • Loading branch information...
1 parent 83e743f commit 512c862cfe3b98f566fa4f5cda88bd701ad9562e @batiste committed Jun 13, 2012
View
2 Makefile
@@ -1,5 +1,5 @@
CFLAGS = -g -O2
-LDFLAGS_GL = -lGL
+LDFLAGS_GL = -lGL -lm
LDFLAGS_MESA = -lMesaGL
SDLFLAGS = $(shell sdl2-config --libs --cflags)
CC=gcc
View
1 android-sdl/AndroidManifest.xml
@@ -7,6 +7,7 @@
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="SDLActivity"
+ android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
View
4 android-sdl/assets/texture-shader-1.frag
@@ -8,7 +8,5 @@ varying mat4 rotate_matrix_2;
uniform sampler2D s_texture;
void main()
{
- gl_FragColor = texture2D( s_texture, v_texCoord ) * vec4(
- v_texCoord[1] / 1.0,
- 1.0, 1.0, 1.0);
+ gl_FragColor = texture2D( s_texture, v_texCoord );
}
View
1 android-sdl/build.sh
@@ -1,4 +1,5 @@
cp -R ../*.c jni/src
cp -R ../*.h jni/src
+rm assets/*
cp -R ../assets/* assets/
ndk-build && ant debug
View
BIN assets/SDL_logo.bmp
Binary file not shown.
View
BIN assets/SDL_logo_64.bmp
Binary file not shown.
View
BIN assets/bamboo.bmp
Binary file not shown.
View
4 assets/texture-shader-1.frag
@@ -8,7 +8,5 @@ varying mat4 rotate_matrix_2;
uniform sampler2D s_texture;
void main()
{
- gl_FragColor = texture2D( s_texture, v_texCoord ) * vec4(
- v_texCoord[1] / 1.0,
- 1.0, 1.0, 1.0);
+ gl_FragColor = texture2D( s_texture, v_texCoord );
}
View
24 common.c
@@ -4,6 +4,7 @@
#include "lodepng.h"
#include "lodepng.c"
#include "list.c"
+#include "math.c"
#define LOG_TAG "SDL"
@@ -735,16 +736,16 @@ GLfloat * transformTexture(struct TextureInfos * texture, float tx, float ty, fl
// rotate and translate the vertices
for(i=0; i<size; i=i+5) {
// back to the origin
- x = texture->vertices[i+0] - texture->px;
- y = texture->vertices[i+1] - texture->py;
+ x = texture->vertices[i+0] - texture->x;
+ y = texture->vertices[i+1] - texture->y;
// rotate point
float new_x = x * cos_a - y * sin_a;
float new_y = x * sin_a + y * cos_a;
// translate back from pivot and add translation
- new_x = new_x + texture->px + tx;
- new_y = new_y + texture->py + ty;
+ new_x = new_x + texture->x + tx;
+ new_y = new_y + texture->y + ty;
texture->vertices[i+0] = new_x;
texture->vertices[i+1] = new_y;
@@ -988,6 +989,7 @@ int getMouse(int* x, int* y) {
// the screen
int hw = screen.w / 2.0;
int hh = screen.h / 2.0;
+ ListElement *el;
#ifdef ANDROID
*(x) = (int)_mouse_x - hw;
*(y) = -((int)_mouse_y - hh);
@@ -1002,12 +1004,22 @@ int getMouse(int* x, int* y) {
pos->x = *(x);
pos->y = *(y);
+ if(mouse_buffer.first) {
+ MousePosition *first = (MousePosition *)mouse_buffer.first->data;
+
+ // reset the mouse buffer in case of big jump
+ if(distance_2_points(pos->x, pos->y, first->x, first->y) > 200) {
+ for(el = mouse_buffer.first; el != NULL; el=el->next) {
+ removeFromList(&mouse_buffer, el);
+ }
+ }
+ }
+
addToList(&mouse_buffer, pos);
- while(mouse_buffer.length > 10) {
+ while(mouse_buffer.length > 6) {
free(mouse_buffer.last->data);
removeFromList(&mouse_buffer, mouse_buffer.last);
}
- //displayList(&mouse_buffer);
}
View
285 intersection.c
@@ -0,0 +1,285 @@
+
+struct Line {
+ float ax;
+ float ay;
+ float bx;
+ float by;
+};
+
+// Returns 1 if the lines intersect, otherwise 0. In addition, if the lines
+// intersect the intersection point may be stored in the floats i_x and i_y.
+int get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
+ float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
+{
+ float s1_x, s1_y, s2_x, s2_y;
+ s1_x = p1_x - p0_x; s1_y = p1_y - p0_y;
+ s2_x = p3_x - p2_x; s2_y = p3_y - p2_y;
+
+ float s, t;
+ s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
+ t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);
+
+ if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
+ {
+ // Collision detected
+ if (i_x != NULL)
+ *i_x = p0_x + (t * s1_x);
+ if (i_y != NULL)
+ *i_y = p0_y + (t * s1_y);
+ return 1;
+ }
+
+ return 0; // No collision
+}
+
+
+int find_intersect_points(struct TextureInfos * texture, struct Line * line, GLfloat * points) {
+
+ int i;
+ float intersect_x;
+ float intersect_y;
+ int nbPoints = 0;
+ int size = texture->verticesSize * 5;
+
+ for(i=0; i<size; i=i+5) {
+ if(get_line_intersection(
+ texture->vertices[i % size], texture->vertices[(i+1) % size], // p1
+ texture->vertices[(i+5) % size], texture->vertices[(i+6) % size], // p2
+ line->ax, line->ay, // p3
+ line->bx, line->by, // p4
+ &intersect_x, &intersect_y
+ )) {
+ points[2 * nbPoints] = intersect_x;
+ points[2 * nbPoints + 1] = intersect_y;
+ nbPoints = nbPoints + 1;
+ if(nbPoints > 2) {
+ LOG("Intersection error, more than 2 points found: %d", nbPoints)
+ return 0;
+ }
+
+ }
+ }
+
+ return nbPoints;
+}
+
+
+struct Intersection {
+ float x;
+ float y;
+ int index_p1;
+ int index_p2;
+};
+
+
+int split_vertex(struct TextureInfos * texture, struct Line * line,
+ struct TextureInfos * texture1, struct TextureInfos * texture2) {
+
+ int i;
+ float intersect_x;
+ float intersect_y;
+ int nbIntersections = 0;
+ struct Intersection intersections[2];
+ int size = texture->verticesSize * 5;
+
+ for(i=0; i<size; i=i+5) {
+ if(get_line_intersection(
+ texture->vertices[i % size], texture->vertices[(i+1) % size], // p1
+ texture->vertices[(i+5) % size], texture->vertices[(i+6) % size], // p2
+ line->ax, line->ay, // p3
+ line->bx, line->by, // p4
+ &intersect_x, &intersect_y
+ )) {
+ intersections[nbIntersections].x = intersect_x;
+ intersections[nbIntersections].y = intersect_y;
+
+ intersections[nbIntersections].index_p1 = i % size;
+ intersections[nbIntersections].index_p2 = (i+5) % size;
+
+ nbIntersections = nbIntersections + 1;
+ if(nbIntersections > 2) {
+ LOG("Intersection error, more than 2 points found: %d", nbIntersections)
+ return 0;
+ }
+ }
+ }
+
+ if(nbIntersections != 2)
+ return 0;
+
+ createNewVertexFromIntersection(&intersections, texture, texture1);
+ struct Intersection inverted_intersections[2];
+ inverted_intersections[0] = intersections[1];
+ inverted_intersections[1] = intersections[0];
+
+ createNewVertexFromIntersection(&inverted_intersections, texture, texture2);
+
+ return nbIntersections;
+}
+
+
+int createNewVertexFromIntersection(
+
+ struct Intersection intersections[2],
+ struct TextureInfos * texture,
+ struct TextureInfos * newTexture) {
+
+ int j = 0, i = 0;
+ int size = texture->verticesSize * 5;
+
+ // start point to built the new vertex
+ int current_index = intersections[0].index_p2;
+
+ // crash after 12 vertices
+ int safeGuard = 5 * 12;
+ // there has to be at least 1 vertices to take from the old
+ int nbVertices = 0;
+ // count the new vertices to take from the old vertices
+ while(current_index != intersections[1].index_p2) {
+ nbVertices = nbVertices + 1;
+ current_index = (current_index+5) % size;
+ safeGuard = safeGuard - 1;
+ if(safeGuard < 0) {
+ LOG("Unexpected big vertex, current index %d, %d", current_index, intersections[1].index_p2)
+ exit(1);
+ }
+ }
+
+ newTexture->verticesSize = 2 + nbVertices;
+
+ // allocate memory for the new vertices
+ GLfloat * new_vertices = malloc((5 * (newTexture->verticesSize)) * sizeof(GLfloat));
+
+
+ int indicesSize = ((newTexture->verticesSize - 2) * 3);
+ // allocate memory for the texture indices
+ newTexture->indices = malloc(indicesSize * sizeof(GLshort));
+
+ j = 0;
+ for(i=0; i<indicesSize; i=i+3) {
+ newTexture->indices[i] = 0; // always 0
+ newTexture->indices[i+1] = 1 + j;
+ newTexture->indices[i+2] = 2 + j;
+ j = j + 1;
+ }
+
+
+ float segment_length = distance_2_points(
+ texture->vertices[intersections[0].index_p1+0],
+ texture->vertices[intersections[0].index_p1+1],
+ texture->vertices[intersections[0].index_p2+0],
+ texture->vertices[intersections[0].index_p2+1]
+ );
+ float distance_intersection = distance_2_points(
+ texture->vertices[intersections[0].index_p2+0],
+ texture->vertices[intersections[0].index_p2+1],
+ intersections[0].x,
+ intersections[0].y);
+ float ratio_1 = distance_intersection / segment_length;
+
+ segment_length = distance_2_points(
+ texture->vertices[intersections[1].index_p1+0],
+ texture->vertices[intersections[1].index_p1+1],
+ texture->vertices[intersections[1].index_p2+0],
+ texture->vertices[intersections[1].index_p2+1]
+ );
+ distance_intersection = distance_2_points(
+ texture->vertices[intersections[1].index_p1+0],
+ texture->vertices[intersections[1].index_p1+1],
+ intersections[1].x,
+ intersections[1].y);
+
+ float ratio_2 = distance_intersection / segment_length;
+
+ if(ratio_1 > 1.0 || ratio_2 > 1.0) {
+ LOG("ERROR RATIO %f, %f", ratio_1, ratio_2);
+ exit(1);
+ }
+
+ // start the new vertices with the 2 collision points
+ new_vertices[0] = intersections[1].x;
+ new_vertices[1] = intersections[1].y;
+ new_vertices[2] = 0.0f;
+ // texture coordinates
+ float x_texture;
+ float y_texture;
+
+ float a = texture->vertices[intersections[1].index_p1+3];
+ float b = texture->vertices[intersections[1].index_p2+3];
+ float c = abs(a - b) * ratio_2;
+ if(a < b) {
+ x_texture = a + c;
+ } else {
+ x_texture = a - c;
+ }
+
+ a = texture->vertices[intersections[1].index_p1+4];
+ b = texture->vertices[intersections[1].index_p2+4];
+ c = abs(a - b) * ratio_2;
+ if(a < b) {
+ y_texture = a + c;
+ } else {
+ y_texture = a - c;
+ }
+
+
+ new_vertices[3] = x_texture ; // x
+ new_vertices[4] = y_texture ; // y
+
+ new_vertices[5] = intersections[0].x;
+ new_vertices[6] = intersections[0].y;
+ new_vertices[7] = 0.0f;
+
+ // texture coordinates
+ a = texture->vertices[intersections[0].index_p2+3];
+ b = texture->vertices[intersections[0].index_p1+3];
+ c = abs(a - b) * ratio_1;
+ if(a < b) {
+ x_texture = a + c;
+ } else {
+ x_texture = a - c;
+ }
+
+ a = texture->vertices[intersections[0].index_p2+4];
+ b = texture->vertices[intersections[0].index_p1+4];
+ c = abs(a - b) * ratio_1;
+ if(a < b) {
+ y_texture = a + c;
+ } else {
+ y_texture = a - c;
+ }
+ new_vertices[8] = x_texture ; // x
+ new_vertices[9] = y_texture ; // y
+
+ //LOG("TEXTURE COORD %f %f", new_vertices[3], new_vertices[4])
+ //LOG("TEXTURE COORD %f %f", new_vertices[8], new_vertices[9])
+
+ int old_index = intersections[0].index_p2;
+
+ // fill with the rest old vertices
+ int new_index = 10;
+ while(nbVertices > 0) {
+ new_vertices[new_index] = texture->vertices[old_index];
+ new_vertices[new_index+1] = texture->vertices[old_index+1];
+ new_vertices[new_index+2] = texture->vertices[old_index+2];
+ // copy the same texture coordinates as before
+ new_vertices[new_index+3] = texture->vertices[old_index+3];
+ new_vertices[new_index+4] = texture->vertices[old_index+4];
+
+ old_index = (old_index+5) % size;
+ nbVertices = nbVertices-1;
+ new_index = (new_index+5) % (newTexture->verticesSize * 5);
+ }
+
+ // copy the new vertices
+ newTexture->vertices = new_vertices;
+ // copy the texture object
+ newTexture->texture = texture->texture;
+
+ /*LOG("nb vertices %d", newTexture->verticesSize)
+ for(i=0; i<(newTexture->verticesSize * 5); i=i+5) {
+ LOG("x: %f y: %f", newTexture->vertices[i], newTexture->vertices[i+1]);
+ }*/
+
+ return 0;
+}
View
284 math.c
@@ -9,289 +9,5 @@ double distance_2_points(float x1, float y1, float x2, float y2) {
}
-// Returns 1 if the lines intersect, otherwise 0. In addition, if the lines
-// intersect the intersection point may be stored in the floats i_x and i_y.
-int get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
- float p2_x, float p2_y, float p3_x, float p3_y, float *i_x, float *i_y)
-{
- float s1_x, s1_y, s2_x, s2_y;
- s1_x = p1_x - p0_x; s1_y = p1_y - p0_y;
- s2_x = p3_x - p2_x; s2_y = p3_y - p2_y;
- float s, t;
- s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / (-s2_x * s1_y + s1_x * s2_y);
- t = ( s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / (-s2_x * s1_y + s1_x * s2_y);
-
- if (s >= 0 && s <= 1 && t >= 0 && t <= 1)
- {
- // Collision detected
- if (i_x != NULL)
- *i_x = p0_x + (t * s1_x);
- if (i_y != NULL)
- *i_y = p0_y + (t * s1_y);
- return 1;
- }
-
- return 0; // No collision
-}
-
-
-struct Line {
- float ax;
- float ay;
- float bx;
- float by;
-};
-
-
-int find_intersect_points(struct TextureInfos * texture, struct Line * line, GLfloat * points) {
-
- int i;
- float intersect_x;
- float intersect_y;
- int nbPoints = 0;
- int size = texture->verticesSize * 5;
-
- for(i=0; i<size; i=i+5) {
- if(get_line_intersection(
- texture->vertices[i % size], texture->vertices[(i+1) % size], // p1
- texture->vertices[(i+5) % size], texture->vertices[(i+6) % size], // p2
- line->ax, line->ay, // p3
- line->bx, line->by, // p4
- &intersect_x, &intersect_y
- )) {
- points[2 * nbPoints] = intersect_x;
- points[2 * nbPoints + 1] = intersect_y;
- nbPoints = nbPoints + 1;
- if(nbPoints > 2) {
- LOG("Intersection error, more than 2 points found: %d", nbPoints)
- exit(1);
- }
-
- }
- }
-
- return nbPoints;
-}
-
-
-struct Intersection {
- float x;
- float y;
- int index_p1;
- int index_p2;
-};
-
-
-int split_vertex(struct TextureInfos * texture, struct Line * line,
- struct TextureInfos * texture1, struct TextureInfos * texture2) {
-
- int i;
- float intersect_x;
- float intersect_y;
- int nbIntersections = 0;
- struct Intersection intersections[2];
- int size = texture->verticesSize * 5;
-
- for(i=0; i<size; i=i+5) {
- if(get_line_intersection(
- texture->vertices[i % size], texture->vertices[(i+1) % size], // p1
- texture->vertices[(i+5) % size], texture->vertices[(i+6) % size], // p2
- line->ax, line->ay, // p3
- line->bx, line->by, // p4
- &intersect_x, &intersect_y
- )) {
- intersections[nbIntersections].x = intersect_x;
- intersections[nbIntersections].y = intersect_y;
-
- intersections[nbIntersections].index_p1 = i % size;
- intersections[nbIntersections].index_p2 = (i+5) % size;
-
- nbIntersections = nbIntersections + 1;
- if(nbIntersections > 2) {
- LOG("Intersection error, more than 2 points found: %d", nbIntersections)
- exit(1);
- }
- }
- }
-
- if(nbIntersections != 2)
- return 0;
-
- createNewVertexFromIntersection(&intersections, texture, texture1);
- struct Intersection inverted_intersections[2];
- inverted_intersections[0] = intersections[1];
- inverted_intersections[1] = intersections[0];
-
- createNewVertexFromIntersection(&inverted_intersections, texture, texture2);
-
- return nbIntersections;
-}
-
-
-int createNewVertexFromIntersection(
-
- struct Intersection intersections[2],
- struct TextureInfos * texture,
- struct TextureInfos * newTexture) {
-
- int j = 0, i = 0;
- int size = texture->verticesSize * 5;
-
- // start point to built the new vertex
- int current_index = intersections[0].index_p2;
-
- // crash after 12 vertices
- int safeGuard = 5 * 12;
- // there has to be at least 1 vertices to take from the old
- int nbVertices = 0;
- // count the new vertices to take from the old vertices
- while(current_index != intersections[1].index_p2) {
- nbVertices = nbVertices + 1;
- current_index = (current_index+5) % size;
- safeGuard = safeGuard - 1;
- if(safeGuard < 0) {
- LOG("Unexpected big vertex, current index %d, %d", current_index, intersections[1].index_p2)
- exit(1);
- }
- }
-
- newTexture->verticesSize = 2 + nbVertices;
-
- // allocate memory for the new vertices
- GLfloat * new_vertices = malloc((5 * (newTexture->verticesSize)) * sizeof(GLfloat));
-
-
- int indicesSize = ((newTexture->verticesSize - 2) * 3);
- // allocate memory for the texture indices
- newTexture->indices = malloc(indicesSize * sizeof(GLshort));
-
- j = 0;
- for(i=0; i<indicesSize; i=i+3) {
- newTexture->indices[i] = 0; // always 0
- newTexture->indices[i+1] = 1 + j;
- newTexture->indices[i+2] = 2 + j;
- j = j + 1;
- }
-
-
- float segment_length = distance_2_points(
- texture->vertices[intersections[0].index_p1+0],
- texture->vertices[intersections[0].index_p1+1],
- texture->vertices[intersections[0].index_p2+0],
- texture->vertices[intersections[0].index_p2+1]
- );
- float distance_intersection = distance_2_points(
- texture->vertices[intersections[0].index_p2+0],
- texture->vertices[intersections[0].index_p2+1],
- intersections[0].x,
- intersections[0].y);
- float ratio_1 = distance_intersection / segment_length;
-
- segment_length = distance_2_points(
- texture->vertices[intersections[1].index_p1+0],
- texture->vertices[intersections[1].index_p1+1],
- texture->vertices[intersections[1].index_p2+0],
- texture->vertices[intersections[1].index_p2+1]
- );
- distance_intersection = distance_2_points(
- texture->vertices[intersections[1].index_p1+0],
- texture->vertices[intersections[1].index_p1+1],
- intersections[1].x,
- intersections[1].y);
-
- float ratio_2 = distance_intersection / segment_length;
-
- if(ratio_1 > 1.0 || ratio_2 > 1.0) {
- LOG("ERROR RATIO %f, %f", ratio_1, ratio_2);
- exit(1);
- }
-
- // start the new vertices with the 2 collision points
- new_vertices[0] = intersections[1].x;
- new_vertices[1] = intersections[1].y;
- new_vertices[2] = 0.0f;
- // texture coordinates
- float x_texture;
- float y_texture;
-
- float a = texture->vertices[intersections[1].index_p1+3];
- float b = texture->vertices[intersections[1].index_p2+3];
- float c = abs(a - b) * ratio_2;
- if(a < b) {
- x_texture = a + c;
- } else {
- x_texture = a - c;
- }
-
- a = texture->vertices[intersections[1].index_p1+4];
- b = texture->vertices[intersections[1].index_p2+4];
- c = abs(a - b) * ratio_2;
- if(a < b) {
- y_texture = a + c;
- } else {
- y_texture = a - c;
- }
-
-
- new_vertices[3] = x_texture ; // x
- new_vertices[4] = y_texture ; // y
-
- new_vertices[5] = intersections[0].x;
- new_vertices[6] = intersections[0].y;
- new_vertices[7] = 0.0f;
-
- // texture coordinates
- a = texture->vertices[intersections[0].index_p2+3];
- b = texture->vertices[intersections[0].index_p1+3];
- c = abs(a - b) * ratio_1;
- if(a < b) {
- x_texture = a + c;
- } else {
- x_texture = a - c;
- }
-
- a = texture->vertices[intersections[0].index_p2+4];
- b = texture->vertices[intersections[0].index_p1+4];
- c = abs(a - b) * ratio_1;
- if(a < b) {
- y_texture = a + c;
- } else {
- y_texture = a - c;
- }
- new_vertices[8] = x_texture ; // x
- new_vertices[9] = y_texture ; // y
-
- //LOG("TEXTURE COORD %f %f", new_vertices[3], new_vertices[4])
- //LOG("TEXTURE COORD %f %f", new_vertices[8], new_vertices[9])
-
- int old_index = intersections[0].index_p2;
-
- // fill with the rest old vertices
- int new_index = 10;
- while(nbVertices > 0) {
- new_vertices[new_index] = texture->vertices[old_index];
- new_vertices[new_index+1] = texture->vertices[old_index+1];
- new_vertices[new_index+2] = texture->vertices[old_index+2];
- // copy the same texture coordinates as before
- new_vertices[new_index+3] = texture->vertices[old_index+3];
- new_vertices[new_index+4] = texture->vertices[old_index+4];
-
- old_index = (old_index+5) % size;
- nbVertices = nbVertices-1;
- new_index = (new_index+5) % (newTexture->verticesSize * 5);
- }
-
- // copy the new vertices
- newTexture->vertices = new_vertices;
- // copy the texture object
- newTexture->texture = texture->texture;
-
- /*LOG("nb vertices %d", newTexture->verticesSize)
- for(i=0; i<(newTexture->verticesSize * 5); i=i+5) {
- LOG("x: %f y: %f", newTexture->vertices[i], newTexture->vertices[i+1]);
- }*/
-
- return 0;
-}
View
77 my_app.c
@@ -1,6 +1,6 @@
#include "common.c"
-#include "math.c"
+#include "intersection.c"
int main(int argc, char** argv)
{
@@ -21,7 +21,7 @@ int main(int argc, char** argv)
// load texture
struct ImageData png;
- png.filename = "bamboo.png";
+ png.filename = "bamboo-2.png";
loadPNG(&png);
struct TextureInfos texture;
@@ -31,21 +31,19 @@ int main(int argc, char** argv)
// load texture
struct ImageData background;
- background.filename = "background.png";
+ background.filename = "bamboo-b2.png";
loadPNG(&background);
- struct TextureInfos back1;
+ struct TextureInfos back;
float scalex = screen.w / (float)background.width;
- float scaley = screen.h / (float)background.height + .01;
+ loadTexture(&back, &background, scalex, scalex);
+ transformTexture(&back, 0, -back.height / 2.0 + screen.h / 2.0, 0);
- loadTexture(&back1, &background, scalex, scaley);
- struct TextureInfos back2;
- loadTexture(&back2, &background, scalex, scaley);
CHECK_GL();
CHECK_SDL();
- glClearColor(0.5f, 0.7f, 1.0f, 0.0f);
+ glClearColor(110. / 255., 127. / 255., 91. / 255., 0.0f);
float x, y;
@@ -67,7 +65,7 @@ int main(int argc, char** argv)
GenericList pieces = { 0, NULL, NULL };
- transformTexture(&back2, 0, -back2.height, 0);
+ transformTexture(&texture, 0, 200.0, 0.00);
// Main loop
while (!done) {
@@ -79,25 +77,22 @@ int main(int argc, char** argv)
}
}
-
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
CHECK_GL();
useProgram(textureProgram);
CHECK_GL();
- if(back2.y > (back2.height / 2.0 + screen.h / 2.0))
- transformTexture(&back2, 0, -2 * back2.height, 0);
- transformTexture(&back2, 0, 5, 0);
- drawTexture(&back2, 0, 0, 0);
-
- if(back1.y > (back2.height / 2.0 + screen.h / 2.0))
- transformTexture(&back1, 0, -2 * back2.height, 0);
- transformTexture(&back1, 0, 5, 0);
- drawTexture(&back1, 0, 0, 0);
-
+ if(back.y < (back.height - screen.h) / 2.0) {
+ transformTexture(&back, 0, 1, 0);
+ transformTexture(&texture, 0, 0, 0.01);
+ }
+ else if(texture.y > -((screen.h / 2.0) -30)) {
+ transformTexture(&texture, 0, -3, 0);
+ transformTexture(&texture, 0, 0, 0.01);
+ }
+ drawTexture(&back, 0, 0, 0);
- transformTexture(&texture, 0, 0, 0.01);
drawTexture(&texture, 0, 0, 0);
CHECK_GL();
@@ -151,14 +146,13 @@ int main(int argc, char** argv)
line.by = last->y;
}
-
int nbPoints = 0;
if(nbPoints = find_intersect_points(&texture, &line, points)) {
useProgram(pointProgram);
drawLines(points, nbPoints);
if(nbPoints > 1 && lastCut < frames) {
- lastCut = frames + 10;
+ lastCut = frames + 5;
struct TextureInfos * texture1 = malloc(sizeof(struct TextureInfos));
struct TextureInfos * texture2 = malloc(sizeof(struct TextureInfos));
@@ -171,8 +165,8 @@ int main(int argc, char** argv)
texture1->vx = 2.0;
texture2->vx = -2.0;
- texture1->vy = -2.0;
- texture2->vy = -2.0;
+ texture1->vy = -1.0;
+ texture2->vy = -1.0;
texture1->vr = 0.01;
texture2->vr = -0.01;
@@ -193,15 +187,44 @@ int main(int argc, char** argv)
continue;
}
+ if(nbPoints = find_intersect_points(myTexture, &line, points)) {
+ useProgram(pointProgram);
+ drawLines(points, nbPoints);
+ if(nbPoints > 1 && lastCut < frames) {
+
+ lastCut = frames + 5;
+
+ struct TextureInfos * texture1 = malloc(sizeof(struct TextureInfos));
+ struct TextureInfos * texture2 = malloc(sizeof(struct TextureInfos));
+
+ split_vertex(myTexture, &line, texture1, texture2);
+
+ addToList(&pieces, texture1);
+ addToList(&pieces, texture2);
+
+ texture1->vx = 2.0;
+ texture2->vx = -2.0;
+
+ texture1->vy = -2.0;
+ texture2->vy = -2.0;
+
+ texture1->vr = 0.01;
+ texture2->vr = -0.01;
+ removeFromList(&pieces, el);
+
+ }
+ }
+
// gravity
- myTexture->vy = myTexture->vy - 0.25;
+ myTexture->vy = myTexture->vy - 0.15;
transformTexture(myTexture, myTexture->vx, myTexture->vy, myTexture->vr);
useProgram(textureProgram);
drawTexture(myTexture, 0, 0, 0);
}
+ //transformTexture(&texture, 0, -200.0, 0.00);
SDL_GL_SwapWindow(mainwindow);

0 comments on commit 512c862

Please sign in to comment.
Something went wrong with that request. Please try again.