コード例 #1
0
ファイル: vectorUtil.c プロジェクト: cesarvr/OpenGLCurso
void vec3Normalize(float* vec, const float* src)
{
	float length = vec3Length(src);
	
	vec[0] = src[0]/length;
	vec[1] = src[1]/length;
	vec[2] = src[2]/length;
}
コード例 #2
0
ファイル: vector.c プロジェクト: BackupTheBerlios/gltron-svn
vec3* vec3Normalize(vec3 *pOut, const vec3 *pV) {
  float fLength = vec3Length(pV);
  if(fLength != 0) {
    pOut->v[0] = pV->v[0] / fLength;
    pOut->v[1] = pV->v[1] / fLength;
    pOut->v[2] = pV->v[2] / fLength;
  }
  return pOut;
}
コード例 #3
0
ファイル: es2util.cpp プロジェクト: gamecip/em-fceux
double vec3Normalize(GLfloat *c, const GLfloat *a)
{
    double d = vec3Length(a);
    if (d > 0) {
        vec3DivScalar(c, a, d);
    } else {
        c[0] = c[1] = c[2] = 0;
    }
    return d;
}
コード例 #4
0
ファイル: matrix.c プロジェクト: MarkKerner/RotatingBox
vec3* vec3Normalize(vec3* pOut, vec3* pIn) {
    if (!pIn->x && !pIn->y && !pIn->z)
        avec3_assign(pOut, pIn);

    float l = 1.0f / vec3Length(pIn);

    vec3 v;
    v.x = pIn->x * l;
    v.y = pIn->y * l;
    v.z = pIn->z * l;

    pOut->x = v.x;
    pOut->y = v.y;
    pOut->z = v.z;

    return pOut;
}
コード例 #5
0
void drawGlow(Camera *pCam, Player *pTarget, PlayerVisual *pV,
							Visual *d, float dim) {
  float mat[4*4];
  float alpha, dist;
	float x, y;

  glPushMatrix();
	
	getPositionFromData(&x, &y, pTarget->data);
  glTranslatef(x, y, 0);

  glDepthMask(GL_FALSE);
  glEnable(GL_DEPTH_TEST);

  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  glEnable(GL_BLEND);

  glGetFloatv(GL_MODELVIEW_MATRIX, mat);
  mat[0] = mat[5] = mat[10] = 1.0;
  mat[1] = mat[2] = 0.0;
  mat[4] = mat[6] = 0.0;
  mat[8] = mat[9] = 0.0;
  glLoadMatrixf(mat);

	{
		vec3 v;
		v.v[0] = x - pCam->cam[0];
		v.v[1] = y - pCam->cam[1];
		v.v[2] = 0 - pCam->cam[2];
		dist = vec3Length(&v);
	}
	{
	  const float fMin = 30;
		const float fMax = 100;
		if(dist < fMin) alpha = 0.0f;
		else if(dist > fMax) alpha = 1.0f;
		else alpha = (dist - fMin) / (fMax - fMin);
		// printf("dist: %.2f, alpha: %.2f\n", dist, alpha);
	}
  glBegin(GL_TRIANGLE_FAN);
  glColor4f(pV->pColorDiffuse[0], 
						pV->pColorDiffuse[1], 
						pV->pColorDiffuse[2],
						alpha);

  glVertex3f(0,TRAIL_HEIGHT/2, 0);
  glColor4f(0,0,0,0.0);
  glVertex3d(dim*cos(-0.2*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(-0.2*3.1415/5.0), 0);
  glVertex3d(dim*cos(1.0*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(1.0*3.1415/5.0), 0);
  glVertex3d(dim*cos(2.0*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(2.0*3.1415/5.0), 0);
  glVertex3d(dim*cos(3.0*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(3.0*3.1415/5.0), 0);
  glVertex3d(dim*cos(4.0*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(4.0*3.1415/5.0), 0);
  glVertex3d(dim*cos(5.2*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(5.2*3.1415/5.0), 0);
  glEnd();
  polycount += 5;


  glBegin(GL_TRIANGLES);
  glColor4f(pV->pColorDiffuse[0], 
						pV->pColorDiffuse[1], 
						pV->pColorDiffuse[2],
						alpha);
  glVertex3f(0,TRAIL_HEIGHT/2, 0);
  glColor4f(0,0,0,0.0);
  glVertex3f(0,-TRAIL_HEIGHT/4,0);
  glVertex3d(dim*cos(-0.2f*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(-0.2*3.1415/5.0), 0);

  glColor4f(pV->pColorDiffuse[0], 
						pV->pColorDiffuse[1], 
						pV->pColorDiffuse[2],
						alpha);
  glVertex3f(0,TRAIL_HEIGHT/2, 0);
  glColor4f(0,0,0,0.0);
  glVertex3d(dim*cos(5.2*3.1415/5.0),
	     TRAIL_HEIGHT/2+dim*sin(5.2*3.1415/5.0), 0);
  glVertex3f(0,-TRAIL_HEIGHT/4,0);
  glEnd();
  polycount += 3;

  glDepthMask(GL_TRUE);
  glEnable(GL_DEPTH_TEST);

  glPopMatrix();  
}