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 / VoxelTables.cs
Created August 29, 2023 00:01
Voxel tables for making voxel mesh
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public static class VoxelTables
{
// all 8 possible vertices for a voxel
public static readonly Vector3[] Vertices = new Vector3[8]
{
@PaperPrototype
PaperPrototype / VoxelTables.cs
Created August 28, 2023 22:21
Lookup tables for voxel terrain
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class VoxelTables
{
// all 8 possible vertices for a voxel
public static readonly Vector3[] Vertices = new Vector3[8]
{
new Vector3(0.0f, 0.0f, 0.0f),
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;
public class Spatial : Node {
public Transform transform;
}
public class Renderable : Spatial {
public Mesh mesh;
public virtual void Render() {
}
}
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 Node {
public string name; // debug name
public Node[] children;
public virtual void Update()
{
// classes can override this
}
}
struct Object {
struct Object []children;
struct Object *parent;
struct Transform transform;
struct Mesh mesh;
struct MeshCollider collider;
}
@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;
}
// 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 / 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;