Learning C, Day 25 (Camera Clipping 3)

Today I spent about two and a half hours implementing camera clipping. Now the renderer doesn’t crash when objects go off screen! I have yet to interpolate the UV coordinates, though. Textures look broken right now because the new points use the old UV coordinates.

The method for creating triangles from polygons ended up being really simple: I just create a series of triangles, each sharing the first point of the polygon:

# Python pseudo code
def triangles_from_polygon(polygon):
	triangles = []
	for i in range(0, len(polygon.vertices)-2):
		index0 = 0
		index1 = i + 1
		index2 = i + 2
		new_triangle = [
			polygon.vertices[index0],
			polygon.vertices[index1],
			polygon.vertices[index2]
		]
		triangles.append(new_triangle)
	return triangles

Another update on Vim: One of my favorite features so far is the repeat action key. It’s great when I need to duplicate lines and then change one part of them. I can make the change once, go to the next line and hit the period key. It’s so much faster than manually typing everything over and over.

That’s all for today, see you tomorrow for UV interpolation!

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.