hi

im pretty sure i have it indented when i try to post to my own email. kinda 
weird probably its unindented by the yahoogrooups.. program... backend? :D
here is my second try, if its still not indented i guess its not worth to read 
then :D 
sorry for the mess, thanks in advance


regards
================================= 
http://www.svnstrk.blogspot.com




________________________________
From: Jos Timanta Tarigan <[email protected]>
To: [email protected]
Sent: Thu, March 4, 2010 7:45:09 PM
Subject: Re: [c-prog] Re: question about c++ memory allocation




Vec3 calculateLightShade(int objectIndex, int lightIndex, Ray ray, double 
distance) {
Vec3 color(0, 0, 0);
Vec3 intPoint = ray.getOrigin() + (ray.getDirection() * distance);
Vec3 pointToLight;
Vec3 lightPoint;
double totalShade = 0;
double shade = 1.0/(sample*1.0);
bool intersected = false;
Ray rayToLight;
float dot = 0;
int intersectIndex = -1;
double intersectDistance = 0;
for (int i = 0; i<sample; i++) {
lightPoint = tris[lightIndex].generateRandomPoint();
rayToLight.setOrigin(lightPoint);
rayToLight.setDirection(intPoint-lightPoint);
rayToLight.getDirection().normalize();
intersectIndex = intersect(rayToLight, intersectDistance);
if (intersectIndex == objectIndex) {
shade = 1.0/(sample*1.0f);
} else shade = 0.0f;
pointToLight = lightPoint - intPoint;
pointToLight.normalize();
Vec3 n = tris[objectIndex].normal;
n.normalize();
dot = pointToLight.dot(n);
if (tris[objectIndex].material.diffuse > 0) {
if (dot > 0) {
float diff = dot * tris[objectIndex].material.diffuse;
color = color + (tris[objectIndex].material.color * diff) * shade;
}
}
// specular
if (tris[objectIndex].material.specular > 0) {
Vec3 v = ray.getDirection();
v.normalize();
Vec3 r = pointToLight - tris[objectIndex].normal * (dot * 2.0f);
float dotProdSpec = v.dot(r);
if (dotProdSpec > 0) {
float spec = powf(dotProdSpec, 20) * tris[objectIndex].material.specular;
color = color + tris[lightIndex].material.color * spec * shade;
}
}
}
return color;
}

Vec3 radiance(Ray ray, int depth) {
Vec3 color(0.0, 0.0, 0.0);
Vec3 intPoint(0.0, 0.0, 0.0);
double distance = 0;
int index = intersect(ray, distance);
if (index == -1) {
return color;
}
intPoint = ray.getOrigin() + (ray.getDirection() * distance);
if (tris[index].material.emmision > 0) {
return tris[index].material.color;
}
for (int i = 0; i < nObject; i++) {
if (tris[i].material.emmision > 0) {
color = calculateLightShade(index, i, ray, distance);
}
}
if (tris[index].material.reflection > 0 && depth < maxDepth) {
if (tris[index].material.diff_refl > 0) {
float diff_refl = tris[index].material.diff_refl;
Ray reflRay = tris[index].getReflectionRay(ray, intPoint);
Vec3 reflDir = reflRay.getDirection();
Vec3 rn1 = Vec3(reflDir.z, reflDir.y, -1*reflDir.x);
Vec3 rn2 = reflDir.cross(rn1);
for (int i = 0; i < sample; i++) {
float xoffs, yoffs;
do {
xoffs = drand48() * diff_refl;
yoffs = drand48() * diff_refl;
} while ( (xoffs*xoffs + yoffs*yoffs) > (diff_refl * diff_refl) );
rn1 = rn1*xoffs;
rn2 = rn2*yoffs*diff_refl;
Vec3 r = reflDir + rn1 + rn2;
r.normalize();
Ray drRay;
drRay.setOrigin(intPoint);
drRay.setDirection(r);
Vec3 res = radiance(drRay, depth+1);
color = color + tris[index].material.color.mult(res * diff_refl);
}
}
else if (depth < 2) {
Ray reflRay = tris[index].getReflectionRay(ray, intPoint);
Vec3 reflColor = radiance(reflRay, depth+1);
color = color + (reflColor * 
tris[index].material.reflection).mult(tris[index].material.color);
}
}
return color;
}

 ================================= 
http://www.svnstrk.blogspot.com




________________________________
From: John <[email protected]>
To: [email protected]
Sent: Thu, March 4, 2010 6:16:23 PM
Subject: [c-prog] Re: question about c++ memory allocation

  
--- In c-p...@yahoogroups. com, Jos Timanta Tarigan <jos_t_tarigan@ ...> wrote:
>
> below i attached sniplet of my code.

It's quite difficult to read without indentation - did that get lost in the 
post?


 



      

[Non-text portions of this message have been removed]

Reply via email to