Пример #1
0
    // バウンディングボックスとの交差判定.
    IZ_BOOL Frustum::isIntersect(
        const BoundingVolume* const volume,
        const math::SMatrix44& mtxW2V)
    {
        // ボックスの中心を取得.
        auto center = volume->getCenter();

        // カメラ座標系に変換.
        math::SMatrix44::Apply(center, center, mtxW2V);

        for (IZ_UINT i = 0; i < COUNTOF(m_planes); i++) {
            math::CVector4 nml(
                m_planes[i].x,
                m_planes[i].y,
                m_planes[i].z,
                0.0f);

            // 実効半径を計算.
            auto radius = volume->computeRadius(mtxW2V, nml);

            auto dot = math::SVector4::Dot(m_planes[i], center);

            if (dot <= -radius) {
                return IZ_FALSE;
            }
        }

        return IZ_TRUE;
    }
Пример #2
0
    // バウンディングボックスとの交差判定.
    IZ_BOOL Frustum::isIntersect(const BoundingVolume* const volume)
    {
        // ボックスの中心を取得.
        auto center = volume->getCenter();

        // World座標系で判定処理を行う.

        for (IZ_UINT i = 0; i < COUNTOF(m_planes); i++) {
            math::CVector4 nml(
                m_planes[i].x,
                m_planes[i].y,
                m_planes[i].z,
                0.0f);

            // 実効半径を計算.
            auto radius = volume->computeRadius(nml);

            auto dot = math::SVector4::Dot(m_planes[i], center);

            if (dot <= -radius) {
                return IZ_FALSE;
            }
        }

        return IZ_TRUE;
    }
