Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<script src="jsKart.js"></script>
</head>
<body onload="Init()">
<center>
<canvas id="screen" width="640" height="480" style="border:solid 1px;"></canvas><br>
<canvas id="track" width="1448" height="1448" style="display: none;"></canvas><br>
</center>
</body>
FF = front face (relative to split plane)
BF = back face (also rtsp)
bad split face = face given to split face function was already bad
bad split faces = generated faces are bad (this log ommits bad faces created from a face already bad)
in DZZD, ZDDZ, etc: D = default, Z = zero, M = minus, P = plus
Default = vertex added was not intersection
Zero = vertex was not considered too close to either end of edge
Minus = vertex was too close to point A of edge
Plus = vertex was too close to point B of edge
void rvface_fromsplitbox(const mplane *plane, const vec3 *min, const vec3 *max, rvface *out)
{
int i;
out->num_verts = 0;
for(i = 0; i < 8; i++){
//Calc an edge parallel to either X axis or Y axis
vec3 a = {
(i & 3) ? min->x : (i & 1) ? min->x : max->x,
void rvface_boxslice(const mplane *plane, const vec3 *min, const vec3 *max, rvface *out)
{
int potato[256] = {0};
int i, j, k, l;
int potato2[256] = {0};
/*
Bitfield representing planes on which each edge lies
+Z-Z+Y-Y+X-X
b5b4b3b2b1b0
*/
//Basic plane equation
P . n + d = 0
//Therefore, 3 plane equations
X * n1x + Y * n1y + Z * n1z + d1 = 0
X * n2x + Y * n2y + Z * n2z + d2 = 0
X * n3x + Y * n3y + Z * n3z + d3 = 0
//Isolate X in 1st eq
Y * n1y + Z * n1z + d1 = -X * n1x
/*
This function works in the following manner:
-Find any 4 planes with which splitting plane is not parallel
-Always generate a quad with those 4 planes as sides
-Split quad using rvface_split and all other planes
*/
void rvface_boxslice(const mplane *plane, const vec3 *min, const vec3 *max, rvface *out)
{
//Planes for the box
//Note max_planes don't point inside the box
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
#include <allegro.h>
#include <stdio.h>
int main(int argc, char ** argv)
{
char lin[1024] = "v 0.123 0.456 -0.789";
float x, y, z;
allegro_init();
if(argc > 1) install_keyboard();
sscanf(lin, "%*s %f %f %f", &x, &y, &z);
@kdrnic
kdrnic / arr.h
Last active May 6, 2018 01:49
Dynamic array implementation for C
/*
Generic dynamic array implementation
Usage example:
foo_arr.h
001 #ifndef FOO_ARR_H
002 #define FOO_ARR_H
003 #define ARR_STRUCT_NAME foo_arr
004 #define ARR_TYPE foo
005 #define ARR_ADD_PREFIX(t) foo_arr_ ## t
006 #include "arr.h"
#include <allegro.h>
#include <math.h>
#include <stdio.h>
#include "raster.h"
/*
Illustration of the two subtriangles
-verts[0] -vs[0]=ve[0]