예제 #1
0
파일: bchgen.c 프로젝트: drownedout/datamap
	int
bchgen(projUV a, projUV b, int nu, int nv, projUV **f, projUV(*func)(projUV)) {
	int i, j, k;
	projUV arg, *t, bma, bpa, *c;
	double d, fac;

	bma.u = 0.5 * (b.u - a.u); bma.v = 0.5 * (b.v - a.v);
	bpa.u = 0.5 * (b.u + a.u); bpa.v = 0.5 * (b.v + a.v);
	for ( i = 0; i < nu; ++i) {
		arg.u = cos(PI * (i + 0.5) / nu) * bma.u + bpa.u;
		for ( j = 0; j < nv; ++j) {
			arg.v = cos(PI * (j + 0.5) / nv) * bma.v + bpa.v;
			f[i][j] = (*func)(arg);
			if ((f[i][j]).u == HUGE_VAL)
				return(1);
		}
	}
	if (!(c = (projUV *) vector1(nu, sizeof(projUV)))) return 1;
	fac = 2. / nu;
	for ( j = 0; j < nv ; ++j) {
		for ( i = 0; i < nu; ++i) {
			arg.u = arg.v = 0.;
			for (k = 0; k < nu; ++k) {
				d = cos(PI * i * (k + .5) / nu);
				arg.u += f[k][j].u * d;
				arg.v += f[k][j].v * d;
			}
			arg.u *= fac;
			arg.v *= fac;
			c[i] = arg;
		}
		for (i = 0; i < nu; ++i)
			f[i][j] = c[i];
	}
	pj_dalloc(c);
	if (!(c = (projUV*) vector1(nv, sizeof(projUV)))) return 1;
	fac = 2. / nv;
	for ( i = 0; i < nu; ++i) {
		t = f[i];
		for (j = 0; j < nv; ++j) {
			arg.u = arg.v = 0.;
			for (k = 0; k < nv; ++k) {
				d = cos(PI * j * (k + .5) / nv);
				arg.u += t[k].u * d;
				arg.v += t[k].v * d;
			}
			arg.u *= fac;
			arg.v *= fac;
			c[j] = arg;
		}
		f[i] = c;
		c = t;
	}
	pj_dalloc(c);
	return(0);
}
예제 #2
0
TEST(SharedBufferTest, getAsBytesLargeSegments) {
  Vector<char> vector0(0x4000);
  for (size_t i = 0; i < vector0.size(); ++i)
    vector0[i] = 'a';
  Vector<char> vector1(0x4000);
  for (size_t i = 0; i < vector1.size(); ++i)
    vector1[i] = 'b';
  Vector<char> vector2(0x4000);
  for (size_t i = 0; i < vector2.size(); ++i)
    vector2[i] = 'c';

  RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::adoptVector(vector0);
  sharedBuffer->append(vector1);
  sharedBuffer->append(vector2);

  const size_t size = sharedBuffer->size();
  std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]);
  sharedBuffer->getAsBytes(data.get(), size);

  ASSERT_EQ(0x4000U + 0x4000U + 0x4000U, size);
  int position = 0;
  for (int i = 0; i < 0x4000; ++i) {
    EXPECT_EQ('a', data[position]);
    ++position;
  }
  for (int i = 0; i < 0x4000; ++i) {
    EXPECT_EQ('b', data[position]);
    ++position;
  }
  for (int i = 0; i < 0x4000; ++i) {
    EXPECT_EQ('c', data[position]);
    ++position;
  }
}
예제 #3
0
	void llquat_test_object_t::test<2>()
	{
		LLMatrix4 llmat;
		LLVector4 vector1(2.0f, 1.0f, 3.0f, 6.0f);
		LLVector4 vector2(5.0f, 6.0f, 0.0f, 1.0f);
		LLVector4 vector3(2.0f, 1.0f, 2.0f, 9.0f);
		LLVector4 vector4(3.0f, 8.0f, 1.0f, 5.0f);

		llmat.initRows(vector1, vector2, vector3, vector4);
		ensure("explicit LLQuaternion(const LLMatrix4 &mat) failed", 2.0f == llmat.mMatrix[0][0] &&
										 	1.0f == llmat.mMatrix[0][1] &&
											3.0f == llmat.mMatrix[0][2] &&
											6.0f == llmat.mMatrix[0][3] &&
											5.0f == llmat.mMatrix[1][0] &&
											6.0f == llmat.mMatrix[1][1] &&
											0.0f == llmat.mMatrix[1][2] &&
											1.0f == llmat.mMatrix[1][3] &&
											2.0f == llmat.mMatrix[2][0] &&
											1.0f == llmat.mMatrix[2][1] &&
											2.0f == llmat.mMatrix[2][2] &&
											9.0f == llmat.mMatrix[2][3] &&
											3.0f == llmat.mMatrix[3][0] &&
											8.0f == llmat.mMatrix[3][1] &&
											1.0f == llmat.mMatrix[3][2] &&
											5.0f == llmat.mMatrix[3][3]);
	}
