/************* * DESCRIPTION: convert rscn version 100 brushes and textures * INPUT: root surface root object * OUTPUT: - *************/ void SURFACE::ConvertV100(OBJECT *root) { BRUSH_OBJECT *brush; TEXTURE_OBJECT *texture; VECTOR ox,oy,oz; MATRIX m; InvOrient(&root->orient_x, &root->orient_y, &root->orient_z, &ox, &oy, &oz); m.SetOMatrix(&ox,&oy,&oz); brush = root->brush; while(brush) { VecSub(&brush->pos, &root->pos, &brush->pos); m.MultVectMat(&brush->orient_x); m.MultVectMat(&brush->orient_y); m.MultVectMat(&brush->orient_z); brush = (BRUSH_OBJECT*)brush->GetNext(); } texture = root->texture; while(texture) { VecSub(&texture->pos, &root->pos, &texture->pos); m.MultVectMat(&texture->orient_x); m.MultVectMat(&texture->orient_y); m.MultVectMat(&texture->orient_z); texture = (TEXTURE_OBJECT*)texture->GetNext(); } }
//求点到直线的垂足,返回点到垂足的距离。输入直线的两端点,当前点,输出垂足点,返回点到垂足的距离.Tested. float FootPoint(const float* Posi1, const float* Posi2, const float* PosiCur, float* fp) { float SE[3]; float SC[3]; float CE[3]; int i; VecSub(Posi2,Posi1,SE); VecSub(PosiCur,Posi1,SC); VecSub(Posi2,PosiCur,CE); if(VecDot(SE,SC) < 0) for(i=0; i<3; i++) fp[i] = Posi1[i]; else if(VecDot(SE,CE) < 0) for(i=0; i<3; i++) fp[i] = Posi2[i]; else { fp[1] = ( (SE[0]*SE[0]/SE[1]+SE[2]*SE[2]/SE[1])*Posi1[1] - SE[0]*(Posi1[0]-PosiCur[0]) + SE[1]*PosiCur[1] - SE[2]*(Posi1[2]-PosiCur[2]) ) / ( SE[0]*SE[0]/SE[1]+SE[1]+SE[2]*SE[2]/SE[1] ); fp[0] = SE[0]/SE[1]*(fp[1]-Posi1[1]) + Posi1[0]; fp[2] = SE[2]/SE[1]*(fp[1]-Posi1[1]) + Posi1[2]; } return sqrt((fp[0]-PosiCur[0])*(fp[0]-PosiCur[0]) + (fp[1]-PosiCur[1])*(fp[1]-PosiCur[1]) + (fp[2]-PosiCur[2])*(fp[2]-PosiCur[2])); }
void prop(std::vector<double> &pos, std::vector<double> &vel, double dt, int i){ // Updating Distance Between Bodies double r = mag(VecSub(pos, bodies[i].getPos())); // Updating Net Force std::vector<double> fNet = VecScaleMulti((VecSub(pos, bodies[i].getPos())), (G*bodies[0].getMass()*bodies[1].getMass())/(r*r*r)); // Update Netforce // Updating Pmomentum vel = VecAdd(vel, VecScaleMulti(fNet, dt/bodies[(i+1)%2].getMass())); // Updating Pos pos=VecAdd(pos, VecScaleMulti(vel, dt)); }
void OpenGLDrawCone(VECTOR *size, ULONG flags) { VECTOR bottom,bottom1, centertop; int i; VECTOR norm, e0,e1; if(!(flags & OBJECT_OPENBOTTOM)) { glEnable(GL_CULL_FACE); glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, -1.f, 0.f); glVertex3f(0.f, 0.f, 0.f); for(i = 0; i <= 360; i += OGL_CONE_DIVS) glVertex3f(sin(i*PI_180)*size->x, 0.f, cos(i*PI_180)*size->z); glEnd(); } glBegin(GL_TRIANGLE_FAN); glNormal3f(0.f, 1.f, 0.f); SetVector(¢ertop, 0.f, size->y, 0.f); glVertex3fv((GLfloat*)¢ertop); SetVector(&bottom, 0.f, 0.f, size->z); SetVector(&bottom1, sin((360-OGL_CONE_DIVS)*PI_180)*size->x, 0.f, cos((360-OGL_CONE_DIVS)*PI_180)*size->z); VecSub(¢ertop, &bottom, &e0); VecSub(¢ertop, &bottom1, &e1); VecNormCross(&e0, &e1, &norm); glNormal3fv((GLfloat*)&norm); glVertex3fv((GLfloat*)&bottom); for(i = 360-OGL_CONE_DIVS; i >= -OGL_CONE_DIVS; i -= OGL_CONE_DIVS) { bottom = bottom1; SetVector(&bottom1, sin(i*PI_180)*size->x, 0.f, cos(i*PI_180)*size->z); VecSub(¢ertop, &bottom, &e0); VecSub(¢ertop, &bottom1, &e1); VecNormCross(&e0, &e1, &norm); glNormal3fv((GLfloat*)&norm); glVertex3fv((GLfloat*)&bottom); } glEnd(); if(!(flags & OBJECT_OPENBOTTOM)) glDisable(GL_CULL_FACE); }
/************* * DESCRIPTION: Adjust the initial ray to account for an aperture and a focal * distance. The ray argument is assumed to be an initial ray, and * always reset to the eye point. It is assumed to be unit length. * INPUT: ray pointer to ray structure * world pointer to world structure * OUTPUT: none *************/ void CAMERA::FocusBlurRay(RAY *ray, WORLD *world) { VECTOR circle_point, aperture_inc; /* * Find a point on a unit circle and scale by aperture size. * This simulates rays passing thru different parts of the aperture. * Treat the point as a vector and rotate it so the circle lies * in the plane of the screen. Add the aperture increment to the * starting position of the ray. Stretch the ray to be focaldist * in length. Subtract the aperture increment from the end of the * long ray. This insures that the ray heads toward a point at * the specified focus distance, so that point will be in focus. * Normalize the ray, and that's it. Really. */ world->UnitCirclePoint(&circle_point, ray->sample); VecComb(aperture * circle_point.x, &scrni, aperture * circle_point.y, &scrnj, &aperture_inc); VecAdd(&aperture_inc, &pos, &(ray->start)); VecScale(focaldist, &ray->dir, &(ray->dir)); VecSub(&ray->dir, &aperture_inc, &(ray->dir)); VecNormalizeNoRet(&ray->dir); }
void DML::Update(float ** local_paras, float **grad, float *x, float * y, int simi_update, \ float * vec_buf_1, float * vec_buf_2) { VecSub(x, y, vec_buf_1, src_feat_dim); for (int i = 0; i < dst_feat_dim; i++) { float sum = 0; for (int j = 0; j < src_feat_dim; j++) { sum += local_paras[i][j]*vec_buf_1[j]; } vec_buf_2[i] = sum; } // dis similar pair if (simi_update == 0) { float dis = VecSqr(vec_buf_2, dst_feat_dim); if (dis > thre) { return; } } for (int i = 0; i < dst_feat_dim; i++) { for (int j = 0; j < src_feat_dim; j++) { if (simi_update == 1) // update similar pairs grad[i][j]+= vec_buf_2[i]*vec_buf_1[j]; else grad[i][j]+= -vec_buf_2[i]*vec_buf_1[j]; } } }
std::vector<std::vector<double>> netForce(){ size_t n = bodies.size(); double totMass = 1.0; std::vector<double> pos = {0, 0, 0}; std::vector<std::vector<double>> output; for(unsigned int i = 0; i < n; ++i){ totMass *= bodies[i].getMass(); for(unsigned int j = 0; j < n && i!=j; ++j){ double magnitude = mag(VecSub(bodies[i].getPos(), bodies[j].getPos())); pos = VecAdd(pos, VecScaleMulti((VecSub(bodies[i].getPos(), bodies[j].getPos())), (1.0/(magnitude * magnitude * magnitude)))); } output.push_back(VecScaleMulti(pos, totMass*G)); } return output; }
std::vector<double> accelFunc(std::vector<double> pos, std::vector<double> vel, double t){ std::vector<double> accel = {0, 0, 0}; double r; for(size_t i=0; i<bodies.size();++i){ r = mag(VecSub(pos, bodies[i].getPos())); if(r==0){ // If comparing body is same as current body continue; }else{ // If comparing to foreign body //accel+=bodies[i].getMass()/(r*r*r); accel= VecAdd(accel, VecScaleMulti(VecSub(pos, bodies[i].getPos()), (G*bodies[i].getMass()/(r*r*r)) ) ); } } return accel; }
void SphereMapping( Mapping *map, Geom * /*obj*/, Vector *pos, Vector * /*norm*/, Vec2d *uv, Vector * /*dpdu*/, Vector * /*dpdv*/) { Vector vtmp; Float nx, ny, nz, phi, theta; VecSub(*pos, map->center, &vtmp); if (VecNormalize(&vtmp) == 0.) { /* * Point is coincident with origin of sphere. Punt. */ uv->u = uv->v = 0.; return; } /* * Find location of point projected onto unit sphere * in the sphere's coordinate system. */ nx = dotp(&map->uaxis, &vtmp); ny = dotp(&map->vaxis, &vtmp); nz = dotp(&map->norm, &vtmp); if (nz > 1.) /* roundoff */ phi = PI; else if (nz < -1.) phi = 0; else phi = acos(-nz); uv->v = phi / PI; if (fabs(uv->v) < EPSILON || equal(uv->v, 1.)) uv->u = 0.; else { theta = nx / sin(phi); if (theta > 1.) theta = 0.; else if (theta < -1.) theta = 0.5; else theta = acos(theta) / TWOPI; if (ny > 0) uv->u = theta; else uv->u = 1 - theta; } }
/************* * DESCRIPTION: transfer camera data to RayStorm Interface * INPUT: stack matrix stack * object pointer to created rsi object * OUTPUT: rsiERR_NONE if ok else error number *************/ rsiResult CAMERA::ToRSI(rsiCONTEXT *rc, MATRIX_STACK *stack, void **object) { VECTOR up, look, orient_x, orient_y, orient_z, pos; MATRIX m, m1; int rsiflags; rsiResult err; stack->GenerateAxis(&orient_x, &orient_y, &orient_z, &pos); m.SetOMatrix(&orient_x, &orient_y, &orient_z); if(track) { track->GetObjectMatrix(&m1); m1.GenerateAxis(&orient_x, &orient_x, &orient_x, &look); } else { SetVector(&look, 0.f, 0.f, 1000.f); m.MultVectMat(&look); VecAdd(&look, &pos, &look); } SetVector(&up, 0.f, 1.f, 0.f); m.MultVectMat(&up); err = PPC_STUB(rsiSetCamera)(CTXT, rsiTCameraPos, &pos, rsiTCameraViewUp, &up, rsiTCameraLook, &look, rsiTDone); if(err) return err; if(flags & OBJECT_CAMERA_VFOV) vfov = hfov*global.yres/global.xres; if(flags & OBJECT_CAMERA_FOCUSTRACK) { VecSub(&look, &pos, &look); focaldist = VecNormalize(&look); } rsiflags = 0; if (flags & OBJECT_CAMERA_FASTDOF) rsiflags |= rsiFCameraFastDOF; return PPC_STUB(rsiSetCamera)(CTXT, rsiTCameraPos, &pos, rsiTCameraHFov, atan(hfov) * 2 * INV_PI_180, rsiTCameraVFov, atan(vfov) * 2 * INV_PI_180, rsiTCameraFocalDist, focaldist, rsiTCameraAperture, aperture, rsiTCameraFlags, rsiflags, rsiTDone); }
void make_view_matrix(Vec p1, Vec p2, Matrix m) { Flt d, len, l1; Vec up, out, left; Vec upv={0,1,0}; //Log( "make_view_matrix()...\n"); //Line between p1 and p2 form a LOS Line-of-sight. //A rotation matrix is built to transform objects to this LOS. // //Diana Gruber //http://www.makegames.com/3Drotation/ // m[0][0]=1.0; m[0][1]=0.0; m[0][2] =0.0; m[1][0]=0.0; m[1][1]=1.0; m[1][2] =0.0; m[2][0]=0.0; m[2][1]=0.0; m[2][2] =1.0; VecSub(p2, p1, out); // len = out[0]*out[0] + out[1]*out[1] + out[2]*out[2]; if (len == 0.0) { MakeVector(0.0,0.0,1.0,out); } else { l1 = 1.0 / sqrt(len); out[0] *= l1; out[1] *= l1; out[2] *= l1; } // m[2][0] = out[0]; m[2][1] = out[1]; m[2][2] = out[2]; // d = out[0] * upv[0] + out[1] * upv[1] + out[2] * upv[2]; up[0] = upv[0] - d * out[0]; up[1] = upv[1] - d * out[1]; up[2] = upv[2] - d * out[2]; len = up[0]*up[0] + up[1]*up[1] + up[2]*up[2]; if (len == 0.0) { MakeVector(0, 0, 1, up); } else { l1 = 1.0 / sqrt(len); up[0] *= l1; up[1] *= l1; up[2] *= l1; } m[1][0] = up[0]; m[1][1] = up[1]; m[1][2] = up[2]; //make left vector. VecCross(up, out, left); m[0][0] = left[0]; m[0][1] = left[1]; m[0][2] = left[2]; }
static void ExtendedDirection(LightRef lr, Vector *pos,Vector* dir,Float* dist) { Extended *lp = (Extended*)lr; /* * Calculate dir from position to center of * light source. */ VecSub(lp->pos, *pos, dir); *dist = VecNormalize(dir); }
float DML::PairDis(float ** L, pair p, float **data_ptr, \ float * vec_buf_1, float * vec_buf_2) { VecSub(data_ptr[p.x], data_ptr[p.y], vec_buf_1, src_feat_dim); for (int i = 0; i < dst_feat_dim; i++) { float sum = 0; for (int j = 0; j < src_feat_dim; j++) { sum += L[i][j]*vec_buf_1[j]; } vec_buf_2[i] = sum; } return VecSqr(vec_buf_2, dst_feat_dim); }
VOID SphTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) { INT i; INT numelems; /* Number of object elements. */ REAL new_rad; SPHERE *ps; /* Ptr to sphere data. */ ELEMENT *pe; /* Ptr to sphere element. */ POINT surf_point; /* Point on surface. */ POINT center_point; /* Center_point. */ POINT rad_vector; /* Radius vector. */ pe = po->pelem; numelems = po->numelements; for (i = 0; i < numelems; i++) { ps = (SPHERE *)pe->data; /* See if radius has changed with a scale. */ surf_point[0] = ps->center[0] + ps->rad; surf_point[1] = ps->center[1]; surf_point[2] = ps->center[2]; surf_point[3] = 1.0; center_point[0] = ps->center[0]; center_point[1] = ps->center[1]; center_point[2] = ps->center[2]; center_point[3] = 1.0; /* Transform center point. */ VecMatMult(center_point, xtrans, center_point); VecMatMult(surf_point, xtrans, surf_point); /* Find radius. */ VecSub(rad_vector, surf_point, center_point); VecCopy(ps->center, center_point); new_rad = VecLen(rad_vector); if (new_rad != ps->rad) { ps->rad = new_rad; ps->rad2 = ps->rad * ps->rad; } pe++; } }
void OpenGLDrawMesh(TRIANGLE *trias, EDGE *edges, VECTOR *points, VECTOR *normals, ULONG acttrias) { USHORT p1,p2,p3; ULONG i; #ifndef NORMAL VECTOR e1,e2,n; #endif // NORMAL glBegin(GL_TRIANGLES); for(i=0; i<acttrias; i++) { p1 = edges[trias->e[0]].p[0]; p2 = edges[trias->e[0]].p[1]; if((p1 != edges[trias->e[1]].p[0]) && (p2 != edges[trias->e[1]].p[0])) p3 = edges[trias->e[1]].p[0]; else p3 = edges[trias->e[1]].p[1]; #ifdef NORMAL glNormal3fv((GLfloat*)&normals[trias->n[0]]); glVertex3fv((GLfloat*)&points[p1]); glNormal3fv((GLfloat*)&normals[trias->n[1]]); glVertex3fv((GLfloat*)&points[p2]); glNormal3fv((GLfloat*)&normals[trias->n[2]]); glVertex3fv((GLfloat*)&points[p3]); #else // NORMAL VecSub(&points[p3], &points[p1], &e1); VecSub(&points[p3], &points[p2], &e2); VecNormCross(&e2, &e1, &n); glNormal3fv((GLfloat*)&n); glVertex3fv((GLfloat*)&points[p1]); glVertex3fv((GLfloat*)&points[p2]); glVertex3fv((GLfloat*)&points[p3]); #endif // NORMAL trias++; } glEnd(); }
VOID SphNormal(IRECORD *hit, POINT Pi, POINT Ni) { ELEMENT *pe; SPHERE *ps; /* Ptr to sphere data. */ /* Compute normal and make it a unit vector. */ pe = hit->pelem; ps = (SPHERE *)pe->data; VecSub(Ni, Pi, ps->center); Ni[0] /= ps->rad; Ni[1] /= ps->rad; Ni[2] /= ps->rad; }
/************* * DESCRIPTION: Modify given normal by "bumping" it. * INPUT: norm normal * dpdu delta u * dpdv delta v * fu * fv * OUTPUT: none *************/ void MakeBump(VECTOR *norm, VECTOR *dpdu, VECTOR *dpdv, float fu, float fv) { VECTOR tmp1, tmp2; VecCross(norm, dpdv, &tmp1); tmp1.x *= fu; tmp1.y *= fu; tmp1.z *= fu; VecCross(norm, dpdu, &tmp2); tmp2.x *= fv; tmp2.y *= fv; tmp2.z *= fv; VecSub(&tmp1, &tmp2, &tmp1); VecAdd(norm, &tmp1, norm); VecNormalizeNoRet(norm); }
VOID SphDataNormalize(OBJECT *po, MATRIX normMat) { INT i; SPHERE *ps; /* Ptr to sphere data. */ ELEMENT *pe; /* Ptr to sphere element. */ POINT surf_point; /* Point on surface. */ POINT center_point; /* Center point. */ POINT rad_vector; /* Radius vector. */ NormalizeBoundBox(&po->bv, normMat); pe = po->pelem; for (i = 0; i < po->numelements; i++) { ps = (SPHERE *)pe->data; NormalizeBoundBox(&pe->bv, normMat); surf_point[0] = ps->center[0] + ps->rad; surf_point[1] = ps->center[1]; surf_point[2] = ps->center[2]; surf_point[3] = 1.0; center_point[0] = ps->center[0]; center_point[1] = ps->center[1]; center_point[2] = ps->center[2]; center_point[3] = 1.0; /* Transform center point. */ VecMatMult(center_point, normMat, center_point); VecMatMult(surf_point, normMat, surf_point); /* Find new radius. */ VecSub(rad_vector, surf_point, center_point); VecCopy(ps->center, center_point); ps->rad = VecLen(rad_vector); ps->rad2 = ps->rad * ps->rad; pe++; } }
/* * Compute intensity ('color') of extended light source 'lp' from 'pos'. */ static int ExtendedIntens( LightRef lr, Color *lcolor, ShadowCache *cache, Ray *ray, Float /*dist*/, int noshadow, Color *color) { Extended *lp = (Extended*)lr; Float jit, vpos, upos, lightdist; Ray newray; Vector Uaxis, Vaxis, ldir; if (noshadow) { *color = *lcolor; return TRUE; } newray = *ray; /* * Determinte two orthoganal vectors that lay in the plane * whose normal is defined by the vector from the center * of the light source to the point of intersection and * passes through the center of the light source. */ VecSub(lp->pos, ray->pos, &ldir); VecCoordSys(&ldir, &Uaxis, &Vaxis); jit = 2. * lp->radius * Sampling.spacing; /* * Sample a single point, determined by SampleNumber, * on the extended source. */ vpos = -lp->radius + (ray->sample % Sampling.sidesamples)*jit; upos = -lp->radius + (ray->sample / Sampling.sidesamples)*jit; vpos += nrand() * jit; upos += nrand() * jit; VecComb(upos, Uaxis, vpos, Vaxis, &newray.dir); VecAdd(ldir, newray.dir, &newray.dir); lightdist = VecNormalize(&newray.dir); return !Shadowed(color, lcolor, cache, &newray, lightdist, noshadow); }
/************* * DESCRIPTION: This routine does both undo and redo for transformations. * INPUT: - * OUTPUT: - *************/ void UNDO_TRANSFORM_OBJECT::Undo_Redo() { VECTOR dpos, dox, doy, doz, dsize; MATRIX m,m1; VECTOR rpos, rorient_x, rorient_y, rorient_z, rsize; // Save current values for redo/undo rpos = object->pos; rorient_x = object->orient_x; rorient_y = object->orient_y; rorient_z = object->orient_z; rsize = object->size; // we need delta values VecSub(&pos, &object->pos, &dpos); object->pos = pos; m.SetOMatrix(&orient_x, &orient_y, &orient_z); m.InvMat(&m1); dox = object->orient_x; doy = object->orient_y; doz = object->orient_z; m1.MultMatOrient(&dox, &doy, &doz); object->orient_x = orient_x; object->orient_y = orient_y; object->orient_z = orient_z; dsize.x = size.x / object->size.x; dsize.y = size.y / object->size.y; dsize.z = size.z / object->size.z; object->size = size; object->SetTreeSizes(&dsize); object->SetObject(NULL, &dpos, &dox, &dox, &dox, &dsize); if(object->istracked) UpdateTracking(); // remember old values for redo/undo pos = rpos; orient_x = rorient_x; orient_y = rorient_y; orient_z = rorient_z; size = rsize; }
static void PlaneUV(GeomRef gref, Vector *pos,Vector *norm, Vec2d *uv,Vector *dpdu,Vector *dpdv) { Plane *plane = (Plane*)gref; Vector vec, du, dv; VecCoordSys(norm, &du, &dv); VecSub(*pos, plane->pos, &vec); uv->u = dotp(&vec, &du); uv->v = dotp(&vec, &dv); if (dpdu) *dpdu = du; if (dpdv) *dpdv = dv; }
/************* * DESCRIPTION: Apply RayStorm texture to surface * INPUT: norm normal * surf surface * pos_ current position on surface * ray actual ray * OUTPUT: none *************/ void RAYSTORM_TEXTURE::Apply(VECTOR *norm, SURFACE *surf, const VECTOR *pos_, RAY *ray) { TEXTURE_PATCH ptch; VECTOR relpos,v; ptch.ambient = surf->ambient; ptch.specular = surf->specular; ptch.diffuse = surf->diffuse; ptch.reflect = surf->reflect; ptch.transpar = surf->transpar; ptch.difftrans = surf->difftrans; ptch.spectrans = surf->spectrans; ptch.refphong = surf->refphong; ptch.transphong = surf->transphong; ptch.foglength = surf->foglength; ptch.refrindex = surf->refrindex; ptch.translucency = surf->translucency; ptch.norm = *norm; // update texture if neccassary if(actor && (time != ray->time)) Update(ray->time); VecSub(pos_, &pos, &v); relpos.x = dotp(&orient_x, &v) / size.x; relpos.y = dotp(&orient_y, &v) / size.y; relpos.z = dotp(&orient_z, &v) / size.z; tinfo->work(tinfo, data, &ptch, &relpos); surf->ambient = ptch.ambient; surf->specular = ptch.specular; surf->diffuse = ptch.diffuse; surf->reflect = ptch.reflect; surf->transpar = ptch.transpar; surf->difftrans = ptch.difftrans; surf->spectrans = ptch.spectrans; surf->refphong = ptch.refphong; surf->transphong = ptch.transphong; surf->foglength = ptch.foglength; surf->refrindex = ptch.refrindex; surf->translucency = ptch.translucency; *norm = ptch.norm; }
int vf_sphere_inside(const view_params *vp, const vec3 center, real radius) { vec3 c_eye; /* transform center to eye space */ VecSub(c_eye, center, vp->eye); /* check if it's inside near and far z planes */ real d = VecDot(vp->gaze, c_eye); if (d+radius < vp->znear || d-radius > vp->zfar) return 0; /* now if it's outside with respect to any of top, bottom, left or right * view planes, it's outside the vf, otherwise it's inside */ if (VecDot(c_eye, vp->nr) > radius) return 0; if (VecDot(c_eye, vp->nl) > radius) return 0; if (VecDot(c_eye, vp->nt) > radius) return 0; if (VecDot(c_eye, vp->nb) > radius) return 0; return 1; }
/************* * DESCRIPTION: Initialize Camera (MUST be called if parameters changed) * INPUT: none * OUTPUT: none *************/ void CAMERA::InitCamera() { float lookdist, magnitude; VECTOR dir; VecSub(&lookp, &pos, &dir); firstray = dir; lookdist = VecNormalize(&dir); VecNormCross(&dir, &vup, &scrni); VecNormCross(&scrni, &dir, &scrnj); magnitude = -2.f*lookdist * (float)tan(0.5f*hfov*PI_180)/xres; VecScale(magnitude, &scrni, &scrnx); magnitude = 2.f*lookdist * (float)tan(0.5f*vfov*PI_180)/yres; VecScale(magnitude, &scrnj, &scrny); firstray.x -= 0.5f*yres*scrny.x + 0.5f*xres*scrnx.x; firstray.y -= 0.5f*yres*scrny.y + 0.5f*xres*scrnx.y; firstray.z -= 0.5f*yres*scrny.z + 0.5f*xres*scrnx.z; DoFData.xres = xres; DoFData.yres = yres; DoFData.left = left; DoFData.top = top; DoFData.right = right; DoFData.bottom = bottom; DoFData.focaldist = focaldist; DoFData.hfov = hfov*PI/180.0f; DoFData.vfov = vfov*PI/180.0f; DoFData.aperture = 2*aperture; DoFData.samples = 7; DoFData.flags = 0; if ((flags & HIDDENAREA) == HIDDENAREA) DoFData.flags = DoFHidden; if ((flags & ACCELERATE) == ACCELERATE) DoFData.flags |= DoFAccelerate; DoF.Init(&DoFData); }
INT SphPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) { INT nhits; /* Number of hits. */ REAL b, disc, t1, t2, vsq; /* Formula variables. */ SPHERE *ps; /* Ptr to sphere data. */ POINT V; /* C - P */ IRECORD *sphhit; ps = (SPHERE *)(pe->data); sphhit = hit; VecSub(V, ps->center, pr->P); /* Ray from origin to center.*/ vsq = VecDot(V, V); /* Length sq of V. */ b = VecDot(V, pr->D); /* Perpendicular scale of V. */ if (vsq > ps->rad2 && b < RAYEPS) /* Behind ray origin. */ return (0); disc = b*b - vsq + ps->rad2; /* Discriminate. */ if (disc < 0.0) /* Misses ray. */ return (0); disc = sqrt(disc); /* Find intersection param. */ t2 = b + disc; t1 = b - disc; if (t2 <= RAYEPS) /* Behind ray origin. */ return (0); nhits = 0; if (t1 > RAYEPS) /* Entering sphere. */ { IsectAdd(sphhit, t1, pe); sphhit++; nhits++; } IsectAdd(sphhit, t2, pe); /* Exiting sphere */ nhits++; return (nhits); }
int vf_point_inside(const view_params *vp, const vec3 v) { vec3 v_eye; /* transform vertex to eye space */ VecSub(v_eye, v, vp->eye); /* check if it's inside near and far z planes */ real d = VecDot(vp->gaze, v_eye); if (d < vp->znear || d > vp->zfar) return 0; /* now if it's outside with respect to any of top, bottom, left or right * view planes, it's outside the vf, otherwise it's inside */ if (VecDot(v_eye, vp->nr) > 0) return 0; if (VecDot(v_eye, vp->nl) > 0) return 0; if (VecDot(v_eye, vp->nt) > 0) return 0; if (VecDot(v_eye, vp->nb) > 0) return 0; return 1; }
void CylinderMapping( Mapping *map, Geom * /*obj*/, Vector *pos, Vector * /*norm*/, Vec2d *uv, Vector *dpdu, Vector *dpdv) { Vector vtmp; Float nx, ny, r; VecSub(*pos, map->center, &vtmp); nx = dotp(&map->uaxis, &vtmp); ny = dotp(&map->vaxis, &vtmp); uv->v = dotp(&map->norm, &vtmp); r = sqrt(nx*nx + ny*ny); if (r < EPSILON) { uv->u = 0.; return; } nx /= r; ny /= r; if (fabs(nx) > 1.) uv->u = 0.5; else uv->u = acos(nx) / TWOPI; if (ny < 0.) uv->u = 1. - uv->u; if (dpdv) *dpdv = map->norm; if (dpdu) (void)VecNormCross(&map->norm, pos, dpdu); }
/************* * DESCRIPTION: Apply imagine texture to surface * INPUT: norm normal * surf surface * pos_ current position on surface * ray actual ray * OUTPUT: none *************/ void IMAGINE_TEXTURE::Apply(VECTOR *norm, SURFACE *surf, const VECTOR *pos_, RAY *ray) { IM_PATCH patch; /* patch-structure */ VECTOR v, relpos; /* hit position relative to texture axis */ patch.ptc_pos = *pos_; patch.ptc_nor = *norm; patch.ptc_col = surf->diffuse; patch.ptc_ref = surf->reflect; patch.ptc_tra = surf->transpar; patch.ptc_spc = surf->specular; patch.ptc_shp = 2; patch.ptc_shd = TRUE; patch.ptc_ray = &ray->start; patch.raydist = ray->lambda; patch.foglen = 0.f; // update texture if neccassary if(actor && (time != ray->time)) Update(ray->time); VecSub(pos_, &pos, &v); relpos.x = dotp(&orient_x, &v); relpos.y = dotp(&orient_y, &v); relpos.z = dotp(&orient_z, &v); #ifdef __PPC__ ppc_texture_work(texture->ttable->work, param, &patch, &relpos, (float*)(&pos)); #else texture->ttable->work(param, &patch, &relpos, (float*)(&pos)); #endif surf->diffuse = patch.ptc_col; surf->reflect = patch.ptc_ref; surf->transpar = patch.ptc_tra; *norm = patch.ptc_nor; }
/************* * DESCRIPTION: texture work funcion * INPUT: this texture * pos position to sample * norm normal at this point * OUTPUT: *************/ void IPREVIEW_TEXTURE::Work(PREVIEW *preview, VECTOR *pos, VECTOR *norm) { VECTOR relpos; patch.ptc_pos = *pos; patch.ptc_nor = *norm; patch.ptc_col = preview->diffuse; patch.ptc_ref = preview->reflect; patch.ptc_tra = preview->transpar; patch.ptc_spc = preview->surf->specular; VecSub(pos, &form.pos, &relpos); #ifdef __PPC__ ITextureWork(ttable, params, &patch, &relpos, (float*)&form); #else ttable->work(params, &patch, &relpos, (float*)&form); #endif preview->diffuse = patch.ptc_col; preview->reflect = patch.ptc_ref; preview->transpar = patch.ptc_tra; *norm = patch.ptc_nor; }
/************* * DESCRIPTION: Apply hyper texture to surface * INPUT: norm normal * surf surface * pos_ current position on surface * ray current ray * OUTPUT: none *************/ void HYPER_TEXTURE::Apply(VECTOR *norm, SURFACE *surf, const VECTOR *pos_, RAY *ray, float *density, float object_density, COLOR *color) { TEXTURE_PATCH ptch; VECTOR relpos,v; ptch.diffuse = *color; ptch.object_density = object_density; ptch.norm = *norm; // update texture if neccassary if(actor && (time != ray->time)) Update(ray->time); VecSub(pos_, &pos, &v); relpos.x = dotp(&orient_x, &v) / size.x; relpos.y = dotp(&orient_y, &v) / size.y; relpos.z = dotp(&orient_z, &v) / size.z; tinfo->work(tinfo, data, &ptch, &relpos); *color = ptch.diffuse; *density = ptch.density; *norm = ptch.norm; }