void batching_add_laser_internal(primitive_batch *batch, vec3d *p0, float width1, vec3d *p1, float width2, int r, int g, int b) { Assert(batch->get_render_info().prim_type == PRIM_TYPE_TRIS); width1 *= 0.5f; width2 *= 0.5f; vec3d uvec, fvec, rvec, center, reye; vm_vec_sub( &fvec, p0, p1 ); vm_vec_normalize_safe( &fvec ); vm_vec_avg( ¢er, p0, p1 ); // needed for the return value only vm_vec_sub(&reye, &Eye_position, ¢er); vm_vec_normalize(&reye); // compute the up vector vm_vec_cross(&uvec, &fvec, &reye); vm_vec_normalize_safe(&uvec); // ... the forward vector vm_vec_cross(&fvec, &uvec, &reye); vm_vec_normalize_safe(&fvec); // now recompute right vector, in case it wasn't entirely perpendiclar vm_vec_cross(&rvec, &uvec, &fvec); // Now have uvec, which is up vector and rvec which is the normal // of the face. vec3d start, end; vm_vec_scale_add(&start, p0, &fvec, -width1); vm_vec_scale_add(&end, p1, &fvec, width2); vec3d vecs[4]; batch_vertex verts[6]; vm_vec_scale_add( &vecs[0], &end, &uvec, width2 ); vm_vec_scale_add( &vecs[1], &start, &uvec, width1 ); vm_vec_scale_add( &vecs[2], &start, &uvec, -width1 ); vm_vec_scale_add( &vecs[3], &end, &uvec, -width2 ); verts[0].position = vecs[0]; verts[1].position = vecs[1]; verts[2].position = vecs[2]; verts[3].position = vecs[0]; verts[4].position = vecs[2]; verts[5].position = vecs[3]; verts[0].tex_coord.u = 1.0f; verts[0].tex_coord.v = 0.0f; verts[1].tex_coord.u = 0.0f; verts[1].tex_coord.v = 0.0f; verts[2].tex_coord.u = 0.0f; verts[2].tex_coord.v = 1.0f; verts[3].tex_coord.u = 1.0f; verts[3].tex_coord.v = 0.0f; verts[4].tex_coord.u = 0.0f; verts[4].tex_coord.v = 1.0f; verts[5].tex_coord.u = 1.0f; verts[5].tex_coord.v = 1.0f; verts[0].r = (ubyte)r; verts[0].g = (ubyte)g; verts[0].b = (ubyte)b; verts[0].a = 255; verts[1].r = (ubyte)r; verts[1].g = (ubyte)g; verts[1].b = (ubyte)b; verts[1].a = 255; verts[2].r = (ubyte)r; verts[2].g = (ubyte)g; verts[2].b = (ubyte)b; verts[2].a = 255; verts[3].r = (ubyte)r; verts[3].g = (ubyte)g; verts[3].b = (ubyte)b; verts[3].a = 255; verts[4].r = (ubyte)r; verts[4].g = (ubyte)g; verts[4].b = (ubyte)b; verts[4].a = 255; verts[5].r = (ubyte)r; verts[5].g = (ubyte)g; verts[5].b = (ubyte)b; verts[5].a = 255; batch->add_triangle(&verts[0], &verts[1], &verts[2]); batch->add_triangle(&verts[3], &verts[4], &verts[5]); }
void batching_add_bitmap_rotated_internal(primitive_batch *batch, vertex *pnt, float angle, float rad, color *clr, float depth) { Assert(batch->get_render_info().prim_type == PRIM_TYPE_TRIS); float radius = rad; rad *= 1.41421356f;//1/0.707, becase these are the points of a square or width and height rad extern float Physics_viewer_bank; angle -= Physics_viewer_bank; if ( angle < 0.0f ) angle += PI2; else if ( angle > PI2 ) angle -= PI2; vec3d PNT(pnt->world); vec3d p[4]; vec3d fvec, rvec, uvec; batch_vertex verts[6]; vm_vec_sub(&fvec, &View_position, &PNT); vm_vec_normalize_safe(&fvec); vm_rot_point_around_line(&uvec, &View_matrix.vec.uvec, angle, &vmd_zero_vector, &View_matrix.vec.fvec); vm_vec_cross(&rvec, &View_matrix.vec.fvec, &uvec); vm_vec_normalize_safe(&rvec); vm_vec_cross(&uvec, &View_matrix.vec.fvec, &rvec); vm_vec_scale_add(&PNT, &PNT, &fvec, depth); vm_vec_scale_add(&p[0], &PNT, &rvec, rad); vm_vec_scale_add(&p[2], &PNT, &rvec, -rad); vm_vec_scale_add(&p[1], &p[2], &uvec, rad); vm_vec_scale_add(&p[3], &p[0], &uvec, -rad); vm_vec_scale_add(&p[0], &p[0], &uvec, rad); vm_vec_scale_add(&p[2], &p[2], &uvec, -rad); //move all the data from the vecs into the verts //tri 1 verts[5].position = p[3]; verts[4].position = p[2]; verts[3].position = p[1]; //tri 2 verts[2].position = p[3]; verts[1].position = p[1]; verts[0].position = p[0]; //tri 1 verts[5].tex_coord.u = 0.0f; verts[5].tex_coord.v = 0.0f; verts[4].tex_coord.u = 1.0f; verts[4].tex_coord.v = 0.0f; verts[3].tex_coord.u = 1.0f; verts[3].tex_coord.v = 1.0f; //tri 2 verts[2].tex_coord.u = 0.0f; verts[2].tex_coord.v = 0.0f; verts[1].tex_coord.u = 1.0f; verts[1].tex_coord.v = 1.0f; verts[0].tex_coord.u = 0.0f; verts[0].tex_coord.v = 1.0f; for (int i = 0; i < 6 ; i++) { verts[i].r = clr->red; verts[i].g = clr->green; verts[i].b = clr->blue; verts[i].a = clr->alpha; verts[i].radius = radius; } batch->add_triangle(&verts[0], &verts[1], &verts[2]); batch->add_triangle(&verts[3], &verts[4], &verts[5]); }
void batching_add_beam_internal(primitive_batch *batch, vec3d *start, vec3d *end, float width, color *clr, float offset) { Assert(batch->get_render_info().prim_type == PRIM_TYPE_TRIS); vec3d p[4]; batch_vertex verts[6]; vec3d fvec, uvecs, uvece, evec; vm_vec_sub(&fvec, start, end); vm_vec_normalize_safe(&fvec); vm_vec_sub(&evec, &View_position, start); vm_vec_normalize_safe(&evec); vm_vec_cross(&uvecs, &fvec, &evec); vm_vec_normalize_safe(&uvecs); vm_vec_sub(&evec, &View_position, end); vm_vec_normalize_safe(&evec); vm_vec_cross(&uvece, &fvec, &evec); vm_vec_normalize_safe(&uvece); vm_vec_scale_add(&p[0], start, &uvecs, width); vm_vec_scale_add(&p[1], end, &uvece, width); vm_vec_scale_add(&p[2], end, &uvece, -width); vm_vec_scale_add(&p[3], start, &uvecs, -width); //move all the data from the vecs into the verts //tri 1 verts[0].position = p[3]; verts[1].position = p[2]; verts[2].position = p[1]; //tri 2 verts[3].position = p[3]; verts[4].position = p[1]; verts[5].position = p[0]; //set up the UV coords //tri 1 verts[0].tex_coord.u = 0.0f; verts[0].tex_coord.v = 0.0f; verts[1].tex_coord.u = 1.0f; verts[1].tex_coord.v = 0.0f; verts[2].tex_coord.u = 1.0f; verts[2].tex_coord.v = 1.0f; //tri 2 verts[3].tex_coord.u = 0.0f; verts[3].tex_coord.v = 0.0f; verts[4].tex_coord.u = 1.0f; verts[4].tex_coord.v = 1.0f; verts[5].tex_coord.u = 0.0f; verts[5].tex_coord.v = 1.0f; for(int i = 0; i < 6; i++) { verts[i].r = clr->red; verts[i].g = clr->green; verts[i].b = clr->blue; verts[i].a = clr->alpha; if(offset > 0.0f) { verts[i].radius = offset; } else { verts[i].radius = width; } } batch->add_triangle(&verts[0], &verts[1], &verts[2]); batch->add_triangle(&verts[3], &verts[4], &verts[5]); }
// Create a grid // *forward is vector pointing forward // *right is vector pointing right // *center is center point of grid // length is length of grid // width is width of grid // square_size is size of a grid square // For example: // *forward = (0.0, 0.0, 1.0) // *right = (1.0, 0.0, 0.0) // *center = (0.0, 0.0, 0.0) // nrows = 10 // ncols = 50.0 // square_size = 10.0 // will generate a grid of squares 10 long by 5 wide. // Each grid square will be 10.0 x 10.0 units. // The center of the grid will be at the global origin. // The grid will be parallel to the xz plane (because the normal is 0,1,0). // (In fact, it will be the xz plane because it is centered on the origin.) // // Stuffs grid in *gridp. If gridp == NULL, mallocs and returns a grid. grid *create_grid(grid *gridp, vector *forward, vector *right, vector *center, int nrows, int ncols, float square_size) { int i, ncols2, nrows2, d = 1; vector dfvec, drvec, cur, cur2, tvec, uvec, save, save2; Assert(square_size > 0.0); if (double_fine_gridlines) d = 2; if (gridp == NULL) gridp = (grid *) malloc(sizeof(grid)); Assert(gridp); gridp->center = *center; gridp->square_size = square_size; // Create the plane equation. Assert(!IS_VEC_NULL(forward)); Assert(!IS_VEC_NULL(right)); vm_vec_copy_normalize(&dfvec, forward); vm_vec_copy_normalize(&drvec, right); vm_vec_cross(&uvec, &dfvec, &drvec); Assert(!IS_VEC_NULL(&uvec)); gridp->gmatrix.v.uvec = uvec; gridp->planeD = -(center->xyz.x * uvec.xyz.x + center->xyz.y * uvec.xyz.y + center->xyz.z * uvec.xyz.z); Assert(!_isnan(gridp->planeD)); gridp->gmatrix.v.fvec = dfvec; gridp->gmatrix.v.rvec = drvec; vm_vec_scale(&dfvec, square_size); vm_vec_scale(&drvec, square_size); vm_vec_scale_add(&cur, center, &dfvec, (float) -nrows * d / 2); vm_vec_scale_add2(&cur, &drvec, (float) -ncols * d / 2); vm_vec_scale_add(&cur2, center, &dfvec, (float) -nrows * 5 / 2); vm_vec_scale_add2(&cur2, &drvec, (float) -ncols * 5 / 2); save = cur; save2 = cur2; gridp->ncols = ncols; gridp->nrows = nrows; ncols2 = ncols / 2; nrows2 = nrows / 2; Assert(ncols < MAX_GRIDLINE_POINTS && nrows < MAX_GRIDLINE_POINTS); // Create the points along the edges of the grid, so we can just draw lines // between them to form the grid. for (i=0; i<=ncols*d; i++) { gridp->gpoints1[i] = cur; // small, dark gridline points vm_vec_scale_add(&tvec, &cur, &dfvec, (float) nrows * d); gridp->gpoints2[i] = tvec; vm_vec_add2(&cur, &drvec); } for (i=0; i<=ncols2; i++) { gridp->gpoints5[i] = cur2; // large, brighter gridline points vm_vec_scale_add(&tvec, &cur2, &dfvec, (float) nrows2 * 10); gridp->gpoints6[i] = tvec; vm_vec_scale_add2(&cur2, &drvec, 10.0f); } cur = save; cur2 = save2; for (i=0; i<=nrows*d; i++) { gridp->gpoints3[i] = cur; // small, dark gridline points vm_vec_scale_add(&tvec, &cur, &drvec, (float) ncols * d); gridp->gpoints4[i] = tvec; vm_vec_add2(&cur, &dfvec); } for (i=0; i<=nrows2; i++) { gridp->gpoints7[i] = cur2; // large, brighter gridline points vm_vec_scale_add(&tvec, &cur2, &drvec, (float) ncols2 * 10); gridp->gpoints8[i] = tvec; vm_vec_scale_add2(&cur2, &dfvec, 10.0f); } return gridp; }
void batching_add_bitmap_internal(primitive_batch *batch, vertex *pnt, int orient, float rad, color *clr, float depth) { Assert(batch->get_render_info().prim_type == PRIM_TYPE_TRIS); float radius = rad; rad *= 1.41421356f;//1/0.707, becase these are the points of a square or width and height rad vec3d PNT(pnt->world); vec3d p[4]; vec3d fvec, rvec, uvec; batch_vertex verts[6]; // get the direction from the point to the eye vm_vec_sub(&fvec, &View_position, &PNT); vm_vec_normalize_safe(&fvec); // get an up vector in the general direction of what we want uvec = View_matrix.vec.uvec; // make a right vector from the f and up vector, this r vec is exactly what we want, so... vm_vec_cross(&rvec, &View_matrix.vec.fvec, &uvec); vm_vec_normalize_safe(&rvec); // fix the u vec with it vm_vec_cross(&uvec, &View_matrix.vec.fvec, &rvec); // move the center of the sprite based on the depth parameter if ( depth != 0.0f ) vm_vec_scale_add(&PNT, &PNT, &fvec, depth); // move one of the verts to the left vm_vec_scale_add(&p[0], &PNT, &rvec, rad); // and one to the right vm_vec_scale_add(&p[2], &PNT, &rvec, -rad); // now move all oof the verts to were they need to be vm_vec_scale_add(&p[1], &p[2], &uvec, rad); vm_vec_scale_add(&p[3], &p[0], &uvec, -rad); vm_vec_scale_add(&p[0], &p[0], &uvec, rad); vm_vec_scale_add(&p[2], &p[2], &uvec, -rad); //move all the data from the vecs into the verts //tri 1 verts[5].position = p[3]; verts[4].position = p[2]; verts[3].position = p[1]; //tri 2 verts[2].position = p[3]; verts[1].position = p[1]; verts[0].position = p[0]; // set up the UV coords if ( orient & 1 ) { // tri 1 verts[5].tex_coord.u = 1.0f; verts[4].tex_coord.u = 0.0f; verts[3].tex_coord.u = 0.0f; // tri 2 verts[2].tex_coord.u = 1.0f; verts[1].tex_coord.u = 0.0f; verts[0].tex_coord.u = 1.0f; } else { // tri 1 verts[5].tex_coord.u = 0.0f; verts[4].tex_coord.u = 1.0f; verts[3].tex_coord.u = 1.0f; // tri 2 verts[2].tex_coord.u = 0.0f; verts[1].tex_coord.u = 1.0f; verts[0].tex_coord.u = 0.0f; } if ( orient & 2 ) { // tri 1 verts[5].tex_coord.v = 1.0f; verts[4].tex_coord.v = 1.0f; verts[3].tex_coord.v = 0.0f; // tri 2 verts[2].tex_coord.v = 1.0f; verts[1].tex_coord.v = 0.0f; verts[0].tex_coord.v = 0.0f; } else { // tri 1 verts[5].tex_coord.v = 0.0f; verts[4].tex_coord.v = 0.0f; verts[3].tex_coord.v = 1.0f; // tri 2 verts[2].tex_coord.v = 0.0f; verts[1].tex_coord.v = 1.0f; verts[0].tex_coord.v = 1.0f; } for (int i = 0; i < 6 ; i++) { verts[i].r = clr->red; verts[i].g = clr->green; verts[i].b = clr->blue; verts[i].a = clr->alpha; verts[i].radius = radius; } batch->add_triangle(&verts[5], &verts[4], &verts[3]); batch->add_triangle(&verts[2], &verts[1], &verts[0]); }
float geometry_batcher::draw_laser(vec3d *p0, float width1, vec3d *p1, float width2, int r, int g, int b) { width1 *= 0.5f; width2 *= 0.5f; vec3d uvec, fvec, rvec, center, reye; vm_vec_sub( &fvec, p0, p1 ); vm_vec_normalize_safe( &fvec ); vm_vec_avg( ¢er, p0, p1 ); // needed for the return value only vm_vec_sub(&reye, &Eye_position, ¢er); vm_vec_normalize(&reye); // compute the up vector vm_vec_cross(&uvec, &fvec, &reye); vm_vec_normalize_safe(&uvec); // ... the forward vector vm_vec_cross(&fvec, &uvec, &reye); vm_vec_normalize_safe(&fvec); // now recompute right vector, in case it wasn't entirely perpendiclar vm_vec_cross(&rvec, &uvec, &fvec); // Now have uvec, which is up vector and rvec which is the normal // of the face. vec3d start, end; vm_vec_scale_add(&start, p0, &fvec, -width1); vm_vec_scale_add(&end, p1, &fvec, width2); vec3d vecs[4]; vertex *pts = &vert[n_to_render * 3]; vm_vec_scale_add( &vecs[0], &end, &uvec, width2 ); vm_vec_scale_add( &vecs[1], &start, &uvec, width1 ); vm_vec_scale_add( &vecs[2], &start, &uvec, -width1 ); vm_vec_scale_add( &vecs[3], &end, &uvec, -width2 ); g3_transfer_vertex( &pts[0], &vecs[0] ); g3_transfer_vertex( &pts[1], &vecs[1] ); g3_transfer_vertex( &pts[2], &vecs[2] ); g3_transfer_vertex( &pts[3], &vecs[0] ); g3_transfer_vertex( &pts[4], &vecs[2] ); g3_transfer_vertex( &pts[5], &vecs[3] ); pts[0].texture_position.u = 1.0f; pts[0].texture_position.v = 0.0f; pts[1].texture_position.u = 0.0f; pts[1].texture_position.v = 0.0f; pts[2].texture_position.u = 0.0f; pts[2].texture_position.v = 1.0f; pts[3].texture_position.u = 1.0f; pts[3].texture_position.v = 0.0f; pts[4].texture_position.u = 0.0f; pts[4].texture_position.v = 1.0f; pts[5].texture_position.u = 1.0f; pts[5].texture_position.v = 1.0f; pts[0].r = (ubyte)r; pts[0].g = (ubyte)g; pts[0].b = (ubyte)b; pts[0].a = 255; pts[1].r = (ubyte)r; pts[1].g = (ubyte)g; pts[1].b = (ubyte)b; pts[1].a = 255; pts[2].r = (ubyte)r; pts[2].g = (ubyte)g; pts[2].b = (ubyte)b; pts[2].a = 255; pts[3].r = (ubyte)r; pts[3].g = (ubyte)g; pts[3].b = (ubyte)b; pts[3].a = 255; pts[4].r = (ubyte)r; pts[4].g = (ubyte)g; pts[4].b = (ubyte)b; pts[4].a = 255; pts[5].r = (ubyte)r; pts[5].g = (ubyte)g; pts[5].b = (ubyte)b; pts[5].a = 255; n_to_render += 2; use_radius = false; return center.xyz.z; }
void geometry_batcher::draw_beam(vec3d *start, vec3d *end, float width, float intensity, float offset) { vec3d p[4]; vertex *P = &vert[n_to_render * 3]; float *R = &radius_list[n_to_render * 3]; vec3d fvec, uvecs, uvece, evec; vm_vec_sub(&fvec, start, end); vm_vec_normalize_safe(&fvec); vm_vec_sub(&evec, &View_position, start); vm_vec_normalize_safe(&evec); vm_vec_cross(&uvecs, &fvec, &evec); vm_vec_normalize_safe(&uvecs); vm_vec_sub(&evec, &View_position, end); vm_vec_normalize_safe(&evec); vm_vec_cross(&uvece, &fvec, &evec); vm_vec_normalize_safe(&uvece); vm_vec_scale_add(&p[0], start, &uvecs, width); vm_vec_scale_add(&p[1], end, &uvece, width); vm_vec_scale_add(&p[2], end, &uvece, -width); vm_vec_scale_add(&p[3], start, &uvecs, -width); //move all the data from the vecs into the verts //tri 1 g3_transfer_vertex(&P[0], &p[3]); g3_transfer_vertex(&P[1], &p[2]); g3_transfer_vertex(&P[2], &p[1]); //tri 2 g3_transfer_vertex(&P[3], &p[3]); g3_transfer_vertex(&P[4], &p[1]); g3_transfer_vertex(&P[5], &p[0]); //set up the UV coords //tri 1 P[0].texture_position.u = 0.0f; P[0].texture_position.v = 0.0f; P[1].texture_position.u = 1.0f; P[1].texture_position.v = 0.0f; P[2].texture_position.u = 1.0f; P[2].texture_position.v = 1.0f; //tri 2 P[3].texture_position.u = 0.0f; P[3].texture_position.v = 0.0f; P[4].texture_position.u = 1.0f; P[4].texture_position.v = 1.0f; P[5].texture_position.u = 0.0f; P[5].texture_position.v = 1.0f; ubyte _color = (ubyte)(255.0f * intensity); for(int i = 0; i < 6; i++){ P[i].r = P[i].g = P[i].b = P[i].a = _color; if(offset > 0.0f) { R[i] = offset; } else { R[i] = width; } } n_to_render += 2; use_radius = true; }
void geometry_batcher::draw_bitmap(vertex *pnt, float rad, float angle, float depth) { float radius = rad; rad *= 1.41421356f;//1/0.707, becase these are the points of a square or width and height rad extern float Physics_viewer_bank; angle -= Physics_viewer_bank; if ( angle < 0.0f ) angle += PI2; else if ( angle > PI2 ) angle -= PI2; vec3d PNT(pnt->world); vec3d p[4]; vec3d fvec, rvec, uvec; vertex *P = &vert[n_to_render * 3]; float *R = &radius_list[n_to_render * 3]; vm_vec_sub(&fvec, &View_position, &PNT); vm_vec_normalize_safe(&fvec); vm_rot_point_around_line(&uvec, &View_matrix.vec.uvec, angle, &vmd_zero_vector, &View_matrix.vec.fvec); vm_vec_cross(&rvec, &View_matrix.vec.fvec, &uvec); vm_vec_normalize_safe(&rvec); vm_vec_cross(&uvec, &View_matrix.vec.fvec, &rvec); vm_vec_scale_add(&PNT, &PNT, &fvec, depth); vm_vec_scale_add(&p[0], &PNT, &rvec, rad); vm_vec_scale_add(&p[2], &PNT, &rvec, -rad); vm_vec_scale_add(&p[1], &p[2], &uvec, rad); vm_vec_scale_add(&p[3], &p[0], &uvec, -rad); vm_vec_scale_add(&p[0], &p[0], &uvec, rad); vm_vec_scale_add(&p[2], &p[2], &uvec, -rad); //move all the data from the vecs into the verts //tri 1 g3_transfer_vertex(&P[5], &p[3]); g3_transfer_vertex(&P[4], &p[2]); g3_transfer_vertex(&P[3], &p[1]); //tri 2 g3_transfer_vertex(&P[2], &p[3]); g3_transfer_vertex(&P[1], &p[1]); g3_transfer_vertex(&P[0], &p[0]); //tri 1 P[5].texture_position.u = 0.0f; P[5].texture_position.v = 0.0f; P[4].texture_position.u = 1.0f; P[4].texture_position.v = 0.0f; P[3].texture_position.u = 1.0f; P[3].texture_position.v = 1.0f; //tri 2 P[2].texture_position.u = 0.0f; P[2].texture_position.v = 0.0f; P[1].texture_position.u = 1.0f; P[1].texture_position.v = 1.0f; P[0].texture_position.u = 0.0f; P[0].texture_position.v = 1.0f; for (int i = 0; i < 6 ; i++) { P[i].r = pnt->r; P[i].g = pnt->g; P[i].b = pnt->b; P[i].a = pnt->a; R[i] = radius; } n_to_render += 2; }
/* 0----1 |\ | | \ | 3----2 */ void geometry_batcher::draw_bitmap(vertex *pnt, int orient, float rad, float depth) { float radius = rad; rad *= 1.41421356f;//1/0.707, becase these are the points of a square or width and height rad vec3d PNT(pnt->world); vec3d p[4]; vec3d fvec, rvec, uvec; vertex *P = &vert[n_to_render * 3]; float *R = &radius_list[n_to_render * 3]; // get the direction from the point to the eye vm_vec_sub(&fvec, &View_position, &PNT); vm_vec_normalize_safe(&fvec); // get an up vector in the general direction of what we want uvec = View_matrix.vec.uvec; // make a right vector from the f and up vector, this r vec is exactly what we want, so... vm_vec_cross(&rvec, &View_matrix.vec.fvec, &uvec); vm_vec_normalize_safe(&rvec); // fix the u vec with it vm_vec_cross(&uvec, &View_matrix.vec.fvec, &rvec); // move the center of the sprite based on the depth parameter if ( depth != 0.0f ) vm_vec_scale_add(&PNT, &PNT, &fvec, depth); // move one of the verts to the left vm_vec_scale_add(&p[0], &PNT, &rvec, rad); // and one to the right vm_vec_scale_add(&p[2], &PNT, &rvec, -rad); // now move all oof the verts to were they need to be vm_vec_scale_add(&p[1], &p[2], &uvec, rad); vm_vec_scale_add(&p[3], &p[0], &uvec, -rad); vm_vec_scale_add(&p[0], &p[0], &uvec, rad); vm_vec_scale_add(&p[2], &p[2], &uvec, -rad); //move all the data from the vecs into the verts //tri 1 g3_transfer_vertex(&P[5], &p[3]); g3_transfer_vertex(&P[4], &p[2]); g3_transfer_vertex(&P[3], &p[1]); //tri 2 g3_transfer_vertex(&P[2], &p[3]); g3_transfer_vertex(&P[1], &p[1]); g3_transfer_vertex(&P[0], &p[0]); // set up the UV coords if ( orient & 1 ) { // tri 1 P[5].texture_position.u = 1.0f; P[4].texture_position.u = 0.0f; P[3].texture_position.u = 0.0f; // tri 2 P[2].texture_position.u = 1.0f; P[1].texture_position.u = 0.0f; P[0].texture_position.u = 1.0f; } else { // tri 1 P[5].texture_position.u = 0.0f; P[4].texture_position.u = 1.0f; P[3].texture_position.u = 1.0f; // tri 2 P[2].texture_position.u = 0.0f; P[1].texture_position.u = 1.0f; P[0].texture_position.u = 0.0f; } if ( orient & 2 ) { // tri 1 P[5].texture_position.v = 1.0f; P[4].texture_position.v = 1.0f; P[3].texture_position.v = 0.0f; // tri 2 P[2].texture_position.v = 1.0f; P[1].texture_position.v = 0.0f; P[0].texture_position.v = 0.0f; } else { // tri 1 P[5].texture_position.v = 0.0f; P[4].texture_position.v = 0.0f; P[3].texture_position.v = 1.0f; // tri 2 P[2].texture_position.v = 0.0f; P[1].texture_position.v = 1.0f; P[0].texture_position.v = 1.0f; } for (int i = 0; i < 6 ; i++) { P[i].r = pnt->r; P[i].g = pnt->g; P[i].b = pnt->b; P[i].a = pnt->a; R[i] = radius; } n_to_render += 2; }
//compute the corners of a rod. fills in vertbuf. static int calc_rod_corners(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width) { vms_vector delta_vec,top,tempv,rod_norm; ubyte codes_and; int i; //compute vector from one point to other, do cross product with vector //from eye to get perpendiclar vm_vec_sub(&delta_vec,&bot_point->p3_vec,&top_point->p3_vec); //unscale for aspect delta_vec.x = fixdiv(delta_vec.x,Matrix_scale.x); delta_vec.y = fixdiv(delta_vec.y,Matrix_scale.y); //calc perp vector //do lots of normalizing to prevent overflowing. When this code works, //it should be optimized vm_vec_normalize(&delta_vec); vm_vec_copy_normalize(&top,&top_point->p3_vec); vm_vec_cross(&rod_norm,&delta_vec,&top); vm_vec_normalize(&rod_norm); //scale for aspect rod_norm.x = fixmul(rod_norm.x,Matrix_scale.x); rod_norm.y = fixmul(rod_norm.y,Matrix_scale.y); //now we have the usable edge. generate four points //top points vm_vec_copy_scale(&tempv,&rod_norm,top_width); tempv.z = 0; vm_vec_add(&rod_points[0].p3_vec,&top_point->p3_vec,&tempv); vm_vec_sub(&rod_points[1].p3_vec,&top_point->p3_vec,&tempv); vm_vec_copy_scale(&tempv,&rod_norm,bot_width); tempv.z = 0; vm_vec_sub(&rod_points[2].p3_vec,&bot_point->p3_vec,&tempv); vm_vec_add(&rod_points[3].p3_vec,&bot_point->p3_vec,&tempv); //now code the four points for (i=0,codes_and=0xff;i<4;i++) codes_and &= g3_code_point(&rod_points[i]); if (codes_and) return 1; //1 means off screen //clear flags for new points (not projected) for (i=0;i<4;i++) rod_points[i].p3_flags = 0; return 0; }