Acceleration of Box's Normal




Old code:
 static void Box_Normal(VECTOR Result, OBJECT *Object, INTERSECTION *Inter)
{ switch (Inter->i1) { case SIDE_X_0: Make_Vector(Result, -1.0, 0.0, 0.0); break; case SIDE_X_1: Make_Vector(Result, 1.0, 0.0, 0.0); break; case SIDE_Y_0: Make_Vector(Result, 0.0, -1.0, 0.0); break; case SIDE_Y_1: Make_Vector(Result, 0.0, 1.0, 0.0); break; case SIDE_Z_0: Make_Vector(Result, 0.0, 0.0, -1.0); break; case SIDE_Z_1: Make_Vector(Result, 0.0, 0.0, 1.0); break; default: Error("Unknown box side in Box_Normal().\n"); } /* Transform the point into the boxes space. */ if (((BOX *)Object)->Trans != NULL) { MTransNormal(Result, Result, ((BOX *)Object)->Trans); VNormalize(Result, Result); } } New code: static void Box_Normal(VECTOR Result, OBJECT *Object, INTERSECTION *Inter) { if (((BOX *)Object)->Trans == NULL ) switch (Inter->i1) { case SIDE_X_0: Make_Vector(Result, -1.0, 0.0, 0.0); break; case SIDE_X_1: Make_Vector(Result, 1.0, 0.0, 0.0); break; case SIDE_Y_0: Make_Vector(Result, 0.0, -1.0, 0.0); break; case SIDE_Y_1: Make_Vector(Result, 0.0, 1.0, 0.0); break; case SIDE_Z_0: Make_Vector(Result, 0.0, 0.0, -1.0); break; case SIDE_Z_1: Make_Vector(Result, 0.0, 0.0, 1.0); break; default: Error("Unknown box side in Box_Normal().\n"); } else switch (Inter->i1) { case SIDE_X_0: Assign_Vector(Result, ((BOX *)Object)->N_X_0); break; case SIDE_X_1: Assign_Vector(Result, ((BOX *)Object)->N_X_1); break; case SIDE_Y_0: Assign_Vector(Result, ((BOX *)Object)->N_Y_0); break; case SIDE_Y_1: Assign_Vector(Result, ((BOX *)Object)->N_Y_1); break; case SIDE_Z_0: Assign_Vector(Result, ((BOX *)Object)->N_Z_0); break; case SIDE_Z_1: Assign_Vector(Result, ((BOX *)Object)->N_Z_1); break; default: Error("Unknown box side in Box_Normal().\n"); } }




Patched files:
    boxes.h : one line
    boxes.c : several things


Source & Tests 3.1 ( 14 479b )