Пример #3
0
// Generate a COMPILED_METHOD_LOAD event for each nnmethod
jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) {
  HandleMark hm;

  // Walk the CodeCache notifying for live nmethods.  The code cache
  // may be changing while this is happening which is ok since newly
  // created nmethod will notify normally and nmethods which are freed
  // can be safely skipped.
  MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
  // Iterate over non-profiled and profiled nmethods
  NMethodIterator iter;
  while(iter.next_alive()) {
    nmethod* current = iter.method();
    // Lock the nmethod so it can't be freed
    nmethodLocker nml(current);

    // Don't hold the lock over the notify or jmethodID creation
    MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
    current->get_and_cache_jmethod_id();
    JvmtiExport::post_compiled_method_load(current);
  }
  return JVMTI_ERROR_NONE;
}
static SCE_PFX_FORCE_INLINE
bool pfxContactTriangleConvex(PfxContactCache &contacts,PfxUInt32 facetId,
							const PfxVector3 &normal,const PfxVector3 &p0,const PfxVector3 &p1,const PfxVector3 &p2,
							const PfxFloat thickness,const PfxFloat angle0,const PfxFloat angle1,const PfxFloat angle2,
							PfxUInt32 edgeChk,
							const PfxConvexMesh &convex)
{
	PfxVector3 facetPnts[6] = {
		p0,p1,p2,p0-thickness*normal,p1-thickness*normal,p2-thickness*normal
	};
	

	PfxPoint3 pA(0.0f),pB(0.0f);
	PfxVector3 nml(0.0f);
	PfxGjkSolver gjk;

	gjk.setup((void*)facetPnts,(void*)&convex,pfxGetSupportVertexTriangleWithThickness,pfxGetSupportVertexConvex);
	PfxFloat d = gjk.collide(nml,pA,pB,PfxTransform3::identity(),PfxTransform3::identity(),SCE_PFX_FLT_MAX);
	if(d >= 0.0f) return false;
	
	PfxVector3 pointsOnTriangle = PfxVector3(pA);
	PfxVector3 pointsOnConvex = PfxVector3(pB);
	PfxVector3 axis = nml;
	
	// 面上の最近接点が凸エッジ上でない場合は法線を変える
	if( ((edgeChk&0x01)&&pfxPointOnLine(pointsOnTriangle,p0,p1)) ||
		((edgeChk&0x02)&&pfxPointOnLine(pointsOnTriangle,p1,p2)) ||
		((edgeChk&0x04)&&pfxPointOnLine(pointsOnTriangle,p2,p0)) ) {
		axis=-normal;
	}
	
	PfxSubData subData;
	subData.setFacetId(facetId);
	contacts.addContactPoint(-length(pointsOnTriangle-pointsOnConvex),axis,pA,pB,subData);
	
	return true;
}
Пример #5
0
void CCourse::CalcNormals () {
	for (int y=0; y<ny; y++) {
        for (int x=0; x<nx; x++) {
            TVector3 nml(0.0, 0.0, 0.0);
            TVector3 p0 (XCD(x), ELEV(x,y), ZCD(y));

			if ((x + y) % 2 == 0) {
				if (x > 0 && y > 0) {
					TVector3 p1 = NMLPOINT(x,  y-1);
					TVector3 p2 = NMLPOINT(x-1,y-1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);

					p1 = NMLPOINT (x-1, y-1);
					p2 = NMLPOINT (x-1, y);
					v1 = SubtractVectors (p1, p0);
					v2 = SubtractVectors (p2, p0);
					n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x > 0 && y < ny-1) {
					TVector3 p1 = NMLPOINT(x-1,y);
					TVector3 p2 = NMLPOINT(x-1,y+1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);

					p1 = NMLPOINT(x-1,y+1);
					p2 = NMLPOINT(x  ,y+1);
					v1 = SubtractVectors (p1, p0);
					v2 = SubtractVectors (p2, p0);
					n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x < nx-1 && y > 0) {
					TVector3 p1 = NMLPOINT(x+1,y);
					TVector3 p2 = NMLPOINT(x+1,y-1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);

					p1 = NMLPOINT(x+1,y-1);
					p2 = NMLPOINT(x  ,y-1);
					v1 = SubtractVectors (p1, p0);
					v2 = SubtractVectors (p2, p0);
					n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x < nx-1 && y < ny-1) {
					TVector3 p1 = NMLPOINT(x+1,y);
					TVector3 p2 = NMLPOINT(x+1,y+1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v1, v2);

					NormVector (n);
					nml = AddVectors (nml, n);

					p1 = NMLPOINT(x+1,y+1);
					p2 = NMLPOINT(x  ,y+1);
					v1 = SubtractVectors (p1, p0);
					v2 = SubtractVectors (p2, p0);
					n = CrossProduct (v1, v2);

					NormVector (n);
					nml = AddVectors (nml, n);

				}
			} else {
				if (x > 0 && y > 0) {
					TVector3 p1 = NMLPOINT(x,  y-1);
					TVector3 p2 = NMLPOINT(x-1,y);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x > 0 && y < ny-1) {
					TVector3 p1 = NMLPOINT(x-1,y);
					TVector3 p2 = NMLPOINT(x  ,y+1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x < nx-1 && y > 0) {
					TVector3 p1 = NMLPOINT(x+1,y);
					TVector3 p2 = NMLPOINT(x  ,y-1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v2, v1);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
				if (x < nx-1 && y < ny-1) {
					TVector3 p1 = NMLPOINT(x+1,y);
					TVector3 p2 = NMLPOINT(x  ,y+1);
					TVector3 v1 = SubtractVectors (p1, p0);
					TVector3 v2 = SubtractVectors (p2, p0);
					TVector3 n = CrossProduct (v1, v2);

					NormVector (n);
					nml = AddVectors (nml, n);
				}
			}
            NormVector (nml);
			nmls [x + nx * y] = nml;
            continue;

		}
    }
}
Пример #6
0
// retourne l'objet en World Coordinates
C3DObject* C3DObject::getWorldObject(void) {
	C3DObject *o = new C3DObject;
	unsigned i,j;
	float *farray;
	// sinus & cosinus
	float cox = cos(orientation.x);
	float six = sin(orientation.x);
	float coy = cos(orientation.y);
	float siy = sin(orientation.y);
	float coz = cos(orientation.z);
	float siz = sin(orientation.z);
	// --- Rotation Matrix ---
	SMLXMatrix Rx(4,4);
	// initialise une matrice identite
	for(j=0;j<4;j++) for(i=0;i<4;i++) Rx[j][i]=(i==j?1.0f:.0f);
	Rx[1][1] = cox;
	Rx[1][2] =-six;
	Rx[2][1] = six;
	Rx[2][2] = cox;
	SMLXMatrix Ry(4,4);
	// initialise une matrice identite
	for(j=0;j<4;j++) for(i=0;i<4;i++) Ry[j][i]=(i==j?1.0f:.0f);
	Ry[0][0] = coy;
	Ry[0][2] = siy;
	Ry[2][0] =-siy;
	Ry[2][2] = coy;
	SMLXMatrix Rz(4,4);
	// initialise une matrice identite
	for(j=0;j<4;j++) for(i=0;i<4;i++) Rz[j][i]=(i==j?1.0f:.0f);
	Rz[0][0] = coz;
	Rz[0][1] =-siz;
	Rz[1][0] = siz;
	Rz[1][1] = coz;
	// Matrice tenant compte des 3 rotations
	SMLXMatrix R = Rz*Ry*Rx;
	// --- Scale Matrix ---
	SMLXMatrix S(4,4);
	for(j=0;j<4;j++) for(i=0;i<4;i++) S[j][i]=(i==j?1.0f:.0f);
	farray = size.data();
	for (i=0; i<3; i++) S[i][i] = farray[i];
	// --- Translation Matrix ---
	SMLXMatrix T(4,4);
	for(j=0;j<4;j++) for(i=0;i<4;i++) T[j][i]=(i==j?1.0f:.0f);
	farray = origin.data();
	for (i=0; i<3; i++) T[i][3] = farray[i];

	SMLXMatrix M = T*R*S;

	o->set(*this);
	// converti les vertices
	for (unsigned v=0; v<o->nb_verts; v++) {
		SMLXMatrix vec(4,1);
		vec[0][0] = o->vertices[v].x;
		vec[1][0] = o->vertices[v].y;
		vec[2][0] = o->vertices[v].z;
		vec[3][0] = 1.0f;
		SMLXMatrix nvec = M*vec;
		o->vertices[v].x = nvec[0][0];
		o->vertices[v].y = nvec[1][0];
		o->vertices[v].z = nvec[2][0];
	}
	// converti les normales (rotation seulement)
	for (unsigned f=0; f<o->nb_faces; f++) {
		SMLXMatrix vec(4,1);
		vec[0][0] = o->faces[f].norm.x;
		vec[1][0] = o->faces[f].norm.y;
		vec[2][0] = o->faces[f].norm.z;
		vec[3][0] = 1.0f;
		SMLXMatrix nvec = R*vec;
		o->faces[f].norm.x = nvec[0][0];
		o->faces[f].norm.y = nvec[1][0];
		o->faces[f].norm.z = nvec[2][0];
		for (v=0; v<3; v++) {
			SMLXMatrix nml(4,1);
			nml[0][0] = o->faces[f].pt_norm[v].x;
			nml[1][0] = o->faces[f].pt_norm[v].y;
			nml[2][0] = o->faces[f].pt_norm[v].z;
			nml[3][0] = 1.0f;
			SMLXMatrix nnml = R*nml;
			o->faces[f].pt_norm[v].x = nnml[0][0];
			o->faces[f].pt_norm[v].y = nnml[1][0];
			o->faces[f].pt_norm[v].z = nnml[2][0];
		}
	}
	o->compute_bbox();
	return o;
}