예제 #4
0
	bool Engine::collisionD(Sprite *sprite1, Sprite *sprite2)
		{
			double radius1, radius2;

			//calculate radius 1
			if (sprite1->getWidth() > sprite1->getHeight())
				radius1 = (sprite1->getWidth()*sprite1->getScaleH())/2;
			else
				radius1 = (sprite1->getHeight()*sprite1->getScaleV())/2;

			//point = center of sprite 1
			double x1 = sprite1->getX() + radius1;
			double y1 = sprite1->getY() + radius1;
			Vector3 vector1(x1, y1, 0.0);

			//calculate radius 2
			if (sprite2->getWidth() > sprite2->getHeight())
				radius2 = (sprite2->getWidth()*sprite2->getScaleH())/2;
			else
				radius2 = (sprite2->getHeight()*sprite2->getScaleV())/2;

			//point = center of sprite 2
			double x2 = sprite2->getX() + radius2;
			double y2 = sprite2->getY() + radius2;
			Vector3 vector2(x2, y2, 0.0);

			//calculate distance
			double dist = vector1.Distance( vector2 );

			//return distance comparison
			return (dist < radius1 + radius2);
		}
예제 #5
0
GLC_Matrix4x4 GLC_RotationManipulator::doManipulate(const GLC_Point3d& newPoint, const GLC_Vector3d& projectionDirection)
{
    // Project the given point on the sliding plane with the given direction
    GLC_Point3d projectedPoint;
    GLC_Line3d projectionLine1(GLC_AbstractManipulator::m_PreviousPosition, projectionDirection);
    GLC_Line3d projectionLine(newPoint, projectionDirection);

    // create the rotation plane
    const GLC_Point3d origine(m_RotationLine.startingPoint());
    GLC_Plane rotationPlane(m_RotationLine.direction(), origine);
    // Project the point on the previous computed plane
    glc::lineIntersectPlane(projectionLine1, rotationPlane, &(GLC_AbstractManipulator::m_PreviousPosition));
    glc::lineIntersectPlane(projectionLine, rotationPlane, &projectedPoint);

    // Compute the the to vector
    GLC_Vector3d vector1((GLC_AbstractManipulator::m_PreviousPosition - origine).normalize());
    GLC_Vector3d vector2((projectedPoint - origine).normalize());

    // Update previous position to this position
    GLC_AbstractManipulator::m_PreviousPosition= projectedPoint;

    // Return the rotation matrix
    const GLC_Matrix4x4 trans1(-origine);
    const GLC_Matrix4x4 trans2(origine);
    const GLC_Matrix4x4 rotation(vector1, vector2);

    return (trans2 * rotation * trans1);

}
예제 #6
0
파일: bch2bps.c 프로젝트: fb/jasper-xcsoar
	static void /* convert columns to power series */
cols(projUV **c, projUV **d, int nu, int nv) {
	projUV *sv, **dd;
	int j, k;

	dd = (projUV **)vector2(nu, nv, sizeof(projUV));
	sv = (projUV *)vector1(nv, sizeof(projUV));
	bclear(d, nu, nv);
	bclear(dd, nu, nv);
	bmove(d[0], c[nu-1], nv);
	for (j = nu-2; j >= 1; --j) {
		for (k = nu-j; k >= 1; --k) {
			bmove(sv, d[k], nv);
			submop(d[k], 2., d[k-1], dd[k], nv);
			bmove(dd[k], sv, nv);
		}
		bmove(sv, d[0], nv);
		subop(d[0], c[j], dd[0], nv);
		bmove(dd[0], sv, nv);
	}
	for (j = nu-1; j >= 1; --j)
		subop(d[j], d[j-1], dd[j], nv);
	submop(d[0], .5, c[0], dd[0], nv);
	freev2((void **) dd, nu);
	pj_dalloc(sv);
}
예제 #7
0
파일: bch2bps.c 프로젝트: fb/jasper-xcsoar
	static void /* convert row to pover series */
