Exemple #1
0
v3d_t LightSource::computeDirectionalLightIntensity (v3d_t normalVector, bool isTheSun) {
  double intensityScalar = v3d_dot (mDirection, normalVector);

  if (intensityScalar < 0.0) {
    intensityScalar = 0.0;
  }

  double overheadIntensity = v3d_dot (mDirection, v3d_v (0.0, 1.0, 0.0));

  if (overheadIntensity < 0.0) {
    intensityScalar += (overheadIntensity * 4.0);
  }
  else {
    intensityScalar += overheadIntensity;
  }

//  if (intensityScalar > 0.0 && intensityScalar < 0.5) {
//    intensityScalar = 0.5;
//  }


//  intensityScalar += (overheadIntensity + 0.3) * 0.5;

//  if (intensityScalar < 0.6) {
//    intensityScalar = 0.6;
//  }

/*
  if (isTheSun) {
    intensityScalar *= 0.2;
  }
  else {
    if (intensityScalar > 0.5) {
      intensityScalar = 0.5;
    }
  }
*/

  if (intensityScalar < 0.0) {
    intensityScalar = 0.0;
  }
  if (intensityScalar > 1.0) {
    intensityScalar = 1.0;
  }

  v3d_t color = v3d_scale (intensityScalar, mColor);

  return color;
}
Exemple #2
0
static gboolean isCoplanar(GList* ring, gdouble epsilon) /* epsilon on degre */
{
	GList*l = NULL;
	V3d normal = {0,0,0};
	V3d v = {0,0,0};
	V3d v1 = {0,0,0};
	V3d v2 = {0,0,0};
	V3d p[] = {{0,0,0}, {0,0,0}, {0,0,0} };
	gint  i;
	gint  j;
	gint  k;
	gdouble tol = 0.1;

	tol = cos((90-epsilon)/180.0*PI);

	for(l=ring, j=0; j<3 ; l = l->next, j++)
	{
		if(!l) return TRUE;
		i = GPOINTER_TO_INT(l->data);
		for(k=0;k<3;k++) p[j][k] = GeomOrb[i].C[k];
	}
	for(k=0;k<3;k++) v1[k] = p[1][k] - p[0][k];
	for(k=0;k<3;k++) v2[k] = p[2][k] - p[0][k];
	v3d_cross(v1,v2, normal);
	v3d_normal(normal);
	for( ; l != NULL ; l = l->next)
	{
		i = GPOINTER_TO_INT(l->data);
		for(k=0;k<3;k++) v[k] = GeomOrb[i].C[k]-p[0][k];
		v3d_normal(v);
		if(fabs(v3d_dot(normal, v))>tol) return FALSE;

	}
	return TRUE;
}
Exemple #3
0
void SkySim::setSkyColorAndWorldLighting(void) {
  mStarAlpha = static_cast<GLfloat>(v3d_dot (v3d_normalize (mCurrentSunPosition), v3d_v (0.0, -1.0, 0.0)));
  mStarAlpha *= 1.5;
  if (mStarAlpha > 1.0) {
    mStarAlpha = 1.0;
  }
  else if (mStarAlpha < -1.0) {
    mStarAlpha = -1.0;
  }

//  mWorldLightingFloor = 0.4; //0.40 - (mStarAlpha * 0.20);
//  defaultLightingCeiling = 0.9; //0.65 - (mStarAlpha * 0.20);

//  printf ("starAlpha: %3.5f\n", starAlpha);
//  printf ("f: %3.5f   c: %3.5f\n", mWorldLightingFloor, defaultLightingCeiling);

  GLfloat currentSkyColor[4] = {
    mSkyColor[0] * (1.0f - max(0.0f, mStarAlpha)),
    mSkyColor[1] * (1.0f - max(0.0f, mStarAlpha)),
    mSkyColor[2] * (1.0f - max(0.0f, mStarAlpha)),
    1.0f };

  glClearColor(
    currentSkyColor[0],
    currentSkyColor[1],
    currentSkyColor[2],
    currentSkyColor[3]);

  glFogfv(GL_FOG_COLOR, currentSkyColor);
}
Exemple #4
0
static void rotatedVector(V3d v)
{
	V3d vz={0.0,0.0,1.0};
	V3d	vert;
	gdouble angle;


	v3d_cross(vz,v,vert);
	angle = acos(v3d_dot(vz,v)/v3d_length(v))*Deg_Rad;
	  
	if(fabs(angle)<1e-6)
		return;
	if(fabs(angle-180)<1e-6)
		glRotated(angle, 1.0, 0.0, 0.0);
	else
	glRotated(angle, vert[0],vert[1],vert[2]);

}
Exemple #5
0
static void draw_bond_for_stick(int i,int j,GLdouble g, GabEditBondType bondType)
{
	
	int k;
	V4d Specular1 = {1.0f,1.0f,1.0f,1.0f};
	V4d Diffuse1  = {0.0f,0.0f,0.0f,1.0f};
	V4d Ambiant1  = {0.0f,0.0f,0.0f,1.0f};
	V4d Specular2 = {1.0f,1.0f,1.0f,1.0f};
	V4d Diffuse2  = {0.0f,0.0f,0.0f,1.0f};
	V4d Ambiant2  = {0.0f,0.0f,0.0f,1.0f};
	GLdouble p1;
	GLdouble p2;
	GLdouble aspect = g;
	
	  
	Specular1[0] = GeomOrb[i].Prop.color.red/(gdouble)65535;
	Specular1[1] = GeomOrb[i].Prop.color.green/(gdouble)65535;
	Specular1[2] = GeomOrb[i].Prop.color.blue/(gdouble)65535;

	Specular2[0] = GeomOrb[j].Prop.color.red/(gdouble)65535;
	Specular2[1] = GeomOrb[j].Prop.color.green/(gdouble)65535;
	Specular2[2] = GeomOrb[j].Prop.color.blue/(gdouble)65535;

	for(k=0;k<3;k++)
	{
		Diffuse1[k] = Specular1[k]*0.8;
		Diffuse2[k] = Specular2[k]*0.8;
	}
	for(k=0;k<3;k++)
	{
		Ambiant1[k] = Specular1[k]*0.5;
		Ambiant2[k] = Specular2[k]*0.5;
	}
	for(k=0;k<3;k++)
	{
		Ambiant1[k] = 0;
		Ambiant2[k] = 0;
	}
	for(k=0;k<3;k++)
	{
		Specular1[k] = 0.8;
		Specular2[k] = 0.8;
	}
	p1 = GeomOrb[i].Prop.covalentRadii+GeomOrb[i].Prop.radii;
	p2 = GeomOrb[j].Prop.covalentRadii+GeomOrb[j].Prop.radii;

	Cylinder_Draw_Color_Two(g,GeomOrb[i].C,GeomOrb[j].C,
				Specular1,Diffuse1,Ambiant1,
				Specular2,Diffuse2,Ambiant2,
				p1,p2);

	if(      bondType == GABEDIT_BONDTYPE_SINGLE ||
		( !ShowMultiBondsOrb && 
		 (bondType == GABEDIT_BONDTYPE_DOUBLE || bondType == GABEDIT_BONDTYPE_TRIPLE)
		 )
	    )
		Cylinder_Draw_Color_Two(g,GeomOrb[i].C,GeomOrb[j].C,
				Specular1,Diffuse1,Ambiant1,
				Specular2,Diffuse2,Ambiant2,
				p1,p2);
	else
	if(bondType == GABEDIT_BONDTYPE_DOUBLE && ShowMultiBondsOrb)
	{
	  	V3d vScal = {g/aspect*0.35,g/aspect*0.35,g/aspect*0.35};
		V3d C1;
		V3d C2;
		V3d cross;
		V3d sub;
		V3d CRing;
		getCentreRing(i,j, CRing);
		v3d_sub(CRing, GeomOrb[i].C, C1);
		v3d_sub(CRing, GeomOrb[j].C, C2);
		v3d_cross(C1, C2, cross);
		v3d_sub(GeomOrb[i].C, GeomOrb[j].C, sub);
		v3d_cross(cross, sub, vScal);
		if(v3d_dot(vScal,vScal)!=0)
		{
			v3d_normal(vScal);
			v3d_scale(vScal, g/aspect*0.35);
		}
		else
			 getvScaleBond(g/aspect*0.35*2, C1,C2, vScal);

		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k];
		Cylinder_Draw_Color_Two(g,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]-vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]-vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
	}
	else
	if(bondType == GABEDIT_BONDTYPE_TRIPLE && ShowMultiBondsOrb)
	{
	  	V3d vScal = {g/aspect*0.35,g/aspect*0.35,g/aspect*0.35};
		V3d C1;
		V3d C2;
		V3d cross;
		V3d sub;
		V3d CRing;
		getCentreRing(i,j, CRing);
		v3d_sub(CRing, GeomOrb[i].C, C1);
		v3d_sub(CRing, GeomOrb[j].C, C2);
		v3d_cross(C1, C2, cross);
		v3d_sub(GeomOrb[i].C, GeomOrb[j].C, sub);
		v3d_cross(cross, sub, vScal);
		if(v3d_dot(vScal,vScal)!=0)
		{
			v3d_normal(vScal);
			v3d_scale(vScal, g/aspect*0.35);
		}
		else
			 getvScaleBond(g/aspect*0.35*2, C1,C2, vScal);

		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]-vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]-vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k];
		Cylinder_Draw_Color_Two(g,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
		for(k=0;k<3;k++) C1[k] = GeomOrb[i].C[k]+vScal[k];
		for(k=0;k<3;k++) C2[k] = GeomOrb[j].C[k]+vScal[k];
		Cylinder_Draw_Color_Two(g/2,C1,C2, Specular1,Diffuse1,Ambiant1, Specular2,Diffuse2,Ambiant2, p1,p2);
	}

}