~zjm/Moon3D

ref: 0fe31db4998f636b8f65ca790b75c0585ba47d86 Moon3D/src/scene.c -rw-r--r-- 819 bytes
0fe31db4Zack Michener refactor camera/projection to avoid globals 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "scene.h"
#include "arraylist.h"

Scene *NewScene(void)
{
	Scene *s = malloc(sizeof(Scene));
	s->objects = NULL;
	s->lights = NULL;
	s->points = NULL;
	return s;
}

void AddObject(Scene *scene, Object *obj)
{
	list_push(scene->objects, obj);
}

void AddLight(Scene *scene, LightSource *light)
{
	list_push(scene->lights, light);
}

void AddPoint(Scene *scene, Point *point)
{
	list_push(scene->points, point);
}

void RenderScene(Scene *scene, RenderingContext context)
{
	Transform imageTransform = GetProjectionTransform(context.camera, context.projection);

	for (int i = 0; i < list_count(scene->objects); i++) {
		DrawObject(scene->objects[i], scene->lights, context, imageTransform);
	}

	for (int i = 0; i < list_count(scene->points); i++) {
		DrawPoint(scene->points[i], context, imageTransform);
	}
}