您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ vec_scale函数代码示例

51自学网 2021-06-03 09:36:29
  C++
这篇教程C++ vec_scale函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中vec_scale函数的典型用法代码示例。如果您正苦于以下问题:C++ vec_scale函数的具体用法?C++ vec_scale怎么用?C++ vec_scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了vec_scale函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: vec_scale

mat_t *mat_scale(float s, mat_t *a){	a->x = vec_scale(s,a->x);	a->y = vec_scale(s,a->y);	a->z = vec_scale(s,a->z);	a->w = vec_scale(s,a->w);	return a;}
开发者ID:fvdsn,项目名称:gally,代码行数:7,


示例2: auto_orient

void auto_orient (void){  int face;    for (face = 0; face < 6; face++)    {      float u[3], a_minus_b[3], a_minus_c[3];            vec_sub (a_minus_b, points[tristrips[face][0]],	       points[tristrips[face][1]]);      vec_scale (a_minus_b, a_minus_b, texcoords[0][1] - texcoords[2][1]);      vec_sub (a_minus_c, points[tristrips[face][0]],	       points[tristrips[face][2]]);      vec_scale (a_minus_c, a_minus_c, texcoords[0][1] - texcoords[1][1]);      vec_sub (u, a_minus_b, a_minus_c);      /* Not really sure if this is right.  */      if (((texcoords[0][0] - texcoords[1][0])	    * (texcoords[0][1] - texcoords[2][1])	   - (texcoords[0][0] - texcoords[2][0])	      * (texcoords[0][1] - texcoords[1][1])) < 0.0f)	vec_scale (u, u, -1.0f);      vec_normalize (u, u);      printf ("face %d: calculated [ %f %f %f ]/n", face, u[0], u[1], u[2]);      printf ("  previously [ %f %f %f ]/n", face_orient[face][0],	      face_orient[face][1], face_orient[face][2]);    }}
开发者ID:crtc-demos,项目名称:wobble,代码行数:28,


示例3: column

