main.c
#include <stdio.h>
#include <math.h>
#include <il/il.h>
#include "vec3.h"
#include "sample.h"
#include "shapes.h"
#define IMAGE_WIDTH 512
#define IMAGE_HEIGHT 384
#define NUM_SAMPLES 16
shape_t shapes[4];
light_t lights[1];
typedef struct camera_s
{
vec3 eye;
vec3 lookat;
vec3 up;
float d; // dist to perfect focus
float aperature;
float l,r,t,b; // extents of view
} camera_t;
unsigned char floattochar(float c)
{
int i = (int)c;
if (i <= 0)
return 0;
if (i >= 255)
return 255;
else
return (unsigned char)(c);
}
int main(int argc, int argv)
{
int r, c, s;
float x_samples[NUM_SAMPLES];
float y_samples[NUM_SAMPLES];
float xl_samples[NUM_SAMPLES];
float yl_samples[NUM_SAMPLES];
float t_samples[NUM_SAMPLES];
unsigned char image[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
float aspect;
vec3 total, color, hitpos;
vec3 start, end, dir;
hit_t hit;
camera_t cam;
vec3 cam_f, cam_r, cam_u;
ILuint iname;
ilInit();
ilEnable(IL_FILE_OVERWRITE);
// 高,宽比
aspect = (float) IMAGE_HEIGHT / (float)IMAGE_WIDTH;
VectorSet(dir, 0, 0, -1);
// 初始化球和三角形
shapes[0].type = SHAPE_SPHERE;
VectorSet(shapes[0].sphere.center, -2.6f, -0.5f, -1.5f);
shapes[0].sphere.radius = 1;
VectorSet(shapes[0].move_velocity, 0, 0, 0);
VectorSet(shapes[0].color, 1, 0, 0);
shapes[1].ty