1 /*
2 * infinite.c
3 *
4 * Copyright (C) 1989, 1991, Craig E. Kolb
5 * All rights reserved.
6 *
7 * This software may be freely copied, modified, and redistributed
8 * provided that this copyright notice is preserved on all copies.
9 *
10 * You may not distribute this software, in whole or in part, as part of
11 * any commercial product without the express consent of the authors.
12 *
13 * There is no warranty or other guarantee of fitness of this software
14 * for any purpose. It is provided solely "as is".
15 *
16 * $Id: infinite.c,v 4.0 91/07/17 14:34:28 kolb Exp Locker: kolb $
17 *
18 * $Log: infinite.c,v $
19 * Revision 4.0 91/07/17 14:34:28 kolb
20 * Initial version.
21 *
22 */
23 #include "light.h"
24 #include "infinite.h"
25
26 static LightMethods *iInfMethods = NULL;
27
28 Infinite *
InfiniteCreate(dir)29 InfiniteCreate(dir)
30 Vector *dir;
31 {
32 Infinite *inf;
33
34 inf = (Infinite *)share_malloc(sizeof(Infinite));
35 inf->dir = *dir;
36 if (VecNormalize(&inf->dir) == 0.) {
37 RLerror(RL_ABORT, "Invalid directional light.\n");
38 return (Infinite *)NULL;
39 }
40 return inf;
41 }
42
43 LightMethods *
InfiniteMethods()44 InfiniteMethods()
45 {
46 if (iInfMethods == (LightMethods *)NULL) {
47 iInfMethods = LightMethodsCreate();
48 iInfMethods->intens = InfiniteIntens;
49 iInfMethods->dir = InfiniteDirection;
50 }
51 return iInfMethods;
52 }
53
54 int
InfiniteIntens(inf,lcolor,cache,ray,dist,noshadow,color)55 InfiniteIntens(inf, lcolor, cache, ray, dist, noshadow, color)
56 Infinite *inf;
57 Color *lcolor, *color;
58 ShadowCache *cache;
59 Ray *ray;
60 Float dist;
61 int noshadow;
62 {
63 return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
64 }
65
66 void
InfiniteDirection(lp,pos,dir,dist)67 InfiniteDirection(lp, pos, dir, dist)
68 Infinite *lp;
69 Vector *pos, *dir;
70 Float *dist;
71 {
72 *dir = lp->dir;
73 *dist = FAR_AWAY;
74 }
75
InfiniteMethodRegister(meth)76 InfiniteMethodRegister(meth)
77 UserMethodType meth;
78 {
79 if (iInfMethods)
80 iInfMethods->user = meth;
81 }
82