Skip to content

Instantly share code, notes, and snippets.

from __future__ import division, print_function
from PIL import Image
import sys
import math
IMAGE_WIDTH = int(sys.argv[3])
IMAGE_HEIGHT = int(sys.argv[4])
# sys.argv[5] is a string marking the shift parameter, we don't need that
CAMERA_DISTANCE = 20
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
// For profiling
#include <time.h>
// Size of each individual image
int image_width=0;
// Create a VAO
GLuint gridVAO;
glGenVertexArrays(1, &gridVAO);
glBindVertexArray(gridVAO);
// Allocate and upload the VBO data
GLuint gridVBO;
glGenBuffers(1, &gridVBO);
glBindBuffer(GL_ARRAY_BUFFER, gridVBO);
glBufferData(GL_ARRAY_BUFFER, MAP_WIDTH * MAP_HEIGHT * sizeof(float) * 3, grid_vertices, GL_STATIC_DRAW);
float *grid_vertices;
int index = 0;
grid_vertices = calloc(9, sizeof(float));
grid_vertices[index++] = -5.0;
grid_vertices[index++] = 0.0;
grid_vertices[index++] = -1.0;
grid_vertices[index++] = 5.0;
grid_vertices[index++] = 0.0;
grid_vertices[index++] = -1.0;
void generate_view_matrix(GLfloat *matrix, point *cam_pos, point *cam_dir)
{
// http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml
// f = cam_dir, up = (0|1|0)
// s = normalize(f X up)
// u = s X f
double x = cam_dir->x, y = cam_dir->y, z = cam_dir->z;
double l = sqrt(z*z + x*x);
double s_x = -z/l, s_z = x/l;
double u_x = -s_z*y, u_y = s_z*x - s_x*z, u_z = s_x*y;
// Make the actual 2d array
map->mask = (bool**) calloc(map->width, sizeof(bool*));
for (int i=0; i<map->width; i++)
{
map->mask[i] = (bool*) calloc(map->height, sizeof(bool));
}
// Data is stored in the first 6 bits of every byte, and apparently bottom-right to top-left
int bitmask = 0x1;
char* index = end_position - 1;
#include "move.h"
#include "data_types.h"
#include <math.h>
#define GRAVITY 0.6
#define OUTPUT_LENGTH 2
#define DIRECTION 0
#define DIR_LEFT -1
// If we're not inside our current/last rectangle, then we are in the air flying towards our destination, so we should just continue to do that
if (character->x < current_rect->bottomleft.x || character->x > current_rect->bottomright.x || character->y < current_rect->topleft.y || character->y > current_rect->bottomleft.y)
{
// Get the equation of the parabola of our current falling (in the form y = ax^2 + bx + c)
double a, b, c;
a = GRAVITY/2;
b = sqrt(character->hs*character->hs + character->vs*character->vs) - 2*a*character->x;
c = character->y - a*character->x*character->x - b*character->x;
// Test whether we'll land within the right boundaries with the current path
char* get_commands(Navmesh *mesh, Character *character, Rect *current_rect, Rect *next_rect)
{
char *output = calloc(sizeof(char), OUTPUT_LENGTH);
// If we're not inside our current/last rectangle, then we are in the air flying towards our destination, so we should just continue to do that
if (character->x < current_rect->bottomleft.x || character->x > current_rect->bottomright.x || character->y < current_rect->topleft.y || character->y > current_rect->bottomleft.y)
{
// Get the equation of the parabola of our current falling (in the form y = ax^2 + bx + c)
double a, b, c;
a = GRAVITY/2;
void export_navmesh(Navmesh *mesh, char* name)
{
char filename[strlen(name)+strlen(".navmesh")];
strcpy(filename, name);
strcat(filename, ".navmesh");
FILE *f;
f = fopen(filename, "w");
fwrite((const void*) &(mesh->num_rects), sizeof(int), 1, f);
RectLinkedList *l;