rows(projUV *c, projUV *d, int n) {
	projUV sv, *dd;
	int j, k;

	dd = (projUV *)vector1(n-1, sizeof(projUV));
	sv.u = sv.v = 0.;
	for (j = 0; j < n; ++j) d[j] = dd[j] = sv;
	d[0] = c[n-1];
	for (j = n-2; j >= 1; --j) {
		for (k = n-j; k >= 1; --k) {
			sv = d[k];
			d[k].u = 2. * d[k-1].u - dd[k].u;
			d[k].v = 2. * d[k-1].v - dd[k].v;
			dd[k] = sv;
		}
		sv = d[0];
		d[0].u = -dd[0].u + c[j].u;
		d[0].v = -dd[0].v + c[j].v;
		dd[0] = sv;
	}
	for (j = n-1; j >= 1; --j) {
		d[j].u = d[j-1].u - dd[j].u;
		d[j].v = d[j-1].v - dd[j].v;
	}
	d[0].u = -dd[0].u + .5 * c[0].u;
	d[0].v = -dd[0].v + .5 * c[0].v;
	pj_dalloc(dd);
}
예제 #8
0
GMBoundingBox GMBoundingBox::CreateFromPoints(const GMVector3D* vecs, size_t count)
{
    GMVector3D vector2(DBL_MAX);
    GMVector3D vector1(DBL_MIN);
    for (int i = 0; i < count; i++) {
        vector2 = GMVector3D::Min(vector2, vecs[i]);
        vector1 = GMVector3D::Max(vector1, vecs[i]);
    }
    return GMBoundingBox(vector2, vector1);
}
예제 #9
0
double PathCorrector::getCos(QPoint const & pnt1, QPoint const & pnt2, QPoint const & pnt3)
{
	QPoint vector1(pnt2.x() - pnt1.x(), pnt2.y() - pnt1.y());
	QPoint vector2(pnt3.x() - pnt2.x(), pnt3.y() - pnt2.y());
	double length1 = (pnt1 - pnt2).manhattanLength();
	double length2 = (pnt2 - pnt3).manhattanLength();
	if(length1 > 0 && length2 > 0)
		return (double) getScalarProduct(vector1, vector2) / (length1 * length2);
	return 1;
}
예제 #10
0
	void GLKernel::PushLine(float32 x0, float32 y0, float32 x1, float32 y1)
	{
		Vector4 vector0(x0, y0, 1.0f, 1.0f);
		Vector4 vector1(x1, y1, 1.0f, 1.0f);
		if(m_Transformed)
		{
			vector0 = m_CurrentMatrix * vector0;
			vector1 = m_CurrentMatrix * vector1;
		}
		vector0.PopulateArray(m_Vertices);
		vector1.PopulateArray(m_Vertices);
	}