void SMat<CoeffRing>::column2by2(size_t c1,                                 size_t c2,                                 elem a1,                                 elem a2,                                 elem b1,                                 elem b2)/* column(c1) <- a1 * column(c1) + a2 * column(c2),   column(c2) <- b1 * column(c1) + b2 * column(c2)*/{  // Make first column: v1 = a1*c1+a2*c2  sparsevec *v1 = vec_copy(columns_[c1]);  sparsevec *v2 = vec_copy(columns_[c2]);  vec_scale(v1, a1);  vec_scale(v2, a2);  vec_add_to(v1, v2);  // Second column: w1 = b1*c1 + b2*c2  sparsevec *w1 = columns_[c1];  sparsevec *w2 = columns_[c2];  vec_scale(w1, b1);  vec_scale(w2, b2);  vec_add_to(w1, w2);  // Set the matrices:  columns_[c1] = v1;  columns_[c2] = w1;}
开发者ID:BertiniM2,项目名称:M2,代码行数:28,


示例4: ga_shade_ao

/* Computes ambiant occlusion */static void ga_shade_ao(vec_t *color, const ga_scene_t *s, const ga_material_t *mat, const vec_t *pos, const vec_t *norm, float importance){	int sample = mat->ao_sample;	float rlen,fact;	vec_t ao_color = vec_new(0,0,0,1);	vec_t dsample,d1,d2;	vec_fperp(norm,&d1,&d2);	while(sample--){		dsample = vec_new(0,0,0,1);		vec_ffadd(&dsample,random()*RAND_NORM,norm);		vec_ffadd(&dsample,(2.0f*random()*RAND_NORM) -1.0f,&d1);		vec_ffadd(&dsample,(2.0f*random()*RAND_NORM) -1.0f,&d2);		vec_fnorm(&dsample);		rlen = ga_ray_length(s,*pos,dsample);		if (rlen <= mat->ao_min_dist){			ao_color = vec_add(ao_color,mat->ao_min_color);		}else if (rlen >= mat->ao_max_dist){			ao_color = vec_add(ao_color,mat->ao_max_color);		}else{			fact = (rlen - mat->ao_min_dist) / (mat->ao_max_dist - mat->ao_min_dist) ;			ao_color = vec_add(ao_color,					vec_add(vec_scale(fact,mat->ao_max_color),						vec_scale(1.0f-fact,mat->ao_min_color)));		}	}	*color = vec_add(*color,			vec_scale(1.0f/mat->ao_sample*mat->ao_factor,ao_color));}
开发者ID:fvdsn,项目名称:gally,代码行数:28,


示例5: crLottiUpdateFly

BOOL crLottiUpdateFly (ENTITY* e){	VECTOR v, w;		vec_set(&w, e->crAccel);	vec_scale(&w, time_step);	vec_add(e->crSpeed, &w);		vec_set(&v, e->crSpeed);	vec_scale(&v, time_step);	vec_add(e->x, &v);		VECTOR feet;		feet.x = feet.y = 0;	feet.z = 0.5 * e->min_z;		vec_rotate(feet, e->pan);	vec_add(feet, e->x);		ent_animate(e, "drown", 5 * total_ticks + e->crInit, ANM_CYCLE);		effect(credits_fire, 2, feet, e->crSpeed);		// explode near screen border	VECTOR v;	vec_set(&v, e->x);		vec_to_screen(&v, camera);		return (v.x < e->crPercent * screen_size.x || v.x > (1 - e->crPercent) * screen_size.x ||	        v.y < e->crPercent * screen_size.y || v.y > (1 - e->crPercent) * screen_size.y);}
开发者ID:Acknex,项目名称:Prince-of-Lotteria,代码行数:34,


示例6: compute_ray

void compute_ray(RAY* ray, VECTOR3D* view_point, VIEWPORT* viewport, PIXEL* pixel, VEC_BASIS* camera_frame, double distance) {	float u, v;	VECTOR3D v1, v2, v3, v4, dir;			// 1. calculate u and v coordinates of the pixels on the image plane:	u = (double)(viewport->xvmin) + (double)(pixel->i) + 0.5 ;  	v = (double)(viewport->yvmin) + (double)(pixel->j) + 0.5 ;  		// 2. calculate ray direction		vec_scale(-distance, &v1, &camera_frame->n);	vec_scale(u, &v2, &camera_frame->u);	vec_scale(v, &v3, &camera_frame->v);		ray->origin.x = view_point->x;  	ray->origin.y = view_point->y;	ray->origin.z = view_point->z;		vec_add(&v4, &v1, &v2);	vec_add(&dir, &v4, &v3);	normalize_vector(&dir);		ray->direction.x = dir.x;	ray->direction.y = dir.y;	ray->direction.z = dir.z;}
开发者ID:BostjanSkok,项目名称:VPSASem1,代码行数:27,


示例7: integrate

void integrate(particle_t *src, particle_t *dst, vec3f acceleration, float dt){    // euler-cromer method    // v' = v + a*dt    --    v, v' and a are vectors, dt is a scalar.    dst->velocity = vec_add(src->velocity, vec_scale(acceleration, dt));    // x' = x + v'*dt   --    x', x, v' are vectors, dt is a scalar.    dst->position = vec_add(src->position, vec_scale(dst->velocity, dt));}
开发者ID:Jem777,项目名称:orbits3d,代码行数:7,


示例8: getReflectedRay

Vector getReflectedRay(Vector surface_norm, Vector light_ray){	float cosTheta1 = vec_dot(surface_norm, vec_scale(light_ray,-1));	Vector reflect_ray = vec_plus(light_ray, vec_scale(surface_norm, 2*cosTheta1));	return reflect_ray;}
开发者ID:hodannyy,项目名称:ray-tracer,代码行数:7,


示例9: intersection_normal

// Calculate normal vector in the point of intersection:void intersection_normal(SPHERE *sphere, SPHERE_INTERSECTION* intersection, RAY* ray) {		double lambda, scale;	VECTOR3D v1, v2, point, normal;		lambda = intersection->lambda_in;		vec_scale(lambda, &v1, &ray->direction);	vec_add(&point, &v1, &ray->origin);		intersection->point.x = point.x;	intersection->point.y = point.y;	intersection->point.z = point.z;		vec_sub(&v2, &point, &sphere->center);		scale = 1.0 / sphere->radius;	vec_scale(scale, &normal, &v2);		normalize_vector(&normal);	intersection->normal.x = normal.x;	intersection->normal.y = normal.y;	intersection->normal.z = normal.z;	}
开发者ID:BostjanSkok,项目名称:VPSASem1,代码行数:27,


示例10: box_bounds

box_t box_bounds(box_t b) {  vec_t corner = vec_add(vec_abs(vec_scale(b.axis0, b.size.x)), vec_abs(vec_scale(b.axis1, b.size.y)));  box_t r;  r.pos = b.pos;  r.size = corner;  r.axis0 = vec_new(corner.x, 0);  r.axis1 = vec_new(0, corner.y);  return r;}
开发者ID:Allanis,项目名称:SpaceJam,代码行数:9,


示例11: vec_reflect

//reflect a vector from a surface plane]void vec_reflect(vec_t *n, vec_t *w, vec_t *v) {    vec_t *u = (vec_t *)malloc(sizeof(vec_t));    vec_unit(w, u);    vec_scale(-1, u, u);    vec_scale((2*vec_dot(u, n)), n, v);    vec_diff(u, v, v);    free(u);}
开发者ID:ryan-becwar,项目名称:raytracer,代码行数:13,


示例12: ga_shade_phong

/* Computes the phong hilight */static void ga_shade_phong(vec_t *color, const ga_material_t *mat,const vec_t *lcolor, const vec_t *ldir, const vec_t *dir, const vec_t *norm, float factor){	vec_t r;	float fact;	float power;	r = vec_sub(		vec_scale(2.0f,vec_scale(vec_dot(*norm,*ldir),*norm)),		*ldir);		if((fact = vec_dot(r,vec_neg(*dir))) > 0.0f){		power = powf(fact,mat->spec_power)*mat->spec_factor;		*color = vec_add(*color, vec_scale( power*factor,				vec_mult(mat->spec_color,*lcolor)));	}}
开发者ID:fvdsn,项目名称:gally,代码行数:14,


示例13: lighting

rgb lighting(scene s, ray r, hit_test h){  rgb result;  if (h.miss)    return s.bg;  vec hit_position = ray_position(r, h.dist);  if (shadow(hit_position, s.light, s.spheres)) {    result = rgb_modulate(h.surf, s.amb);  }  else {      double dot = vec_dot(h.surf_norm, s.light.direction);    double d = double_max(0, dot);    rgb diffuse_light = rgb_scale(d, s.light.color);    rgb lsum = rgb_add(s.amb, diffuse_light);    result = rgb_modulate(h.surf, lsum);  }  /**** === implement specular reflection here === ****/   if (rgb_nonzero(h.shine)) {    rgb ss;    vec N = h.surf_norm;    vec L = s.light.direction;    rgb S = h.shine;    vec R = vec_sub( vec_scale(2* vec_dot(N,L),N),L);    vec V = vec_neg(r.direction);    if (vec_dot(N,L)>0){      ss = rgb_scale( pow( double_max( vec_dot(R,V),0), 6), S);      //rgb_print(k);    }    else      ss = rgb_expr(0,0,0);    return rgb_add(result,ss);  }  return result;}
开发者ID:yunchenliu,项目名称:Sample_C_Code,代码行数:35,


示例14: item_fade

void item_fade(){	var vTicks = total_ticks;	VECTOR vecDist;		var fadeScale = my->scale_x;	vec_set(&vecDist, &my->x);	vec_sub(&vecDist, &player->x);	while (my->scale_x > 0)	{		wait(1);		//scale down item		my->scale_x -= 0.1 * time_step * fadeScale;		my->scale_y = my->scale_x;		my->scale_z = my->scale_x;		my->pan += (total_ticks - vTicks) * 10 * time_step;		//move item towards player		vec_set(&my->x, &vecDist);		vec_scale(&my->x, my->scale_x / fadeScale);		vec_add(&my->x, &player->x);	}	itemCounter--;	ptr_remove(me);}
开发者ID:Acknex,项目名称:Wichtelwald,代码行数:25,


示例15: vec_dot

double plane_t::hits(vec_t *base, vec_t* dir){	double ndotd;	double t;	double ndotb;	ndotq = vec_dot(&normal, &point);	ndotd = vec_dot(dir, &normal);	/* ndotd = 0 -> ray is parallel to the plane */	if (ndotd == 0)		return(-1);	ndotb = vec_dot(&normal, base);	t = (ndotq - ndotb) / ndotd;	if (t <= 0)		return(-1);	vec_scale(t, dir, &last_hitpt);	vec_sum(&last_hitpt, base, &last_hitpt);	if ((last_hitpt.z > 0.01) && (strcmp(obj_type, "projector")))		return(-1);	return(t);}
开发者ID:ryan-becwar,项目名称:raytracer,代码行数:28,


示例16: lightsource_fake_phong

voidlightsource_fake_phong (float *vertex, float *norm, const float *light_pos,			const float *light_up, const float *eye_pos,			matrix_t *invcamera, vertex_attrs *vertex_info,			unsigned int idx){  float norm_light[3];  float eye_to_vertex[3], tmp[3], reflection[3];  float light_to_vertex[3];  float eye_dot_norm;    vec_sub (light_to_vertex, light_pos, vertex);  vec_normalize (norm_light, light_to_vertex);    vec_sub (eye_to_vertex, eye_pos, vertex);  vec_normalize (eye_to_vertex, eye_to_vertex);    eye_dot_norm = vec_dot (eye_to_vertex, norm);  vec_scale (tmp, norm, 2.0 * eye_dot_norm);  vec_sub (reflection, tmp, eye_to_vertex);  if (eye_dot_norm < 0)    vertex_info[idx].fakephong.transformed_z = -0.01;  else    fakephong_texcoords (&vertex_info[idx].fakephong.texc[0],			 &vertex_info[idx].fakephong.texc[1],			 reflection, norm_light, light_up,			 &vertex_info[idx].fakephong.transformed_z);}
开发者ID:crtc-demos,项目名称:wobble,代码行数:29,


示例17: vec_scale

vec *ray_position(ray *r, double t){    vec *w = vec_scale(t, r->direction);    vec *result = vec_add(r->origin, w);    vec_free(w);    return result;}
开发者ID:Sun77789,项目名称:raytracer,代码行数:7,


示例18: vec_dot

double plane_t::hits(vec_t    *base,      /* ray base              */vec_t    *dir)       /* unit direction vector */{   double   ndotd;   double   t;   double   ndotb;   ndotq = vec_dot(&normal, &point);   ndotd = vec_dot(dir, &normal);/* ndotd = 0 -> ray is parallel to the plane */   if (ndotd == 0)       return(-1);   ndotb = vec_dot(&normal, base);   t = (ndotq - ndotb) / ndotd;   if (t <= 0)      return(-1);   vec_scale(t, dir, &hitloc);   vec_sum(&hitloc, base, &hitloc);   if (hitloc.z > 0.001)      return(-1);   return(t);}
开发者ID:kevinms,项目名称:cu-ray,代码行数:31,


示例19: vec_unit

/* Construct a unit vector v2 in direction of input vector v1 */void vec_unit(    vec_t *v1,    /* Input vector      */    vec_t *v2)    /* output unit vec   */{    double mult = 1 / vec_len(v1);    vec_scale(mult, v1, v2);}
开发者ID:ryan-becwar,项目名称:raytracer,代码行数:8,


示例20: vec_copy

void SMat<CoeffRing>::vec_column_op(sparsevec *&v, const elem &a, sparsevec *w) const    // v := v + a*w{  sparsevec *w1 = vec_copy(w);  vec_scale(w1, a);  vec_add_to(v, w1);}
开发者ID:ChristineJost,项目名称:M2,代码行数:7,


示例21: vec_normalize

vec_t vec_normalize(vec_t a){	if (vec_zero(a)){		return a;	}else{		return vec_scale(a,1.0/vec_len(a));	}}
开发者ID:brownman,项目名称:bastos85,代码行数:7,


示例22: qrdec

//Brief: QR decomposition void qrdec(mat *A, mat* R){    double proj = 0;    double norm = 0;        // Allocates pointers of type *vec     //vec *coli = (vec*)malloc(sizeof(vec));    //vec *colj = (vec*)malloc(sizeof(vec));    vec* coli = vec_new(A->row);    vec* colj = vec_new(A->row);    for(int i=0; i<A->col; i++){	mat_get_col(coli, A, i);		norm = vec_norm(coli);	mat_set(R, i, i, norm);	vec_scale(coli, 1.0/norm);	mat_set_col(A, coli, i);	for(int j=i+1; j<A->col; j++){	    mat_get_col(colj, A, j);	    proj = vec_dot(coli,colj);	    vec_add(colj,coli,-proj);	    mat_set_col(A, colj, j);	    mat_set(R, i, j, proj);	}	    }    // Free pointers    vec_free(coli);    vec_free(colj);}
开发者ID:yangmw,项目名称:fedorov,代码行数:29,


示例23: compute_means

/* Function compute_means. * This function recomputes the means based on the current clustering * of the points. * * Inputs: *   n          : number of input descriptors *   dim        : dimension of each input descriptor *   k          : number of means *   v          : array of pointers to dim-dimensional descriptors *   clustering : current assignment of descriptors to means (should *                range between 0 and k-1) * * Output: *   means_out  : array of output means.  You need to fill this *                array.  The means should be concatenated into one *                long array of length k*dim. */double compute_means(int n, int dim, int k, unsigned char **v,                     unsigned int *clustering, double *means_out){    int i;    double max_change = 0.0;    int *counts = (int *) malloc(sizeof(int) * k);    for (i = 0; i < k * dim; i++)        means_out[i] = 0.0;    for (i = 0; i < k; i++)        counts[i] = 0;    for (i = 0; i < n; i++) {        unsigned int cluster = clustering[i];        vec_accum(dim, means_out + cluster * dim, v[i]);        counts[cluster]++;    }    /* Normalize new means */    for (i = 0; i < k; i++) {        if (counts[i] == 0) {            continue;        }        vec_scale(dim, means_out + i * dim, 1.0 / counts[i]);    }    free(counts);    return max_change;}
开发者ID:josame,项目名称:VocabTree2,代码行数:50,


示例24: vec_norm

vec_t vec_norm(vec_t a){	float len = vec_len(a);	if(len == 0.0f){		return vec_new(1.0f,0.0f,0.0f,0.0f);	}else{		return vec_scale(1.0f/len,a);	}}
开发者ID:fvdsn,项目名称:gally,代码行数:8,


示例25: ga_shade_diffuse

/* diffuse shading */static void ga_shade_diffuse(vec_t *color, const ga_material_t *mat,const vec_t *lcolor, const vec_t *ldir, const vec_t *norm, float factor){	float fact = vec_dot(*norm,*ldir);	if(fact > 0.0f){		*color = vec_add(*color,			vec_scale(fact*factor*mat->diff_factor				,vec_mult(mat->diff_color,*lcolor)));	}}
开发者ID:fvdsn,项目名称:gally,代码行数:9,


示例26: vec_project

//project a vector onto a planevoid vec_project(vec_t *n, vec_t *v, vec_t *p) {    vec_t *r = (vec_t *)malloc(sizeof(vec_t));    vec_scale(vec_dot(n, v), n, r);    vec_diff(r, v, p);    free(r);}
开发者ID:ryan-becwar,项目名称:raytracer,代码行数:9,


示例27: getRefractedRay

Vector getRefractedRay(float initial_refraction, Spheres *sph, Vector surface_norm, Vector light_ray){	float refraction_index = sph->refraction_index;	float n = initial_refraction/refraction_index;	Vector refract_ray;	//n = .9;	//light_ray.x = 0.707107;	//light_ray.y = -0.707107;	//light_ray.z = 0;	//surface_norm.x = 0;	//surface_norm.y = 1;	//surface_norm.z = 0;	float cosTheta1 = vec_dot(surface_norm, vec_scale(light_ray,-1));	float cosTheta2 = sqrt(1.0f-pow(n,2)*(1-(cosTheta1*cosTheta1)));		Vector a = vec_scale(light_ray, n);	Vector b = vec_scale(surface_norm, n*cosTheta1 - cosTheta2);	if(cosTheta1 > 0.0f)	{		refract_ray = vec_plus(vec_scale(light_ray,n), vec_scale(surface_norm, n*cosTheta1-cosTheta2));	}	else	{		refract_ray = vec_minus(vec_scale(light_ray,n), vec_scale(surface_norm, n*cosTheta1-cosTheta2));	}	return refract_ray;}
开发者ID:hodannyy,项目名称:ray-tracer,代码行数:30,


示例28: createPhysicsComponent

static gameComponentT* createPhysicsComponent(void) {    gameComponentT* component = newPhysicsComponent(1.0f * Kilogram);        physicsComponentDataT* phys = component->data;        vec2 pos;    vec2 vel;        switch (rand() % 4) {            case 0: {        // Spawn above screen.        pos = (vec2) { -0.5f + 1.0f * rand()/(float)RAND_MAX, 0.6f };        vel = (vec2) { -1.0f + 2.0f * rand()/(float)RAND_MAX,                       -0.2f - 1.0f * rand()/(float)RAND_MAX };        break;    };    case 1: {        // Spawn to the right of screen.        pos = (vec2) {  1.0f, -0.5f + 1.0f * rand()/(float)RAND_MAX };        vel = (vec2) { -0.2f - 1.0f * rand() / (float)RAND_MAX,                       -1.0f + 2.0f * rand() / (float)RAND_MAX };        break;    };    case 2: {        // Spawn below screen.        pos = (vec2) { -0.5f + 1.0f * rand()/(float)RAND_MAX, -0.6f };        vel = (vec2) { -1.0f + 2.0f * rand()/(float)RAND_MAX,                        0.2f + 1.0f * rand()/(float)RAND_MAX };        break;    };    case 3: {        // Spawn to the left of screen.        pos = (vec2) { -1.0f, -0.5f + 1.0f * rand()/(float)RAND_MAX };        vel = (vec2) {  0.2f + 1.0f * rand() / (float)RAND_MAX,                       -1.0f + 2.0f * rand() / (float)RAND_MAX };        break;    };    }    vec_scale(&pos, 6.0f, &pos);    //bodySetOrientation(((physicsComponentDataT*)phys)->body, 17 * 3.141592f / 180.0f);    //pos.x = -1.0f;    //pos.y = 0.0f;    //vel.x = -1.0f;    //vel.y = 0.0f;    bodySetPosition(((physicsComponentDataT*)phys)->body, pos);    //vec_scale(&vel, 0.1f, &vel);    bodySetVelocity(((physicsComponentDataT*)phys)->body, vel);        return (component);}
开发者ID:philiparvidsson,项目名称:sa14-game1,代码行数:57,


示例29: vec_homog

vec_t vec_homog(vec_t a){	if(a.w == 0.0f){		return a;	}else{		a = vec_scale(1.0/a.w,a);		a.w = 1.0;		return a;	}}
开发者ID:fvdsn,项目名称:gally,代码行数:9,


示例30: vec_vec

vec_t vec_vec(vec_t a){	if (a.w == 0.0f){		return a;	}else{		a = vec_scale(1.0f/a.w,a);		a.w = 0.0f;		return a;	}}
开发者ID:fvdsn,项目名称:gally,代码行数:9,



注:本文中的vec_scale函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ vec_set函数代码示例
C++ vec_safe_push函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。