Start making an actual road mesh
This commit is contained in:
parent
72bd683900
commit
1815ab9ef2
@ -296,7 +296,6 @@ draw :: proc() {
|
||||
|
||||
camera := game_camera_3d()
|
||||
|
||||
|
||||
{
|
||||
rl.BeginMode3D(camera)
|
||||
defer rl.EndMode3D()
|
||||
@ -311,19 +310,35 @@ draw :: proc() {
|
||||
points := &g_mem.track.points
|
||||
points_len := len(points)
|
||||
|
||||
// road: rl.Mesh
|
||||
// defer rl.UnloadMesh(road)
|
||||
// road_vertices: [dynamic]f32
|
||||
// road_normals: [dynamic]f32
|
||||
// road_uvs: [dynamic]f32
|
||||
// road_indices: [dynamic]u16
|
||||
// road_vertices.allocator = context.temp_allocator
|
||||
// road_normals.allocator = context.temp_allocator
|
||||
// road_uvs.allocator = context.temp_allocator
|
||||
// road_indices.allocator = context.temp_allocator
|
||||
|
||||
// spline_segment_count := max(len(g_mem.track.points) - 4, 0)
|
||||
|
||||
|
||||
SPLINE_SUBDIVS_U :: 4
|
||||
SPLINE_SUBDIVS_V :: 8
|
||||
ROAD_WIDTH :: 2.0
|
||||
|
||||
{
|
||||
rlgl.Begin(rlgl.LINES)
|
||||
defer rlgl.End()
|
||||
|
||||
rlgl.Color3f(1, 0, 0)
|
||||
|
||||
SPLINE_SUBDIVS :: 8
|
||||
|
||||
for i in 0 ..< points_len {
|
||||
if i >= 1 && i < points_len - 2 {
|
||||
for j in 0 ..< SPLINE_SUBDIVS {
|
||||
t := f32(j) / f32(SPLINE_SUBDIVS)
|
||||
t2 := f32(j + 1) / f32(SPLINE_SUBDIVS)
|
||||
for v in 0 ..< SPLINE_SUBDIVS_V {
|
||||
t := f32(v) / f32(SPLINE_SUBDIVS_V)
|
||||
t2 := f32(v + 1) / f32(SPLINE_SUBDIVS_V)
|
||||
point := linalg.catmull_rom(
|
||||
points[i - 1],
|
||||
points[i],
|
||||
@ -339,6 +354,23 @@ draw :: proc() {
|
||||
t2,
|
||||
)
|
||||
|
||||
tangent := linalg.normalize0(point2 - point)
|
||||
right := -linalg.cross(tangent, rl.Vector3{0, 1, 0})
|
||||
// normal := linalg.cross(tangent, right)
|
||||
|
||||
for u in 0 ..< SPLINE_SUBDIVS_U {
|
||||
offset := f32(u) / f32(SPLINE_SUBDIVS_U)
|
||||
offset = offset * 2 - 1
|
||||
offset2 := f32(u + 1) / f32(SPLINE_SUBDIVS_U)
|
||||
offset2 = offset2 * 2 - 1
|
||||
|
||||
p1 := point + offset * right
|
||||
p2 := point + offset2 * right
|
||||
|
||||
rlgl.Vertex3f(p1.x, p1.y, p1.z)
|
||||
rlgl.Vertex3f(p2.x, p2.y, p2.z)
|
||||
}
|
||||
|
||||
rlgl.Vertex3f(point.x, point.y, point.z)
|
||||
rlgl.Vertex3f(point2.x, point2.y, point2.z)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user