void OBJECT::CalculateNormals()
{
	int x;
	for (x=0; x<VertexNum; x++)	VertexList[x].Normal=V3_Make(0,0,0);
	for (x=0; x<PolygonNum; x++)
	{
		PolygonList[x].Normal=//V3_Normalize(
							  V3_Cross(V3_Sub(VertexList[PolygonList[x].v[2]].MapTransformedPosition,VertexList[PolygonList[x].v[0]].MapTransformedPosition),
									   V3_Sub(VertexList[PolygonList[x].v[1]].MapTransformedPosition,VertexList[PolygonList[x].v[0]].MapTransformedPosition))
							;	//	 );

		if (NormalsInverted) PolygonList[x].Normal=V3_Mults(PolygonList[x].Normal,-1);
			
		VertexList[PolygonList[x].v[0]].Normal=V3_Add(VertexList[PolygonList[x].v[0]].Normal,PolygonList[x].Normal);
		VertexList[PolygonList[x].v[1]].Normal=V3_Add(VertexList[PolygonList[x].v[1]].Normal,PolygonList[x].Normal);
		VertexList[PolygonList[x].v[2]].Normal=V3_Add(VertexList[PolygonList[x].v[2]].Normal,PolygonList[x].Normal);
		//M_Xform3(IT,PolygonList[x].Normal,PolygonList[x].CurrentNormal);
		PolygonList[x].CurrentNormal=V3_Normalize(PolygonList[x].Normal);
	}

	for (x=0; x<VertexNum; x++)	
	{
		VertexList[x].CurrentNormal=V3_Normalize(VertexList[x].Normal);
		//M_Xform3(IT,VertexList[x].CurrentNormal,VertexList[x].CurrentNormal);
	}

}
예제 #2
0
void SetCameraView(CAMERA *Cam, float AspectRatio)
{
	//kamerabeallitas :)

	MATRIX m;
	VECTOR3 u,dir;

	dir=V3_Normalize(V3_Sub(Cam->Target,Cam->Eye));
	M_Rotate(dir.x,dir.y,dir.z,(float)Cam->Roll*360.0f/255.0f*(float)radtheta,m);
	M_Xformd(m,Cam->Up,u); //itt keszul a rotated up vector (a rollhoz)

	Cam->i=V3_Normalize(V3_Cross(dir,u));
	Cam->j=V3_Normalize(V3_Cross(dir,Cam->i)); //kamera sikjaban egysegvektorok (billboardinghoz)

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(Cam->Fov,AspectRatio,0.1,2000.0);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	gluLookAt(Cam->Eye.x,Cam->Eye.y,Cam->Eye.z,
			  Cam->Target.x,Cam->Target.y,Cam->Target.z,
			  u.x,u.y,u.z);

}
예제 #3
0
/*===========================================*/
int VF_BackFaceCullPolys(Poly *poly_i, Poly *poly_j)
{
  int    n, m;
  double tmp;
  Vector *normal_i, *normal_j, r;

  normal_i = &(poly_i->normal);
  normal_j = &(poly_j->normal);
  for (m=0; m<poly_i->np; m++) {
    for (n=0; n<poly_j->np; n++) {
      V3_Sub(&(poly_j->p[n]), &(poly_i->p[m]), &r);
      V3_Normalize(&r,tmp);
      if ((V3_Dot(&r, normal_i)>0.0) && (-V3_Dot(&r, normal_j)>0.0)) return 0;
    }
  }
  return 1;
}
void GeneratePrimitive(OBJECT *Object)
{
	int x,y;
	int x1,x2,y1,y2;
	VECTOR3 v;
#ifdef INCLUDE_OBJ_STORED
	if (Object->Primitive!=aDDict_STORED)
	{
		Object->VertexNum=0;
		Object->PolygonNum=0;
	}
#else
	Object->VertexNum=0;
	Object->PolygonNum=0;
#endif
	//M_Identity(Object->ModelView);
	//Object->Primitive=PrimitiveID;
	switch (Object->Primitive)
	{
#ifdef INCLUDE_OBJ_BOX
	case aDDict_BOX:
		{
			for (int x=0; x<14; x++) Object->AddVertex(BoxVertexData[x*5]/10.0f,BoxVertexData[x*5+1]/10.0f,BoxVertexData[x*5+2]/10.0f,BoxVertexData[x*5+3]/10.0f,BoxVertexData[x*5+4]/10.0f);
			for (int x=0; x<24; x++) Object->AddPolygon(BoxPolyData[x*7],BoxPolyData[x*7+1],BoxPolyData[x*7+2],BoxPolyData[x*7+3],BoxPolyData[x*7+4],BoxPolyData[x*7+5],BoxPolyData[x*7+6],0.5f,0.5f,1,0,0);
		}
		break;
#endif
#ifdef INCLUDE_OBJ_SPHERE
	case aDDict_SPHERE:

		Object->AddVertex(0,-0.5,0,0.5,0);
		Object->AddVertex(0,0.5,0,0.5,0);
		float theta,phi;
		for (x=1; x<Object->Param1-1; x++)
		{
			theta=(float)((x/(float)(Object->Param1-1)*180-90)*radtheta);
			for (int y=0; y<Object->Param2; y++)
			{
				phi=y/(float)Object->Param2*360.0f*(float)radtheta;
				v.x=(float)cos(theta)*(float)cos(phi)*0.5f;
				v.y=(float)cos(theta)*(float)sin(phi)*0.5f;
				v.z=(float)sin(theta)*0.5f;
				Object->AddVertex(v.x,v.z,-v.y,x/(float)Object->Param1,y/(float)Object->Param2);
			}
		}

		for (x=0; x<Object->Param1-1; x++)
		{
			x1=(x-1)*Object->Param2;
			x2=x*Object->Param2;
			for (int y=0; y<Object->Param2; y++)
			{
				y1=y+2;
				y2=(y+1)%Object->Param2+2;
				if (x>0 && x<Object->Param1-2)
				{
					Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,(x+1)/(float)(Object->Param1),y/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,0,1);
					Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,x/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,1,1);
				}
				else
				if (x==0) Object->AddPolygon(y2,0,y1,aDDict_GOURAUDSHADE,(1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,(y+1)/(float)Object->Param2,(1)/(float)(Object->Param1),(y)/(float)Object->Param2,1,1,1);
				else Object->AddPolygon(x1+y1,1,x1+y2,aDDict_GOURAUDSHADE,(x)/(float)(Object->Param1),(y)/(float)Object->Param2,1,(y+1)/(float)Object->Param2,(x)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,1,1);
			}
		}

		break;
#endif
#ifdef INCLUDE_OBJ_CYLINDER
	case aDDict_CYLINDER:
		Object->AddVertex(0,-0.5,0,0.5,0.5);
		Object->AddVertex(0,0.5,0,0.5,0.5);
		for (y=0; y<Object->Param2+1; y++)
		{
			for (x=0; x<Object->Param1; x++)
			{
				float theta=(float)((x/(float)Object->Param1*360.0f)*radtheta);
				v.x=(float)cos(theta)*0.5f;
				v.y=(float)sin(theta)*0.5f;
				v.z=-0.5f+y/(float)Object->Param2;
				Object->AddVertex(v.x,v.z,-v.y,x/(float)Object->Param1,v.z+0.5f);
			}
		}

		for (x=0; x<Object->Param1; x++)
		{
			x1=x;
			x2=(x+1)%Object->Param1;
			if (Object->Param3)
			{
				Object->AddPolygon(0,x1+2,x2+2,0.5f,0.5f,(float)sin(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)sin((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,1,1,1);
				Object->AddPolygon(x1+Object->Param1*Object->Param2+2,1,x2+Object->Param1*Object->Param2+2,(float)sin(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos(x/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,0.5f,0.5f,(float)sin((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,(float)cos((x+1)/(float)(Object->Param1)*360*radtheta)*0.5f+0.5f,1,1,1);
			}
			for (int y=0; y<Object->Param2; y++)
			{
				y1=y*Object->Param1+2;
				y2=(y+1)*Object->Param1+2;
				Object->AddPolygon(x2+y1,x1+y1,x2+y2,aDDict_GOURAUDSHADE,(x+1)/(float)(Object->Param1),y/(float)Object->Param2,x/(float)(Object->Param1),y/(float)Object->Param2,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,1,1,0);
				Object->AddPolygon(x2+y2,x1+y1,x1+y2,aDDict_GOURAUDSHADE,(x+1)/(float)(Object->Param1),(y+1)/(float)Object->Param2,x/(float)(Object->Param1),y/(float)Object->Param2,x/(float)(Object->Param1),(y+1)/(float)Object->Param2,0,1,1);
			}
		}


		break;
#endif
#ifdef INCLUDE_OBJ_CONE
	case aDDict_CONE:
		Object->AddVertex(0,0.5,0,0.5,0.5);
		Object->AddVertex(0,-0.5,0,0.5,0.5);

		for (y=1; y<=Object->Param3; y++)
		{
			for (x=0; x<Object->Param1; x++)
			{
				float theta=(float)((x/(float)Object->Param1*360.0f)*radtheta);
				v.x=(float)cos(theta)*0.5f*y/(float)Object->Param3;
				v.y=(float)sin(theta)*0.5f*y/(float)Object->Param3;
				v.z=-(-0.5f+y/(float)Object->Param3);
				Object->AddVertex(v.x,v.z,-v.y,v.x+0.5f,v.y+0.5f);
			}
		}

		for (x=0; x<Object->Param1; x++)
		{
			x1=x;
			x2=(x+1)%Object->Param1;

			Object->AddPolygon(x1+2,0,x2+2,aDDict_GOURAUDSHADE,1,1,1);
			
			if (Object->Param2)
				Object->AddPolygon(1,x1+Object->Param1*(Object->Param3-1)+2,x2+Object->Param1*(Object->Param3-1)+2,1,1,1);

			for (int y=0; y<Object->Param3-1; y++)
			{
				y1=y*Object->Param1+2;
				y2=(y+1)*Object->Param1+2;
				Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_GOURAUDSHADE,1,0,1);
				Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_GOURAUDSHADE,0,1,1);
			}
		}
		
		break;
#endif
#ifdef INCLUDE_OBJ_PLANE
	case aDDict_PLANE:
		for (x=0; x<=Object->Param1; x++)
			for (y=0; y<=Object->Param2; y++)
				Object->AddVertex(x/(float)Object->Param1-0.5f,0,y/(float)Object->Param2-0.5f,x/(float)Object->Param1,y/(float)Object->Param2);
		for (x=0; x<Object->Param1; x++)
		{
			x1=x*(Object->Param2+1);
			x2=(x+1)*(Object->Param2+1);
			for (int y=0; y<Object->Param2; y++)
			{
				y1=y;
				y2=(y+1)%(Object->Param2+1);
				Object->AddPolygon(x1+y1,x2+y1,x2+y2,1,0,1);
				Object->AddPolygon(x1+y1,x2+y2,x1+y2,0,1,1);
			}
		}
		break;
#endif
#ifdef INCLUDE_OBJ_CIRCLE
	case aDDict_CIRCLE:
		for (x=0; x<Object->Param1; x++)
		{
				theta=(float)((x/(float)Object->Param1*360.0f)*radtheta);
				v.x=(float)cos(theta);
				v.y=(float)sin(theta);
				v.z=0;
				float p=Object->Param2/255.0f*0.5f;
				Object->AddVertex(v.x*0.5f,v.z,-v.y*0.5f,x/(float)Object->Param1,0);
				Object->AddVertex(v.x*p,v.z,-v.y*p,x/(float)Object->Param1,1);
		}
		for (x=0; x<Object->Param1; x++)
		{
			x1=(x)%Object->Param1*2;
			x2=(x+1)%Object->Param1*2;
			y1=0;
			y2=1;
			Object->AddPolygon(x1+y1,x2+y1,x2+y2,aDDict_FLATSHADE,x/(float)Object->Param1,0,(x+1)/(float)Object->Param1,0,(x+1)/(float)Object->Param1,1,1,0,1);
			Object->AddPolygon(x1+y1,x2+y2,x1+y2,aDDict_FLATSHADE,x/(float)Object->Param1,0,(x+1)/(float)Object->Param1,1,x/(float)Object->Param1,1,0,1,1);
		}
		break;
#endif
#ifdef INCLUDE_OBJ_LINE
	case aDDict_LINE:
		for (x=-1; x<=Object->Param1; x++)
		{
			Object->AddVertex(0,0,-0.5f+x/(float)(Object->Param1-1),0,0);
			/*if (x>0 && x<Object->Param1) 
				Object->AddEdge(x,x+1,-1);*/
		}
		break;
#endif
#ifdef INCLUDE_OBJ_ARC
	case aDDict_ARC:
		for (x=-1; x<=Object->Param1; x++)
		{
			float phase=x/(float)(Object->Param1-1)*(float)Object->Param2*radtheta;
			
			Object->AddVertex((float)(0.5f*cos(phase)),0,(float)(0.5f*sin(phase)),0,0);
			/*if (x>0 && x<Object->Param1) 
				Object->AddEdge(x,x+1,-1);*/
		}
		break;
#endif
#ifdef INCLUDE_OBJ_LOFT
	case aDDict_LOFT: 
		{
		VECTOR3 Up=V3_Make(0,1,0);

		Object->Backface=false;
		OBJECT *v1,*v2;
		v1=(OBJECT*)Object->Param1;
		v2=(OBJECT*)Object->Param2;

		if (v1 && v2)
		{
			bool xc=v1->Param2==360,
				 yc=v2->Param2==360;

			int v1v=v1->VertexNum-2;
			int v2v=v2->VertexNum-2;

			if (xc) v1v--;
			if (yc) v2v--;

			int xx=0;
			if ((v1->VertexNum>1) && (v2->VertexNum>1))
			{
				int xa,ya;

				for (xa=1;xa<=v1v;xa++)
				{
					VECTOR3 va,vb,vc;
					va=v1->VertexList[xa-1].Position;
					vb=v1->VertexList[xa].Position;
					vc=v1->VertexList[xa+1].Position;
					M_Xformd(v1->ModelView,va,va);
					M_Xformd(v1->ModelView,vb,vb);
					M_Xformd(v1->ModelView,vc,vc);

					VECTOR3 a1=V3_Normalize(V3_Sub(vb,va));
					VECTOR3 a2=V3_Normalize(V3_Sub(vc,va));
					VECTOR3 dir=V3_Normalize(V3_Add(a1,a2));

					VECTOR3 nx=V3_Cross(Up,dir);
					VECTOR3 ny=V3_Cross(nx,dir);

					int yy=0;
					for (ya=1;ya<=v2v;ya++)
					{
						VECTOR3 yv=v2->VertexList[ya].Position;
						M_Xformd(v2->ModelView,yv,yv);

						VECTOR3 nv=V3_Add(V3_Mults(nx,yv.x),V3_Mults(ny,yv.z));

						nv=V3_Add(nv,vb);

						Object->AddVertex(nv.x,nv.y,nv.z,xx/(float)(v1v-1),yy/(float)(v2v-1));

						yy++;
					}

					xx++;
				}

				if (xc) v1v++;
				if (yc) v2v++;

				for (xx=0;xx<=v2v-2;xx++)
					for (int yy=0;yy<=v1v-2;yy++)
					{
						int xa=xx, ya=yy;
						int x1=xx+1,y1=yy+1;
						int v2vs=v2v;

						if (yc)
						{
							v2vs--;
							xa%=v2v-1;
							x1%=v2v-1;
						}
						if (xc)
						{
							ya%=v1v-1;
							y1%=v1v-1;
						}

						Object->AddPolygon(ya*v2vs+xa,ya*v2vs+x1,y1*v2vs+x1,aDDict_GOURAUDSHADE,xx/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),(yy+1)/((float)v1v-1),1,0,1);
						Object->AddPolygon(ya*v2vs+xa,y1*v2vs+x1,y1*v2vs+xa,aDDict_GOURAUDSHADE,xx/((float)v2v-1),yy/((float)v1v-1),(xx+1)/((float)v2v-1),(yy+1)/((float)v1v-1),xx/((float)v2v-1),(yy+1)/((float)v1v-1),0,1,1);
					}


			}
		}
		}
		break;
#endif
#ifdef INCLUDE_OBJ_FUR
	case aDDict_FUR:
		{
			srand(115); //9,26,30,35,39,46,62,75,79,115,116,126
						//135 volt az utolso
			OBJECT *Host=(OBJECT*)Object->Param5;
			for (int x=0; x<Host->PolygonNum; x++)
			{
				VECTOR3 Ha,Hb,Hc;
				Ha=Host->VertexList[Host->PolygonList[x].v[0]].Position;
				Hb=Host->VertexList[Host->PolygonList[x].v[1]].Position;
				Hc=Host->VertexList[Host->PolygonList[x].v[2]].Position;

				MATRIX m;
				memcpy(&m,Host->ModelView,sizeof(MATRIX));
				//for (int a=0; a<4; a++) for (int b=0; b<4; b++) m[a][b]=KillFloat(m[a][b],2);

				M_Xformd(m,Ha,Ha);
				M_Xformd(m,Hb,Hb);
				M_Xformd(m,Hc,Hc);

				VECTOR3 Origin=V3_Mults(V3_Add(V3_Add(Ha,Hb),Hc),1/3.0f);
				VECTOR3 i=V3_Normalize(V3_Cross(V3_Sub(Hc,Ha),V3_Sub(Hb,Ha)));

				for (int y=0; y<Object->Param2; y++)
				{
					VECTOR3 Random=V3_Normalize(V3_Make((float)rand(),(float)rand(),(float)rand()));
					VECTOR3 j=V3_Cross(i,Random);
					VECTOR3 k=V3_Mults(V3_Cross(i,j),0.5f);

					VECTOR3 a,b,c,d;
					float r=((rand()/(float)RAND_MAX)-0.5f)*2.0f;
					i=V3_Mults(i,Object->Param3/255.0f);
					k=V3_Mults(k,Object->Param1/255.0f);
					
					a=V3_Add(Origin,k);
					b=V3_Add(V3_Add(Origin,k),i);
					c=V3_Add(V3_Sub(Origin,k),i);
					d=V3_Sub(Origin,k);

					Object->AddVertex(a.x,a.y,a.z,0,0);
					Object->AddVertex(b.x,b.y,b.z,0,1);
					Object->AddVertex(c.x,c.y,c.z,1,1);
					Object->AddVertex(d.x,d.y,d.z,1,0);

					Object->AddPolygon((x*Object->Param2+y)*4,(x*Object->Param2+y)*4+1,(x*Object->Param2+y)*4+2,aDDict_GOURAUDSHADE,1,0,1);
					Object->AddPolygon((x*Object->Param2+y)*4,(x*Object->Param2+y)*4+2,(x*Object->Param2+y)*4+3,aDDict_GOURAUDSHADE,0,1,1);
				}
			}
		}
		break;
#endif
#ifdef INCLUDE_OBJ_SUPERSHAPE
	case aDDict_SUPERSHAPE:
		{
			SUPERSHAPE *s=(SUPERSHAPE*)Object->Param1;

			for (int x=0; x<=s->Xres; x++)
			{
				float phi=LinearInterpolate((float)s->Rangex1,(float)s->Rangex2,x/(float)(s->Xres))/180.0f*3.1415f;
			
				float r0=0;
				if (!s->Sphere) r0=s->Trad0;

				float r1a=SuperShapeRad(s->SuperShape1.mint+s->SuperShape1.mfloat/255.0f,s->SuperShape1.n1,s->SuperShape1.n2,s->SuperShape1.n3,s->SuperShape1.a,s->SuperShape1.b,phi)+r0;

				if (s->RadFunc)
				{
					float r1;
					if (s->RadFunc==1) r1=s->Rada*phi;
					if (s->RadFunc==2) r1=(float)(s->Rada*exp(s->Radb*phi));
					r1a*=r1;
				}

				float r1=s->Verta*phi;
				
				for (int y=0; y<=s->Yres; y++)
				{
					float ro=LinearInterpolate((float)s->Rangey1,(float)s->Rangey2,y/(float)(s->Yres))/180.0f*3.1415f;

					float r2a=SuperShapeRad(s->SuperShape2.mint+s->SuperShape2.mfloat/255.0f,s->SuperShape2.n1,s->SuperShape2.n2,s->SuperShape2.n3,s->SuperShape2.a,s->SuperShape2.b,ro);

					VECTOR3 pos;
					if (s->Sphere) pos=V3_Make((float)(r1a*cos(phi )*r2a*cos(ro )),(float)(r1a*sin(phi )*r2a*cos(ro )),(float)(r2a*sin(ro )));
					else pos=V3_Make((float)(cos(phi )*(r1a+r2a*cos(ro ))),(float)(sin(phi )*(r1a+r2a*cos(ro ))),(float)(r2a*sin(ro )));

					if (s->VertFunc) pos.z*=r1;

					Object->AddVertex(pos.x,pos.y,pos.z,x/(float)(s->Xres),y/(float)(s->Yres));

				}
			}

			for (x=0; x<s->Xres; x++)
			{
				for (int y=0; y<s->Yres; y++)
				{
					Object->AddPolygon(x*(s->Yres+1)+y,(x+1)*(s->Yres+1)+y+1,(x+1)*(s->Yres+1)+y,aDDict_GOURAUDSHADE,0,1,1);
					Object->AddPolygon(x*(s->Yres+1)+y,(x)*(s->Yres+1)+y+1,(x+1)*(s->Yres+1)+y+1,aDDict_GOURAUDSHADE,1,0,1);
				}
			}

		}
		break;
#endif
	case -25472:
	default: break;
	}
		
#ifdef INCLUDE_OBJ_STORED
	if (Object->Primitive!=aDDict_STORED)
	{
		Object->CalculateTextureCoordinates();
	}
#else
	Object->CalculateTextureCoordinates();
#endif

	for (x=0; x<Object->PolygonNum; x++)
	{
		if (Object->Shading!=aDDict_DEFAULTSHADE) Object->PolygonList[x].CurrentShading=Object->Shading;
	}


}
예제 #5
0
double VF_Visibility(Poly *poly_i, Poly *poly_j, 
                     CandidateList *candidates, int nc)
{
  int    i, j, n, ns, cnt, nt, test_vertices=0;
  double tmax, tmp, n_dot_d;
  Ray    ray0,*ray;
  Point  samples_i[4096], samples_j[4096];
  Vector q;
  Adaptive    *adaptive;
  VFenclosure *enclosure=VF_CurrentEnclosure();

  adaptive = &(enclosure->adaptive);
  if (nc==0) return(1.0);
  VF_SamplesUVtoXYZ(poly_i, &(adaptive->visibility.sampling), 
                    adaptive->visibility.sampleuv_i, samples_i);
  VF_SamplesUVtoXYZ(poly_j, &(adaptive->visibility.sampling), 
                    adaptive->visibility.sampleuv_j, samples_j);
  ns = adaptive->visibility.sampling.n;
  if (test_vertices) {
    cnt = nt = ns+poly_i->np*poly_j->np;
  } else {
    cnt = nt = ns;
  }
  /*=================================================*/
  /* TEST VISIBILITY OF RAYS BETWEEN SAMPLING POINTS */
  /*=================================================*/
  for (n=0; n<ns; n++) {
    ray      = &(adaptive->visibility.ray[n]);
    ray->O   = samples_i[n];
    ray->vis = 0;
    V3_Sub(&(samples_j[n]), &(ray->O), &(ray->D));
    V3_Normalize(&(ray->D),tmp);
    n_dot_d = V3_Dot(&(poly_j->normal), &(ray->D));
    if (fabs(n_dot_d)<VF_RAY_TEST) {
      cnt--;
    } else {
      V3_Sub(&(poly_j->p[0]), &(ray->O), &q);
      tmax = V3_Dot(&(poly_j->normal), &q)/n_dot_d;
      if (VF_RayPatchListTest(&(adaptive->visibility.ray[n]), 
                              n, tmax, candidates, nc)) cnt--;
    }
  }
  if (test_vertices) {
    /*===============================================================*/
    /* ALSO TEST RAYS BETWEEN ALL VERTEX COMBINATIONS FOR VISIBILITY */
    /*===============================================================*/
    for (i=0; i<poly_i->np; i++) {
      for (j=0; j<poly_j->np; j++) {
        ray0.vis = 0;
        ray0.O   = poly_i->p[i];
        V3_Sub(&(poly_j->p[j]), &(ray0.O), &(ray0.D));
        V3_Normalize(&(ray0.D),tmp);
        n_dot_d = V3_Dot(&(poly_j->normal), &(ray0.D));
        if (fabs(n_dot_d)<VF_RAY_TEST) {
          cnt--;
        } else {
          V3_Sub(&(poly_j->p[0]), &(ray0.O), &q);
          tmax = V3_Dot(&(poly_j->normal), &q)/n_dot_d;
          if (VF_RayPatchListTest(&ray0, n, tmax, candidates, nc)) {
            cnt--;
          }
        }
      }
    }
  }
  return ((double)(cnt)/(double)(nt));
}
예제 #6
0
void OBJECT::SortVertexEdges()
{
    for (int x=0; x<VertexNum; x++)
    {
        if (VertexList[x].EdgeNum>2)
        {
            VECTOR3 vertvector;
            VECTOR3 normal = V3_Normalize(VertexList[x].Normal);
            VECTOR3 vx = VertexList[x].Position;

            float *szogek = new float[VertexList[x].EdgeNum];

            int e=GetEdgeVertex(this,x,VertexList[x].EdgeList[0]);
            VECTOR3 refvector=VertexList[e].Position;
            refvector = V3_Sub(refvector,vx);

            VECTOR3 projvec=normal;
            projvec=V3_Mults(projvec,V3_Dot(refvector,normal));
            refvector = V3_Normalize(V3_Sub(refvector,projvec));

            int y;
            for (y=1; y<VertexList[x].EdgeNum; y++)
            {
                e=GetEdgeVertex(this,x,VertexList[x].EdgeList[y]);
                vertvector = V3_Sub(VertexList[e].Position,vx);
                projvec=V3_Mults(normal,V3_Dot(vertvector,normal));
                vertvector = V3_Normalize(V3_Sub(vertvector,projvec));

                float cosTheta = max(-1.0f,min(1.0f,V3_Dot(vertvector,refvector)));
                float angle = (float)acos(cosTheta) * 180.0f / 3.1415f;

                VECTOR3 crossProd=V3_Cross(vertvector,refvector);
                if (V3_Dot(crossProd,normal) < 0) angle = 360 - angle;

                szogek[y]=angle;

            }

            int smallest,b1;
            float smallestvalue, b2;

            for (int z=0; z<VertexList[x].EdgeNum; z++)
            {
                smallest=z;
                smallestvalue=szogek[z];

                for (y=z; y<VertexList[x].EdgeNum; y++)
                {
                    if (szogek[y]<=smallestvalue)
                    {
                        smallest=y;
                        smallestvalue=szogek[y];
                    }
                }

                b2=szogek[smallest];
                szogek[smallest]=szogek[z];
                szogek[z]=b2;

                b1=VertexList[x].EdgeList[smallest];
                VertexList[x].EdgeList[smallest]=VertexList[x].EdgeList[z];
                VertexList[x].EdgeList[z]=b1;
            }

            delete[] szogek;
        }
    }
}