70 lines · 1.0 KB · C
RawDownload
#include <u.h>#include <libc.h>#include <thread.h>#include <draw.h>#include <memdraw.h>#include <geometry.h> #include "scene.h"#include "pipes.h" Obj *newlight(Point3 p, double r, Point3 n, Colour c){	Obj *light; 	light = malloc(sizeof(Obj));	if(light == nil)		exits("malloc"); 	light->type = LIGHT;	light->p = p;	light->r = r;	light->n = n;	light->c = c; 	return light;} Hitpipe *mklightpipe(int id, Point3 p, double r, Point3 n, Colour c){	Obj *light; 	light = newlight(p, r, n, c);	return mkobjpipe(id, light);} Hitlighthit(Obj *light, Point3 e, Point3 d){	double denom, intersect;	Point3 dist;	Hit hit; 	denom = dot3(d, light->n);	if(denom == 0)		goto nohit; 	dist = sub3(light->p, e);	intersect = dot3(dist, light->n)/denom; 	if(intersect <= 0)		goto nohit; 	hit.d = intersect;	hit.p = add3(e, mul3(d, intersect));	hit.n = light->n;	hit .ie = e;	hit.id = mul3(d, hit.d);	hit.o = light;	hit.c = light->c; 	if(dist3(hit.p, light->p) > light->r)		goto nohit; 	return hit;nohit:	hit.d = 0;	return hit;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t