Exemple #1
0
void TileSet::tile_add_shape(int p_id, const Ref<Shape2D> &p_shape, const Transform2D &p_transform, bool p_one_way) {

	ERR_FAIL_COND(!tile_map.has(p_id));

	ShapeData new_data = ShapeData();
	new_data.shape = p_shape;
	new_data.shape_transform = p_transform;
	new_data.one_way_collision = p_one_way;

	tile_map[p_id].shapes_data.push_back(new_data);
};
Exemple #2
0
void TileSet::_tile_set_shapes(int p_id, const Array &p_shapes) {

	ERR_FAIL_COND(!tile_map.has(p_id));
	Vector<ShapeData> shapes_data;
	Transform2D default_transform = tile_get_shape_transform(p_id, 0);
	bool default_one_way = tile_get_shape_one_way(p_id, 0);
	for (int i = 0; i < p_shapes.size(); i++) {
		ShapeData s = ShapeData();

		if (p_shapes[i].get_type() == Variant::OBJECT) {
			Ref<Shape2D> shape = p_shapes[i];
			if (shape.is_null()) continue;

			s.shape = shape;
			s.shape_transform = default_transform;
			s.one_way_collision = default_one_way;
		} else if (p_shapes[i].get_type() == Variant::DICTIONARY) {
			Dictionary d = p_shapes[i];

			if (d.has("shape") && d["shape"].get_type() == Variant::OBJECT)
				s.shape = d["shape"];
			else
				continue;

			if (d.has("shape_transform") && d["shape_transform"].get_type() == Variant::TRANSFORM2D)
				s.shape_transform = d["shape_transform"];
			else if (d.has("shape_offset") && d["shape_offset"].get_type() == Variant::VECTOR2)
				s.shape_transform = Transform2D(0, (Vector2)d["shape_offset"]);
			else
				s.shape_transform = default_transform;

			if (d.has("one_way") && d["one_way"].get_type() == Variant::BOOL)
				s.one_way_collision = d["one_way"];
			else
				s.one_way_collision = default_one_way;

		} else {
			ERR_EXPLAIN("Expected an array of objects or dictionaries for tile_set_shapes");
			ERR_CONTINUE(true);
		}

		shapes_data.push_back(s);
	}

	tile_map[p_id].shapes_data = shapes_data;
}
#include <GL/glu.h>
#else
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#endif

#include <cmath>
#include "matm.h"
#include "ShapeData.h"
#include "Primitives.h"

//----------------------------------------------------------------------------
// Cube

const int numCubeVertices = 36; //(6 faces)(2 triangles/face)(3 vertices/triangle)
ShapeData cubeData = ShapeData(numCubeVertices);

// Vertices of a unit cube centered at origin, sides aligned with axes
vec4 vertices[8] = {
    vec4( -0.5, -0.5,  0.5, 1.0 ),
    vec4( -0.5,  0.5,  0.5, 1.0 ),
    vec4(  0.5,  0.5,  0.5, 1.0 ),
    vec4(  0.5, -0.5,  0.5, 1.0 ),
    vec4( -0.5, -0.5, -0.5, 1.0 ),
    vec4( -0.5,  0.5, -0.5, 1.0 ),
    vec4(  0.5,  0.5, -0.5, 1.0 ),
    vec4(  0.5, -0.5, -0.5, 1.0 )
};

// quad generates two triangles for each face and assigns normals and texture coordinates to the vertices
void quad( ShapeData* data, int &Index, int a, int b, int c, int d, float tex_size, const vec3& normal, const vec3& tangent ) {