احمد - 1 year ago 73
C Question

# mapping intensity from dot product to float RGB 0->1

I'm getting the dot product of the surface normal and light position. The weird thing is the dot product is larger than 1. That's problem number 1.

The second problem is I want to map that intensity from 0->1 to Float RGB from 0->1
here is my code

``````    if (the_object->polys[curr_poly].shading == 1)
{

// compute the dot product between the light source vector
// and normal vector to surface

dp = Dot_Product_3D((vector_3d_ptr)&normal,
(vector_3d_ptr)&light_source);

// test if light ray is reflecting off surface

if (dp > 0)
{
// now cos 0 = (u.v)/|u||v| or

intensity = ambient_light + ( dp / (the_object->polys[curr_poly].normal_length));

float r = the_object->polys[curr_poly].color.R*intensity;
float g = the_object->polys[curr_poly].color.G*intensity;
float b = the_object->polys[curr_poly].color.B*intensity;
Color color = Color(r, g, b, 1);
}
``````

I assume you understand what scalar products are, in any case they are `|a|*|b|*cos Θ`. they could certainly be over or under 1 since cos Θ is at most 1, multiplying the vectors, unless they are unit vectors may certainly lead to various numbers.
`(color / 255) * intensity`