Skip to content

Instantly share code, notes, and snippets.

View PaperPrototype's full-sized avatar

Abdiel Lopez PaperPrototype

  • Nytro Interactive
View GitHub Profile
@PaperPrototype
PaperPrototype / player.c
Last active February 14, 2021 16:17
player struct in C
struct Player {
float pos[3]; // array of 3 floats (aka vector3)
float rot[4]; // array of 4 floats (aka vector4, aka quaternion)
struct Mesh mesh; // if you are in third person u should see your player
struct BoxCollider collider; // collision
}
@PaperPrototype
PaperPrototype / player_components.c
Last active February 7, 2021 18:38
Player "components"
struct Mesh {
int meshIndex; // the number of vertices or "size" of the mesh
float vertices[meshIndex][3]; // array of 3 dimensional floats
float normals[meshIndex][3]; // surface normals
float uvs[meshIndex][2]; // 2 dimensional floats, maps a pixel position on the texture to the corresponding vertex
int triangles[meshIndex]; // in sets of 3 gets vetices by index to make triangles bewteen the 3 vertices
}
struct BoxCollider {
@PaperPrototype
PaperPrototype / game.c
Last active February 14, 2021 16:18
Simple game
# include <renderer.h>
# include <input.h> // other C files except they end in .h
// ... our structs
int main (void) {
// ... initializing a visible os window for rendering
struct Player player;
// the generic objects struct for static objects in the world (obstactles not moving with physics)
struct Object {
struct Transform transform;
struct Mesh mesh;
struct MeshCollider collider;
}
struct Transform {
// float pos[3] or struct with { x, y, z ... } both work
struct Vector3 pos;
@PaperPrototype
PaperPrototype / objects_hierarchy.c
Last active February 7, 2021 20:24
objects with parents
struct Object {
struct Object *parent; // a pointer
struct Transform transform;
struct Mesh mesh;
struct MeshCollider collider;
}
struct Object {
struct Object []children;
struct Object *parent;
struct Transform transform;
struct Mesh mesh;
struct MeshCollider collider;
}
public class Node {
public string name; // debug name
public Node[] children;
public virtual void Update()
{
// classes can override this
}
}
using Rendering;
public class Renderable : Node {
public Mesh mesh;
public virtual Render() {
// this.transform, inherited transform from Node
Rendering.enqeue(this.transform, this.mesh);
}
}
public class Spatial : Node {
public Transform transform;
}
public class Renderable : Spatial {
public Mesh mesh;
public virtual void Render() {
}
}
public class Collider : Spatial {
private Enum ColliderType { Box, Sphere, Capsule };
public virtual float GetArea(ColliderType colliderType) {
switch(colliderType) {
case Box:
// return area of box
break;
case Sphere:
// return area of sphere
break;