void MMLmsqrt::doPaint(MML::Attributes *a) const { MMLNode *sqrt = first; v_unit linethickness(0.05, l_unit::em); float lineth = linethickness.get(a); sqrt->paint(a); float ly = -sqrt->getAscent() - 3.5*lineth; float d = (gui->ascent + gui->descent)/12; float bx = sqrt->getX(); v_unit ex = v_unit(-0.5, v_unit::ex); float hex = ex.get(a); float x[10], y[10]; float px[5], py[5]; float t[4]; px[0] = 0; py[0] = 0.7*hex; px[1] = d; py[1] = hex; px[2] = 3*d; py[2] = gui->descent/2; px[3] = bx; py[3] = ly; px[4] = gui->width; py[4] = ly; t[0] = lineth/2; t[1] = 2*lineth; t[2] = t[3] = lineth; rootPoints(px, py, t, x, y); a->p->drawPolygon(10, x, y); }
/* Compute the reflection of a vector on an object. * * the_object: The object to reflect off of. * position: The position hit. * direction: The direction of the vector to be reflected. * * Returns: the reflection of direction on the object at position. */ float* reflection_vector(object *the_object, float *position, float *direction) { float *reflection = (float*)malloc(sizeof(float)*3); float *normal = get_normal(the_object, position); v_scale(normal, -2*v_dot(direction, normal), reflection); v_add(reflection, direction, reflection); v_unit(reflection, reflection); return reflection; }
/* Get the normal of a shape at a given position. * * the_object: The object to get the normal of. * position: The position on the object to calculate the normal. * * Returns: The normal to the object at the given position. */ float* get_normal(object *the_object, float *position) { float *normal; if (the_object->type == PLANE_TYPE) normal = the_object->definition.plane.normal; else { normal = (float*)malloc(sizeof(float)*3); v_sub(position, the_object->definition.sphere.center, normal); v_unit(normal, normal); } return normal; }