| 1 |
/* |
| 2 |
*============================================================================= |
| 3 |
* color.c - routines to generate colors for AC3D file output |
| 4 |
* |
| 5 |
* Copyright (C) 2010 Ronald Jensen |
| 6 |
* ron(at)jentronics.com |
| 7 |
* http://www.jentronics.com |
| 8 |
* |
| 9 |
* This program is free software; you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation; either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program; if not, write to the Free Software |
| 21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 |
*============================================================================= |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <stdio.h> |
| 26 |
#include <math.h> |
| 27 |
|
| 28 |
#include "modeler.h" |
| 29 |
#include "modeler_proto.h" |
| 30 |
|
| 31 |
#ifdef STANDALONE |
| 32 |
#include <stdlib.h> |
| 33 |
|
| 34 |
int verbose = 3; |
| 35 |
|
| 36 |
int main(int argc, char *argv[]) |
| 37 |
{ |
| 38 |
int i; |
| 39 |
double r=1.0, g=0.5, b=.25, sr, sg, sb; |
| 40 |
|
| 41 |
for(i=0;i<145;i+=16) |
| 42 |
{ |
| 43 |
GetSpecular(r,g,b,i,&sr,&sg,&sb); |
| 44 |
fprintf(stdout,"rgb %0.3f %0.3f %0.3f spec %0.3f %0.3f %0.3f shi %d\n", r, g, b, sr, sg, sb, i); |
| 45 |
} |
| 46 |
return(EXIT_SUCCESS); |
| 47 |
} |
| 48 |
|
| 49 |
#else |
| 50 |
extern int verbose; |
| 51 |
#endif /* STANDALONE */ |
| 52 |
|
| 53 |
|
| 54 |
int GetShine(double roughness) |
| 55 |
{ |
| 56 |
/* |
| 57 |
Aerodynamically Smooth 0 |
| 58 |
Polished Metal 2.00E-005 |
| 59 |
Polished Wood 8.00E-005 |
| 60 |
Natural Sheet Metal 1.60E-004 |
| 61 |
Smooth Matte Paint 2.50E-004 |
| 62 |
Standard Camo Paint 4.00E-004 |
| 63 |
Cheap Camo Paint 1.20E-003 |
| 64 |
Galvanized Metal 6.00E-003 |
| 65 |
Cast Iron 1.00E-002 |
| 66 |
*/ |
| 67 |
/* 0 is dull, 128 is shiny */ |
| 68 |
|
| 69 |
/* I take the nth root of the rougness value times a factor and subtract that from 128. */ |
| 70 |
#define COLOR_ROOT 0.17 // Root and factor chosen to give 128 at 0 roughness |
| 71 |
#define COLOR_FACTOR 280.0 // 65 at default, and 0 at max roughness |
| 72 |
#define DEFAULT_ROUGHNESS 0.00016 //inches, from DATCOM manual |
| 73 |
|
| 74 |
double t; |
| 75 |
if(roughness < 0.) { |
| 76 |
if (verbose > 1) fprintf(stderr,"color: Default Roughness\n"); |
| 77 |
roughness = DEFAULT_ROUGHNESS; |
| 78 |
} |
| 79 |
if(roughness > 1.00e-2) roughness = 1.00e-2; |
| 80 |
t = pow(roughness, COLOR_ROOT); |
| 81 |
t *= COLOR_FACTOR; // 128/(Cast Iron)^0.2 |
| 82 |
t = 128.-t; |
| 83 |
return((int)t); |
| 84 |
} |
| 85 |
|
| 86 |
#define HARD 80 |
| 87 |
int GetSpecular(double ired, double igrn, double iblu, int shiny, double *ored, double *ogrn, double *oblu) |
| 88 |
{ |
| 89 |
double factor; |
| 90 |
|
| 91 |
if (shiny > 128) shiny = 128; |
| 92 |
|
| 93 |
/* if (shiny <= HARD) |
| 94 |
{ |
| 95 |
factor=(double)shiny/HARD; |
| 96 |
*ored = ired*factor; |
| 97 |
*ogrn = igrn*factor; |
| 98 |
*oblu = iblu*factor; |
| 99 |
} else { |
| 100 |
factor=(double)(128-shiny)/HARD; |
| 101 |
*ored = ired*factor - factor + 1; |
| 102 |
*ogrn = igrn*factor - factor + 1;; |
| 103 |
*oblu = iblu*factor - factor + 1;; |
| 104 |
} |
| 105 |
*/ |
| 106 |
|
| 107 |
factor = (double)shiny/128.; |
| 108 |
*ored = factor; |
| 109 |
*ogrn = factor; |
| 110 |
*oblu = factor; |
| 111 |
return(1); |
| 112 |
} |