Advertisement
Advertisement
| 04.19.2008 at 09:18PM PDT, ID: 23337366 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
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: |
color spawnRay(ray, depth) {
// Code to determine if ray hit an object
// ...
// If ray didn't intersect anything, just return background color
if (!intersection) {
return background_color;
// There has been an intersection
} else {
// MAX_DEPTH sets a limit to the recursion depth (10 is fine)
if (depth < MAX_DEPTH) {
//Spawn reflection ray if intersected object hit is reflective
if (kr > 0) {
retcolor += spawnRay(reflect_ray, depth+1);
}
//Spawn transmission ray if intersected object is transparent
if (kt > 0) {
retcolor += spawnRay(trans_ray, depth+1);
}
}
}
return retcolor;
}
|
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 04.19.2008 at 10:38PM PDT, ID: 21395127 |
| 04.19.2008 at 10:53PM PDT, ID: 21395147 |
| 04.20.2008 at 01:59AM PDT, ID: 21395397 |
| 04.20.2008 at 02:08AM PDT, ID: 21395417 |
| 04.20.2008 at 06:59AM PDT, ID: 21396015 |
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: |
/*
Unrolled recursive function.
At each level in the tree we must evaluate the reflection ray and the transmission ray.
When the intersection is calculated, both tRay and rRay are calculated along with kr and kt.
To ensure that intersection is called minimally we must therefore have at least 4 stacks.
The tRay, the rRay, kt and kr.
We also need a state that tells us which ray we have processed (ray, t or r). This must also be stacked so
that makes 5 stacks.
*/
// Two stages at each level.
Ray tStack[MAX];
Ray rStack[MAX];
int ktStack[MAX];
int krStack[MAX];
// Next ray to process at this level (tRay or rRay).
#define STATE_T_RAY (0)
#define STATE_R_RAY (1)
#define STATE_COMPLETE (2)
int trStack[MAX];
int d; // Depth.
color traceRay(ray) {
// Start at depth 0.
d = 0;
// Keep walking the tree until we get back to depth 0.
do {
// Trace the ray.
if ( intersection(ray) ) {
// Keep the results of the intersection call at the current level.
tStack[d] = trans_ray;
ktStack[d] = kt;
rStack[d] = reflect_ray;
krStack[d] = kr;
// Next state at this level is to check the t ray.
trStack[d] = STATE_T_RAY;
} else {
// No intersection, add background colour
retcolor += background_color;
// and were done at this level.
d -= 1;
}
// Which ray should we work on for the next iteration?
// Initially nothing.
ray = null;
// Walk the stack till we're done or we know which ray to do next.
while ( ray == null && d >= 0 ) {
// Check the state.
switch ( trStack[d] ) {
case STATE_T_RAY:
// Was there one?
if ( d < MAX && ktStack[d] > 0 ) {
// Do the transmission ray.
ray = tStack[d];
// Step my state.
trStack[d] += 1;
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
case STATE_R_RAY:
// Was there one?
if ( d < MAX && krStack[d] > 0 ) {
// Do the reflection ray.
ray = rStack[d];
// Step my state.
trStack[d] += 1;
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
default:
// Complete at this level, step out.
d -= 1;
break;
}
}
} while( d >= 0 );
return retcolor;
}
|
| 04.20.2008 at 07:40AM PDT, ID: 21396142 |
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: |
/*
Unrolled recursive function.
At each level in the tree we must evaluate the reflection ray and the transmission ray.
When the intersection is calculated, both tRay and rRay are calculated along with kr and kt.
To ensure that intersection is called minimally we must therefore have at least 4 stacks.
The tRay, the rRay, kt and kr.
We also need a state that tells us which ray we have processed (ray, t or r). This must also be stacked so
that makes 5 stacks.
*/
// Two stages at each level.
Ray tStack[MAX];
Ray rStack[MAX];
int ktStack[MAX];
int krStack[MAX];
// Next ray to process at this level (tRay or rRay).
#define STATE_T_RAY (0)
#define STATE_R_RAY (1)
#define STATE_COMPLETE (2)
int trStack[MAX];
int d; // Depth.
color traceRay(ray) {
// Start at depth 0.
d = 0;
// Keep walking the tree until we get back to depth 0.
do {
// Trace the ray.
if ( intersection(ray) ) {
// Keep the results of the intersection call at the current level.
tStack[d] = trans_ray;
ktStack[d] = kt;
rStack[d] = reflect_ray;
krStack[d] = kr;
// Next state at this level is to check the t ray.
trStack[d] = STATE_T_RAY;
} else {
// No intersection, add background colour
retcolor += background_color;
// and were done at this level.
d -= 1;
}
// Which ray should we work on for the next iteration?
// Initially nothing.
ray = null;
// Walk the stack till we're done or we know which ray to do next.
while ( ray == null && d >= 0 ) {
// Check the state.
switch ( trStack[d] ) {
case STATE_T_RAY:
// Step my state.
trStack[d] += 1;
// Was there one?
if ( ktStack[d] > 0 && d < MAX ) {
// Do the transmission ray.
ray = tStack[d];
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
case STATE_R_RAY:
// Step my state.
trStack[d] += 1;
// Was there one?
if ( krStack[d] > 0 && d < MAX ) {
// Do the reflection ray.
ray = rStack[d];
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
default:
// Complete at this level, step out.
d -= 1;
break;
}
}
} while( d >= 0 );
return retcolor;
}
|
| 04.20.2008 at 07:51AM PDT, ID: 21396207 |
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: |
/*
Unrolled recursive function.
At each level in the tree we must evaluate the reflection ray and the transmission ray.
When the intersection is calculated, both tRay and rRay are calculated along with kr and kt.
To ensure that intersection is called minimally we must therefore have at least 4 stacks.
The tRay, the rRay, kt and kr.
We also need a state that tells us which ray we have processed (ray, t or r). This must also be stacked so
that makes 5 stacks.
*/
// Two stages at each level.
Ray tStack[MAX];
Ray rStack[MAX];
int ktStack[MAX];
int krStack[MAX];
// Next ray to process at this level (tRay or rRay).
#define STATE_T_RAY (0)
#define STATE_R_RAY (1)
#define STATE_COMPLETE (2)
int trStack[MAX];
int d; // Depth.
color traceRay(ray) {
// Start at depth 0.
d = 0;
// Keep walking the tree until we get back to depth 0.
do {
// Trace the ray.
if ( intersection(ray) ) {
// Keep the results of the intersection call at the current level.
tStack[d] = trans_ray;
ktStack[d] = kt;
rStack[d] = reflect_ray;
krStack[d] = kr;
// Next state at this level is to check the t ray.
trStack[d] = STATE_T_RAY;
} else {
// No intersection, add background colour
retcolor += background_color;
// and were done at this level.
d -= 1;
}
// Which ray should we work on for the next iteration?
// Initially nothing.
ray = null;
// Walk the stack till we're done or we know which ray to do next.
while ( ray == null && d >= 0 ) {
// Check and step the state.
switch ( trStack[d]++ ) {
case STATE_T_RAY:
// Was there one?
if ( ktStack[d] > 0 && d < MAX ) {
// Do the transmission ray.
ray = tStack[d];
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
case STATE_R_RAY:
// Was there one?
if ( krStack[d] > 0 && d < MAX ) {
// Do the reflection ray.
ray = rStack[d];
// Step up.
trStack[++d] = STATE_T_RAY;
}
break;
default:
// Complete at this level, step out.
d -= 1;
break;
}
}
} while( d >= 0 );
return retcolor;
}
|
| 04.21.2008 at 10:48AM PDT, ID: 21404256 |
| 04.21.2008 at 11:31AM PDT, ID: 21404632 |
| 04.23.2008 at 08:29AM PDT, ID: 21421773 |