예제 #11
0
//! intersection of line and plane
bool
CMathGeom3D::
LinePlaneIntersect(const CPoint3D &point, const CVector3D &direction,
                   const CNPlane3D &normal, CPoint3D &ipoint, double &iparam)
{
  double d1 = direction.dotProduct(normal.getDirection());

  if (fabs(d1) < CMathGen::EPSILON_E6)
    return false;

  CVector3D vector1(point);

  double d2 = vector1.dotProduct(normal.getDirection());

  iparam = (normal.getScalar() - d2)/d1;
  ipoint = point + direction*iparam;

  return true;
}
예제 #12
0
void NormalsFinder::execute()
{
    assert ( _mesh != NULL );
    for ( unsigned int i = 0; i < _mesh->face_count(); i++ )
    {
        Face face = _mesh->get_face ( i );
        Vertex middle = _mesh->get_vertex( face[1] );
        Vertex first = _mesh->get_vertex( face[0] );
        Vertex last = _mesh->get_vertex( face[2] );

        Vector < float > vector0 ( middle, first );
        Vector < float > vector1 ( middle, last );
        Vector < float > normal;
        normal = vector1 * vector0;
        normal /= normal.length();
        _mesh->add_normals_coord ( normal[0] );
        _mesh->add_normals_coord ( normal[1] );
        _mesh->add_normals_coord ( normal[2] );
    }
}
예제 #13
0
Normal triangle_normal(const Position &position1, const Position &position2, const Position &position3)
{
    Vector vector1(position2.x - position1.x, position2.y - position1.y, position2.z - position1.z);
    Vector vector2(position3.x - position1.x, position3.y - position1.y, position3.z - position1.z);
    Vector vector3;

    vector3.x = (vector1.y * vector2.z) - (vector1.z * vector2.y);
    vector3.y = (vector1.z * vector2.x) - (vector1.x * vector2.z);
    vector3.z = (vector1.x * vector2.y) - (vector1.y * vector2.x);

    Normal normal;
    double distance = sqrt((vector3.x * vector3.x) + (vector3.y * vector3.y) + (vector3.z * vector3.z));
    if (equal(distance, 0.0))
    {
        return Normal(0, 0, 0);
    }

    normal.x = -vector3.x / distance;
    normal.y = -vector3.y / distance;
    normal.z = -vector3.z / distance;
    return normal;
}
예제 #14
0
TEST(OsgMaterialTests, AccessibleUniformTest)
{
	auto material = std::make_shared<OsgMaterial>("material");

	std::string uniform1Name = "ossFloatUniform";
	auto uniform1 = std::make_shared<OsgUniform<float>>(uniform1Name);


	std::string uniform2Name = "ossVector2fUniform";
	auto uniform2 = std::make_shared<OsgUniform<Vector2f>>(uniform2Name);

	material->addUniform(uniform1);
	material->addUniform(uniform2);

	material->setValue(uniform1Name, 2.0f);

	EXPECT_FLOAT_EQ(2.0, uniform1->get());

	uniform1->set(4.0f);
	EXPECT_FLOAT_EQ(4.0f, material->getValue<float>(uniform1Name));

	Vector2f vector1(1.0f, 2.0f);
	Vector2f vector2(3.0f, 4.0f);

	material->setValue(uniform2Name, vector1);

	EXPECT_TRUE(vector1.isApprox(uniform2->get()));

	uniform2->set(vector2);
	EXPECT_TRUE(vector2.isApprox(material->getValue<Vector2f>(uniform2Name)));

	material->removeUniform(uniform1);

	EXPECT_ANY_THROW(material->setValue(uniform1Name, 1.0f));

}
예제 #15
0
void HighscoreScene::calculateEntryPositions()
{
    float entryHeight = 40;
    int numberOfEntries = 10;
    
    float padding = 50;
    float headerHighscoreHeight = 60;
    float headerHighscoreEntryHeight = 0;
    
    // Highscore Panel
    float highscorePanelHeight = 700;
    float highscorePanelWidth = 700;
    float highscorePanelX = highscore_->getPositionX();
    float highscorePanelY = highscore_->getPositionY();
    
    // Highscore Content
    float contentHeight = highscorePanelHeight - (2 * padding);
    float contentWidth = highscorePanelWidth - (2 * padding);
    float contentX = (highscorePanelX - 700/2) + padding;
    float contentY = (highscorePanelY - 700/2) + padding;
    float contentHeightForEntryList = contentHeight - headerHighscoreHeight - headerHighscoreEntryHeight;
    
    // Calculate padding between each entry
    float entryPadding = (contentHeightForEntryList - (entryHeight * numberOfEntries)) / 9;
    int entryPaddingRounded = static_cast<int>(entryPadding);
    
    // Calculate Positions for all entries
    for (int i = 0; i < numberOfEntries; i++){
        float y = contentY + (i * entryHeight + i * entryPaddingRounded);
        
        Vec2 vector1(contentX, y);
        Vec2 vector2(contentX + contentWidth, y);
        this->entryPositionListName.insert(entryPositionListName.end(), std::move(vector1));
        this->entryPositionListPoint.insert(entryPositionListPoint.end(), std::move(vector2));
    }
}
예제 #16
0
WFace *WShape::MakeFace(vector<WVertex *>& iVertexList, vector<bool>& iFaceEdgeMarksList, unsigned iMaterial,
                        WFace *face)
{
	int id = _FaceList.size();

	face->setFrsMaterialIndex(iMaterial);

	// Check whether we have a degenerated face:

	// LET'S HACK IT FOR THE TRIANGLE CASE:

	if (3 == iVertexList.size()) {
		if ((iVertexList[0] == iVertexList[1]) ||
		    (iVertexList[0] == iVertexList[2]) ||
		    (iVertexList[2] == iVertexList[1]))
		{
			cerr << "Warning: degenerated triangle detected, correcting" << endl;
			return NULL;
		}
	}

	vector<WVertex *>::iterator it;

	// compute the face normal (v1v2 ^ v1v3)
	WVertex *v1, *v2, *v3;
	it = iVertexList.begin();
	v1 = *it;
	it++;
	v2 = *it;
	it++;
	v3 = *it;

	Vec3r vector1(v2->GetVertex() - v1->GetVertex());
	Vec3r vector2(v3->GetVertex() - v1->GetVertex());

	Vec3r normal(vector1 ^ vector2);
	normal.normalize();
	face->setNormal(normal);

	vector<bool>::iterator mit = iFaceEdgeMarksList.begin();
	face->setMark(*mit);
	mit++;

	// vertex pointers used to build each edge
	vector<WVertex *>::iterator va, vb;

	va = iVertexList.begin();
	vb = va;
	for (; va != iVertexList.end(); va = vb) {
		++vb;
		// Adds va to the vertex list:
		//face->AddVertex(*va);

		WOEdge *oedge;
		if (*va == iVertexList.back())
			oedge = face->MakeEdge(*va, iVertexList.front()); //for the last (closing) edge
		else
			oedge = face->MakeEdge(*va, *vb);

		if (!oedge)
			return NULL;

		WEdge *edge = oedge->GetOwner();
		if (1 == edge->GetNumberOfOEdges()) {
			// means that we just created a new edge and that we must add it to the shape's edges list
			edge->setId(_EdgeList.size());
			AddEdge(edge);
			// compute the mean edge value:
			_meanEdgeSize += edge->GetaOEdge()->GetVec().norm();
		}

		edge->setMark(*mit);
		++mit;
	}

	// Add the face to the shape's faces list:
	face->setId(id);
	AddFace(face);

	return face;
}
예제 #17
0
  void ModelContainerView::generateHeightMap(int pMapId, int x, int y)
  {
      //TODO: Fix this in general.
      //Here we need to load the GridMap from .map file. then generate vertex map from heigh points.
      GridMap mapArray[64][64]; //TODO: make smaller array and recalculate matching gridmap.
      for (int x1 = x-1; x1 <= x+1; ++x1)
        for (int y1 = y-1; y1 <= y+1; ++y1) {
            mapArray[x1][y1] = GridMap();
            char tmp[12];
            sprintf(tmp, "%03u%02u%02u.map",pMapId,x1,y1);
            std::string gmap =  gMapDataDir + "/" + tmp;
            if (mapArray[x1][y1].loadData(gmap.c_str()))
                printf("Loaded %s\n", gmap.c_str());
        }
    float x_min,y_min,x_max, y_max;
    x_max = (32-x)*SIZE_OF_GRIDS + 50;
    y_max = (32-y)*SIZE_OF_GRIDS + 50;
    x_min = (32-x)*SIZE_OF_GRIDS - 533 - 50;
    y_min = (32-y)*SIZE_OF_GRIDS - 533 - 50;
    for (float x = x_min; x < x_max-2;x += 2)
        for (float y = y_min; y < y_max-2;y += 2) {
            int gx,gy;
            // Here we need to add vertexes. so 3 Vector3 for each triangle.
            // FIXME: This is overly efficient since we visit each vector3 multipletimes during loop.
            gx = (int)(32 - x / SIZE_OF_GRIDS);
            gy = (int)(32 - y / SIZE_OF_GRIDS);
            float heightxy = mapArray[gx][gy].getHeight(x,y);
            gx = (int)(32 - (x+2) / SIZE_OF_GRIDS);
            float heightx1y = mapArray[gx][gy].getHeight(x+2,y);
            gx = (int)(32 - x / SIZE_OF_GRIDS);
            gy = (int)(32 - (y+2) / SIZE_OF_GRIDS);
            float heightxy1 = mapArray[gx][gy].getHeight(x,y+2);
            gx = (int)(32 - (x+2) / SIZE_OF_GRIDS);
            float heightx1y1 = mapArray[gx][gy].getHeight(x+2,y+2);
            Vector3 vector1(x,y,heightxy);
            Vector3 vector2(x+2,y,heightx1y);
            Vector3 vector3(x,y+2,heightxy1);
            Vector3 vector4(x+2,y+2,heightx1y1);
            /*
             * vector1 ------ vector2
             *   |     \     /    |
             *   |      \   /     |
             *   |       \ /      |
             *   |        X       |
             *   |       / \      |
             *   |      /   \     |
             *   |     /     \    |
             * vector3 -------- vector4
             */

            Triangle t1 = Triangle(vector1,vector4,vector3);
            Triangle t2 = Triangle(vector1,vector2,vector4);
            // Check if the center of this Triangle is deep under water. (here: 1 meter)
            Vector3 center = t1.center();
            if (mapArray[(int)(32 - center.x / SIZE_OF_GRIDS)][(int)(32 - center.y / SIZE_OF_GRIDS)].getLiquidLevel(center.x,center.y) < center.z - 1.f)
                globalTriangleArray.append(t1);
            center = t2.center();
            if (mapArray[(int)(32 - center.x / SIZE_OF_GRIDS)][(int)(32 - center.y / SIZE_OF_GRIDS)].getLiquidLevel(center.x,center.y) < center.z - 1.f)
                globalTriangleArray.append(t2);
        }
  }
