-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaterial.c
129 lines (109 loc) · 2.83 KB
/
material.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* @file material.c Material*: manutenção de materiais.
*
* @author
* - Maira Noronha
* - Thiago Bastos
* - Mauricio Carneiro
*
* @date
* Criado em: 1 de Dezembro de 2002
* Última Modificação: 4 de Junho de 2003
*
* @version 2.0
*/
#include "material.h"
#include <string.h>
#include <stdlib.h>
/**
* Material* com o qual é feito um objeto.
*/
struct _Material
{
/**
* Textura do material.
*/
Image *texture;
/**
* Cor base do material (difusa).
*/
Color diffuseColor;
/**
* Cor do brilho especular do material.
*/
Color specularColor;
/**
* Coeficiente que define o brilho especular.
*/
double specularExponent;
/**
* Fator de refletividade do material.
*/
double reflectionFactor;
/**
* Índice de refração do material.
*/
double refractionFactor;
/**
* Opacidade do material.
*/
double opacityFactor;
};
/************************************************************************/
/* Definição das Funções Exportadas */
/************************************************************************/
Material* matCreate( Image *texture, Color diffuseColor,
Color specularColor, double specularExponent,
double reflectionFactor, double refractionFactor, double opacityFactor )
{
Material* material = (struct _Material *)malloc( sizeof(struct _Material) );
material->texture = texture;
material->diffuseColor = diffuseColor;
material->specularColor = specularColor;
material->specularExponent = specularExponent;
material->reflectionFactor = reflectionFactor;
material->refractionFactor = refractionFactor;
material->opacityFactor = opacityFactor;
return material;
}
Color matGetDiffuse( Material* material, Vector textureCoordinate )
{
int x;
int y;
int width;
int height;
if( material->texture == NULL )
{
return material->diffuseColor;
}
width = imgGetWidth(material->texture);
height = imgGetHeight(material->texture);
//imageGetDimensions( material->texture, &width, &height );
x = ( (int)( textureCoordinate.x * ( width - 1 ) ) % width );
y = ( (int)( textureCoordinate.y * ( height - 1 ) ) % height );
return imageGetPixel( material->texture, x, y );
}
Color matGetSpecular( Material* material )
{
return material->specularColor;
}
double matGetSpecularExponent( Material* material )
{
return material->specularExponent;
}
double matGetReflectionFactor( Material* material )
{
return material->reflectionFactor;
}
double matGetRefractionIndex( Material* material )
{
return material->refractionFactor;
}
double matGetOpacity( Material* material )
{
return material->opacityFactor;
}
void matDestroy( Material* material )
{
free( material );
}