예제 #18
0
	Tseries *
mk_cheby(projUV a, projUV b, double res, projUV *resid, projUV (*func)(projUV), 
	int nu, int nv, int power) {
	int j, i, nru, nrv, *ncu, *ncv;
	Tseries *Ts = 0;
	projUV **w;
	double cutres;

	if (!(w = (projUV **)vector2(nu, nv, sizeof(projUV))) ||
		!(ncu = (int *)vector1(nu + nv, sizeof(int))))
		return 0;
	ncv = ncu + nu;
	if (!bchgen(a, b, nu, nv, w, func)) {
		projUV *s;
		double *p;

		/* analyse coefficients and adjust until residual OK */
		cutres = res;
		for (i = 4; i ; --i) {
			eval(w, nu, nv, cutres, resid);
			if (resid->u < res && resid->v < res)
				break;
			cutres *= 0.5;
		}
		if (i <= 0) /* warn of too many tries */
			resid->u = - resid->u;
		/* apply cut resolution and set pointers */
		nru = nrv = 0;
		for (j = 0; j < nu; ++j) {
			ncu[j] = ncv[j] = 0; /* clear column maxes */
			for (s = w[j], i = 0; i < nv; ++i, ++s) {
				if (fabs(s->u) < cutres) /* < resolution ? */
					s->u = 0.;		/* clear coefficient */
				else
					ncu[j] = i + 1;	/* update column max */
				if (fabs(s->v) < cutres) /* same for v coef's */
					s->v = 0.;
				else
					ncv[j] = i + 1;
			}
			if (ncu[j]) nru = j + 1;	/* update row max */
			if (ncv[j]) nrv = j + 1;
		}
		if (power) { /* convert to bivariate power series */
			if (!bch2bps(a, b, w, nu, nv))
				goto error;
			/* possible change in some row counts, so readjust */
			nru = nrv = 0;
			for (j = 0; j < nu; ++j) {
				ncu[j] = ncv[j] = 0; /* clear column maxes */
				for (s = w[j], i = 0; i < nv; ++i, ++s) {
					if (s->u)
						ncu[j] = i + 1;	/* update column max */
					if (s->v)
						ncv[j] = i + 1;
				}
				if (ncu[j]) nru = j + 1;	/* update row max */
				if (ncv[j]) nrv = j + 1;
			}
			Ts = makeT(nru, nrv);
			if (Ts) {
				Ts->a = a;
				Ts->b = b;
				Ts->mu = nru - 1;
				Ts->mv = nrv - 1;
				Ts->power = 1;
				for (i = 0; i < nru; ++i) /* store coefficient rows for u */
					Ts->cu[i].m = ncu[i];
          if (Ts->cu[i].m) {
						if ((p = Ts->cu[i].c =
                 (double *)pj_malloc(sizeof(double) * ncu[i]))) {
              for (j = 0; j < ncu[i]; ++j) {
                *p++ = (w[i] + j)->u;
              }
            } else {
							goto error;
            }
          }
				for (i = 0; i < nrv; ++i) /* same for v */
					Ts->cv[i].m = ncv[i];
          if (Ts->cv[i].m) {
						if ((p = Ts->cv[i].c =
                 (double *)pj_malloc(sizeof(double) * ncv[i]))) {
              for (j = 0; j < ncv[i]; ++j) {
								*p++ = (w[i] + j)->v;
              }
            } else {
							goto error;
            }
          }
			}
		} else if ((Ts = makeT(nru, nrv))) {
			/* else make returned Chebyshev coefficient structure */
			Ts->mu = nru - 1; /* save row degree */
			Ts->mv = nrv - 1;
			Ts->a.u = a.u + b.u; /* set argument scaling */
			Ts->a.v = a.v + b.v;
			Ts->b.u = 1. / (b.u - a.u);
			Ts->b.v = 1. / (b.v - a.v);
			Ts->power = 0;
			for (i = 0; i < nru; ++i) /* store coefficient rows for u */
				Ts->cu[i].m = ncu[i];
        if (Ts->cu[i].m) {
					if ((p = Ts->cu[i].c =
               (double *)pj_malloc(sizeof(double) * ncu[i]))) {
						for (j = 0; j < ncu[i]; ++j)
							*p++ = (w[i] + j)->u;
          } else {
						goto error;
          }
        }
			for (i = 0; i < nrv; ++i) /* same for v */
				Ts->cv[i].m = ncv[i];
        if (Ts->cv[i].m) {
					if ((p = Ts->cv[i].c =
               (double *)pj_malloc(sizeof(double) * ncv[i]))) {
						for (j = 0; j < ncv[i]; ++j)
							*p++ = (w[i] + j)->v;
          } else {
						goto error;
          }
        }
		} else
			goto error;
	}
	goto gohome;
error:
	if (Ts) { /* pj_dalloc up possible allocations */
		for (i = 0; i <= Ts->mu; ++i)
			if (Ts->cu[i].c)
				pj_dalloc(Ts->cu[i].c);
		for (i = 0; i <= Ts->mv; ++i)
			if (Ts->cv[i].c)
				pj_dalloc(Ts->cv[i].c);
		pj_dalloc(Ts);
	}
	Ts = 0;
gohome:
	freev2((void **) w, nu);
	pj_dalloc(ncu);
	return Ts;
}
예제 #19
0
update_status ModulePlayer::Update(){


	if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_UP)
	{
		b2Vec2 vector(0.0f, -400.0f);
		ball.b->body->ApplyForceToCenter(vector, true);
	}

	if (App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_DOWN || App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_DOWN)
	{

		//App->audio->PlayFx(flipper1.fx);
	}

	if (App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_DOWN || App->input->GetKey(SDL_SCANCODE_LEFT) == KEY_REPEAT)
	{
		left_down_flipper.b->body->ApplyAngularImpulse(-2 * PI, true);
		left_middle_flipper.b->body->ApplyAngularImpulse(-2 * PI, true);
		left_up_flipper.b->body->ApplyAngularImpulse(-2 * PI, true);
	}

	if (App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_DOWN || App->input->GetKey(SDL_SCANCODE_RIGHT) == KEY_REPEAT)
	{

		right_down_flipper.b->body->ApplyAngularImpulse(2 * PI, true);
		right_middle_flipper.b->body->ApplyAngularImpulse(2 * PI, true);
		right_up_flipper.b->body->ApplyAngularImpulse(2 * PI, true);

	}

	float spring_push = 0.0f;
	if (App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_DOWN || App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_REPEAT)
	{
		spring_push += 175.0f;
		b2Vec2 vector1(0, spring_push);
		spring.b->body->ApplyForceToCenter(vector1, true);
	}
	else {
		spring_push = 0.0f;
	}

	if (App->input->GetKey(SDL_SCANCODE_DOWN) == KEY_UP)
	{
		//App->audio->PlayFx(spring.fx);
	}

	//////////////////////////BALL BLIT///////////////////////////////
	int x, y;
	ball.b->GetPosition(x, y);
	App->renderer->Blit(ball.image, x, y, NULL, 1.0f);

	//////////////////////////SPRING BLIT///////////////////////////////
	int x_spring, y_spring;
	spring.b->GetPosition(x_spring, y_spring);
	App->renderer->Blit(spring.image, x_spring, y_spring, NULL, 1.0f);

	//////////////////////////FLIPPERS BLIT///////////////////////////////
	int x_right_down, y_right_down;
	right_down_flipper.b->GetPosition(x_right_down, y_right_down);
	App->renderer->Blit(right_down_flipper.image, PIXEL_TO_METERS(x_right_down + 227), PIXEL_TO_METERS(y_right_down + 609), NULL, 1.0f, (right_down_flipper.b->body->GetAngle()), 0, 0);
	
	int x_left_down, y_left_down;
	left_down_flipper.b->GetPosition(x_left_down, y_left_down);
	App->renderer->Blit(left_down_flipper.image, PIXEL_TO_METERS(x_left_down + 200), PIXEL_TO_METERS(y_left_down + 609), NULL, 1.0f, (left_down_flipper.b->body->GetAngle()), 0, 0);
	
	int x_right_middle, y_right_middle;
	right_middle_flipper.b->GetPosition(x_right_middle, y_right_middle);
	App->renderer->Blit(right_middle_flipper.image, PIXEL_TO_METERS(x_right_middle + 345), PIXEL_TO_METERS(y_right_middle + 381), NULL, 1.0f, (right_middle_flipper.b->body->GetAngle()), 0, 0);
	
	int x_left_middle, y_left_middle;
	left_middle_flipper.b->GetPosition(x_left_middle, y_left_middle);
	App->renderer->Blit(left_middle_flipper.image, PIXEL_TO_METERS(x_left_middle + 115), PIXEL_TO_METERS(y_left_middle + 304), NULL, 1.0f, (left_middle_flipper.b->body->GetAngle()), 0, 0);
	
	int x_right_up, y_right_up;
	right_up_flipper.b->GetPosition(x_right_up, y_right_up); 
	App->renderer->Blit(right_up_flipper.image, PIXEL_TO_METERS(x_right_up + 337), PIXEL_TO_METERS(y_right_up + 135), NULL, 1.0f, (right_up_flipper.b->body->GetAngle()), 0, 0);
	
	int x_left_up, y_left_up;
	left_up_flipper.b->GetPosition(x_left_up, y_left_up); 
	App->renderer->Blit(left_up_flipper.image, PIXEL_TO_METERS(x_left_up + 282), PIXEL_TO_METERS(y_left_up + 132), NULL, 1.0f, (left_up_flipper.b->body->GetAngle()), 0, 0);
	

	return UPDATE_CONTINUE;
}
예제 #20
0
GMBoundingBox GMBoundingBox::CreateFromSphere(const GMBoundingSphere& sphere)
{
    GMVector3D vector1(sphere.radius);
    return GMBoundingBox(sphere.center - vector1, sphere.center + vector1);
}
예제 #21
0
void Weights::calculateWeights()
{
    mCoefficientNumber = (mTwoDim ? ((size_t)mPolynomeOrder + 1) * ((size_t)mPolynomeOrder + 1)
                                  :  (size_t)mPolynomeOrder + 1);
    size_t  ix, iy, i, j;
    int     x, y;

    // Determine coordinates of pixels to be sampled

    if (mTwoDim)
    {

        int iPolynomeOrder = (int) mPolynomeOrder; //lets avoid signed/unsigned comparison warnings
        int iHeight        = (int) height();
        int iWidth         = (int) width();

        for (y = -iPolynomeOrder; y < iHeight + iPolynomeOrder; ++y)
        {
            for (x = -iPolynomeOrder; x < iWidth + iPolynomeOrder; ++x)
            {
                if ((x < 0 && y < 0 && -x - y < iPolynomeOrder + 2)                             ||
                    (x < 0 && y >= iHeight && -x + y - iHeight < iPolynomeOrder + 1)            ||
                    (x >= iWidth && y < 0 && x - y - iWidth < iPolynomeOrder + 1)               ||
                    (x >= iWidth && y >= iHeight && x + y - iWidth - iHeight < iPolynomeOrder)  ||
                    (x < 0 && y >= 0 && y < iHeight) || (x >= iWidth  && y >= 0 && y < iHeight) ||
                    (y < 0 && x >= 0 && x < iWidth ) || (y >= iHeight && x >= 0 && x < iWidth))
                {
                    QPoint position(x,y);
                    mPositions.append(position);
                }
            }
        }
    }
    else
    {
        // In the one-dimensional case, only the y coordinate and y size is used.  */

        for (y = (-1)*mPolynomeOrder; y < 0; ++y)
        {
            QPoint position(0,y);
            mPositions.append(position);
        }

        for (y = (int) height(); y < (int) height() + (int) mPolynomeOrder; ++y)
        {
            QPoint position(0,y);
            mPositions.append(position);
        }
    }

    // Allocate memory.

    QScopedArrayPointer<double> matrix (new double[mCoefficientNumber * mCoefficientNumber]);
    QScopedArrayPointer<double> vector0(new double[mPositions.count() * mCoefficientNumber]);
    QScopedArrayPointer<double> vector1(new double[mPositions.count() * mCoefficientNumber]);

    // Calculate coefficient matrix and vectors

    for (iy = 0; iy < mCoefficientNumber; ++iy)
    {
        for (ix = 0; ix < mCoefficientNumber; ++ix)
        {
            matrix [iy* mCoefficientNumber+ix] = 0.0;
        }

        for (j = 0; j < (size_t)mPositions.count(); ++j)
        {
            vector0 [iy * mPositions.count() + j] = polyTerm (iy, mPositions.at(j).x(),
                                                    mPositions.at(j).y(), mPolynomeOrder);

            for (ix = 0; ix < mCoefficientNumber; ++ix)
            {
                matrix [iy* mCoefficientNumber + ix] += (vector0 [iy * mPositions.count() + j]
                                                        * polyTerm (ix, mPositions.at(j).x(), mPositions.at(j).y(), mPolynomeOrder));
            }
        }
    }

    // Invert matrix.

    matrixInv (matrix.data(), mCoefficientNumber);

    // Multiply inverse matrix with vector.

    for (iy = 0; iy < mCoefficientNumber; ++iy)
    {
        for (j = 0; j < (size_t)mPositions.count(); ++j)
        {
            vector1 [iy * mPositions.count() + j] = 0.0;

            for (ix = 0; ix < mCoefficientNumber; ++ix)
            {
                vector1 [iy * mPositions.count() + j] += matrix [iy * mCoefficientNumber + ix]
                        * vector0 [ix * mPositions.count() + j];
            }
        }
    }

    // Store weights

    // Allocate mPositions.count() matrices.
    mWeightMatrices = new double** [mPositions.count()];

    for (i=0 ; i < (size_t)mPositions.count() ; ++i)
    {
        // Allocate mHeight rows on each position
        mWeightMatrices[i] = new double*[mHeight];

        for (j=0 ; j < mHeight ; ++j)
        {
            // Allocate mWidth columns on each row
            mWeightMatrices[i][j] = new double[mWidth];
        }
    }

    for (y = 0; y < (int) mHeight; ++y)
    {
        for (x = 0; x < (int) mWidth; ++x)
        {
            for (j = 0; j < (size_t)mPositions.count(); ++j)
            {
                mWeightMatrices [j][y][x] = 0.0;

                for (iy = 0; iy < mCoefficientNumber; ++iy)
                {
                    mWeightMatrices [j][y][x] += vector1 [iy * mPositions.count() + j]
                                                 * polyTerm (iy, x, y, mPolynomeOrder);
                }

                mWeightMatrices [j][y][x] *= (double) mPositions.count();
            }
        }
    }
}