예제 #1
0
파일: Wall.cpp 프로젝트: ArthurAlensky/Tank
void Wall::Init(float x, float y, float z, int numOfBricks, int brickTexture, Terrain * terrain)
{
	SetPosition(TVector(x,y,z));

	for(int j = 0; j < sqrt(numOfBricks); j++ )
	{
		for(int i = 0; i < sqrt(numOfBricks); i++)
		{
			Brick *brick = new Brick();
			bricks.push_back(brick);

			brick->setTexture(brickTexture);
			brick->setTerrain(terrain);

			brick->setPosition(TVector(x, y + brick->height * j, z + brick->length * i ));

			brick->setDirection(TVector(
				float((rand()%50)-26.0f)*10.0f,	// Random Speed On X Axis
				float((rand()%50)-25.0f)*10.0f,	// Random Speed On Y Axis
				float((rand()%50)-25.0f)*10.0f	// Random Speed On Z Axis
				));   

			brick->setGravity(TVector(
				0.0f,	// Set Horizontal Pull To Zero
				-0.8f,	// Set Vertical Pull Downward
				0.0f	// Set Pull On Z Axis To Zero
				));              
		}
	}
}
예제 #2
0
    void CPDRigid<T, D>::m_step()
    {
        T N_P = _P1.sum();

        TVector mu_x = _data.transpose() * _PT1 / N_P;
        TVector mu_y = _model.transpose() * _P1 / N_P;

        TMatrixD X_hat = _data - TMatrix(TVector(_N).setOnes() * mu_x.transpose());
        TMatrixD Y_hat = _model - TMatrix(TVector(_M).setOnes() * mu_y.transpose());

        TMatrix A = (_PX-_P1*mu_x.transpose()).transpose() * 
            (_model - TMatrix(TVector(_M).setOnes() * mu_y.transpose()));

        Eigen::JacobiSVD<TMatrix> svd(A, Eigen::ComputeThinU | Eigen::ComputeThinV);
        TMatrix U = svd.matrixU();
        TMatrix V = svd.matrixV();

        T det_uv = TMatrix(U*V.transpose()).determinant();
        TVector C(D);
        C.setIdentity();
        C(D-1) = det_uv;
        _paras._R = U * C.asDiagonal() * V.transpose();

        T s_upper = TMatrix(A.transpose()*_paras._R).trace();
        T s_lower = TMatrix(Y_hat.transpose()*_P1.asDiagonal()*Y_hat).trace();
        _paras._s =  s_upper / s_lower; 
            
        _paras._t = mu_x - _paras._s * _paras._R * mu_y;

        T tr_f = TMatrix(X_hat.transpose()*_PT1.asDiagonal()*X_hat).trace();
        T tr_b = TMatrix(A.transpose()*_paras._R).trace();
        _paras._sigma2 = (tr_f - _paras._s * tr_b) / (N_P * D);

    }
예제 #3
0
TScalar TWood::wood (const TScalar ktX,
                     const TScalar ktY,
                     const TScalar ktZ,
                     const TScalar ktRINGSCALE,
                     const TScalar ktGRAINFACTOR) const
{
  TVector  tQ;
  TScalar  tT;
  TScalar  tR;
  TScalar  tS;

  tT =  ktZ / ktRINGSCALE;
  tQ =  TVector (ktX * 8.0, ktY * 8.0, ktZ);
  tT += tNoise.noise (tQ) / 16.0;

  tQ =  TVector (ktX, tT, ktY + 12.93);
  tR =  ktRINGSCALE * tNoise.noise (tQ);
  tR -= tfloor (tR);
  tR =  0.2 + 0.8 * smoothstep (0.2, 0.55, tR) * (1.0 - smoothstep (0.75, 0.8, tR));
  
  tQ =  TVector (ktX * 128.0 + 5.0, ktZ * 8.0 - 3.0, ktY * 128.0 + 1);
  tS =  ktGRAINFACTOR * (1.3 - tNoise.noise (tQ)) + (1.0 - ktGRAINFACTOR);
  
  return tR * tS * tS;

}  /* wood */
예제 #4
0
// ----------------------------------------------------------------------
// CRainfall::ResetParticle
// Implementation of CParticleEngine::ResetParticle(GLint)
// ----------------------------------------------------------------------
//
void CRainfall::ResetParticle(GLint aIndex)
	{

	TParticle & Particle = iParticles[aIndex];

    Particle.iPosition = TVector( iWidth * (Random() - 0.5f), 0, iDepth * (Random() - 0.5f)) + iPosition;
    Particle.iVelocity = TVector( 0, randrange( -40.f, -20.f, iSeed ), 0);
	}
예제 #5
0
CollisionBox::CollisionBox()
{
	totalTimeLife = 0;
	remainTimeLife =0;
	xNormal = TVector(1.0, 0.0, 0.0);
	yNormal = TVector(0.0, 1.0, 0.0);
	zNormal = TVector(0.0, 0.0, 1.0);
	angleWithX = 0.0;
	life = false;
}
예제 #6
0
TVector CCharacter::GetGlobalGravity() const
{
	if (GetGroundEntity())
		return TVector();

	return BaseClass::GetGlobalGravity();
}
예제 #7
0
TVector CCharacterCamera::GetThirdPersonCameraPosition()
{
	CCharacter* pCharacter = m_hCharacter;
	if (!pCharacter)
		return TVector(10, 0, 0);

	TVector vecEyeHeight = pCharacter->GetUpVector() * pCharacter->EyeHeight();

	TMatrix mView = TMatrix(pCharacter->GetThirdPersonCameraAngles(), TVector());
	TVector vecThird = pCharacter->GetGlobalTransform().GetTranslation() + vecEyeHeight;
	vecThird -= Vector(mView.GetForwardVector()) * m_flBack;
	vecThird += Vector(mView.GetUpVector()) * m_flUp;
	vecThird += Vector(mView.GetLeftVector()) * m_flSide;

	return vecThird;
}
예제 #8
0
TVector CCamera::GetCameraPosition()
{
	if (m_bFreeMode)
		return m_vecFreeCamera;

	return TVector(30, 30, 30);
}
예제 #9
0
TVector CCamera::GetCameraTarget()
{
	if (m_bFreeMode)
		return m_vecFreeCamera + AngleVector(m_angFreeCamera);

	return TVector(0,0,0);
}
예제 #10
0
void AirPlane::changeVelocityDirection(float newAngleWithX)
{
	this->angleWithX = newAngleWithX;
	float radAngle = M_PI*angleWithX/180.0;
	collisionBox.updateCollisionBoxAngle(angleWithX);
	this->velocity = TVector(velocityMag*cos(radAngle), 0.0, -velocityMag*sin(radAngle));
	collisionBox.updateCollisionBoxAngle(angleWithX);
}
예제 #11
0
/* initialize variables */
void InitVars() {
  int i;
  
  /* create outer cylinder */
  cyl1._Position = TVector(0,0,0);
  cyl1._Axis = TVector(0,0,1);
  cyl1._Radius = board_r - ball_r;

  /* Set initial positions and velocities of balls */
  ball_count = 3;
  ball_vel[0] = veloc;
  ball_pos[0] = TVector(-2,-1,ball_r);
  ball_vel[1] = veloc;
  ball_pos[1] = TVector(1,2,ball_r);
  ball_vel[2] = veloc;
  ball_pos[2] = TVector(2,-2,ball_r);
}
예제 #12
0
TVector CCharacterCamera::GetThirdPersonCameraDirection()
{
	CCharacter* pCharacter = m_hCharacter;

	if (!pCharacter)
		return TVector();

	return AngleVector(pCharacter->GetThirdPersonCameraAngles());
}
예제 #13
0
void AirPlane::startMove(TVector initPosition, float velocityMag, float angleWithX)
{
	this->angleWithX = angleWithX;
	this->velocityMag = velocityMag;
	float radAngle = M_PI*angleWithX/180.0;
	collisionBox.setTimeLife(2);
	AutoWarObject::startMove(initPosition, TVector(velocityMag*cos(radAngle), 0.0, -velocityMag*sin(radAngle)));
	collisionBox.updateCollisionBoxAngle(angleWithX);
}
예제 #14
0
파일: main.cpp 프로젝트: demonh1/tarkanoid
BOOL ProcessKeys()
{

	if (keys[VK_LEFT] && paddle.position.X() > -1*PLANE_POS+PADDLE_LENGTH)
	{
		paddle.position += TVector(-2,0,0);
		paddle.point[0] = TVector(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,0);
		paddle.point[1] = TVector(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,0);
		paddle.point[2] = TVector(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,0);
		paddle.point[3] = TVector(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,0);
	}
	if (keys[VK_RIGHT]&& paddle.position.X() < PLANE_POS-PADDLE_LENGTH)
	{
		paddle.position += TVector(2,0,0);
		paddle.point[0] = TVector(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,0);
		paddle.point[1] = TVector(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,0);
		paddle.point[2] = TVector(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,0);
		paddle.point[3] = TVector(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,0);
	}
	if (keys[VK_F3]) 
	{   
		Time += 0.1;
		keys[VK_F3] = FALSE;
	}
	if (keys[VK_F2])
	{
		if(Time > 0.1)
			Time -= 0.1;
		keys[VK_F2] = FALSE;
	}
	if (keys[VK_F11])						
	{
		keys[VK_F11] = FALSE;					
		KillGLWindow();						
		fullscreen =! fullscreen;	
		// Recreate Our OpenGL Window
		if (!CreateGLWindow("Arkanoid",640,480,16,fullscreen))
			return 0;						
	}

	return 1;
}
예제 #15
0
int ProcessKeys()
{
	if (keys[VK_UP])    pos+=TVector(0,0,-10);
	if (keys[VK_UP])    pos+=TVector(0,0,10);
	if (keys[VK_LEFT])  camera_rotation+=10;
	if (keys[VK_RIGHT]) camera_rotation-=10;
	if (keys[VK_ADD])
	{
		Time+=0.1;
        keys[VK_ADD]=FALSE;
	}
	if (keys[VK_SUBTRACT])
	{
		Time-=0.1;
        keys[VK_SUBTRACT]=FALSE;
	}
	if (keys[VK_F3]) 
	{   
		sounds^=1;
        keys[VK_F3]=FALSE;
	}
	if (keys[VK_F2])
	{
	    hook_toball1^=1;
	    camera_rotation=0;
		keys[VK_F2]=FALSE;
	}
	if (keys[VK_F1])						// Is F1 Being Pressed?
	{
		keys[VK_F1]=FALSE;					// If So Make Key FALSE
		KillGLWindow();						// Kill Our Current Window
		fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
		// Recreate Our OpenGL Window
		if (!CreateGLWindow("Magic Room",640,480,16,fullscreen))
		{
			return 0;						// Quit If Window Was Not Created
		}
	}

	return 1;
}
예제 #16
0
    void CPDNRigid<Scalar, Dim>::constructG()
    {
        G_ = MatrixType<Scalar, Dim>::Matrix::Zero(this->M_, this->M_);

        for (size_t i = 0; i < this->M_; i ++)
        {
            for (size_t j = 0; j < this->M_; j ++)
            {
                G_(i, j) = exp(-TVector(this->model_.row(i)-this->model_.row(j)).squaredNorm()/(2*paras_.beta_*paras_.beta_));
            }
        }
    }
예제 #17
0
    void CPDNRigid<T, D>::constructG()
    {
        _G = TMatrix::Zero(_M, _M);

        for (size_t i = 0; i < _M; i ++)
        {
            for (size_t j = 0; j < _M; j ++)
            {
                _G(i, j) = exp(-TVector(_model.row(i)-_model.row(j)).squaredNorm()/(2*_paras._beta*_paras._beta));
            }
        }
    }
예제 #18
0
    void CPDRigid<T, D>::e_step()
    {
        if (!_fgt)
        {
            correspondences();
            _P1 = _corres * TVector(_N).setOnes();
            _PT1 = _corres.transpose() * TVector(_M).setOnes();
            _PX = _corres * _data;

        }
        else
        {
            T c = pow((2*M_PI*_paras._sigma2), 0.5*D) * (_w/(1-_w)) * (T(_M)/_N);
            TMatrix KT1 = fgt<T, D>(_T, _data, TVector(_M).setOnes(), sqrt(2*_paras._sigma2), _fgt_eps);
            TVector a = (TVector(KT1) + c*TVector(_N).setOnes()).cwiseInverse();

            TMatrix aX = TMatrix::Zero(_N, D);
            for (size_t i = 0; i < D; i ++)
            {
                aX.col(i) = _data.col(i).cwiseProduct(a);
            }

            _PT1 = TVector(_N).setOnes() - c * a;
            _P1 = fgt<T, D>(_data, _T, a, sqrt(2*_paras._sigma2), _fgt_eps);
            _PX = fgt<T, D>(_data, _T, aX, sqrt(2*_paras._sigma2), _fgt_eps);
        }
    }
예제 #19
0
    void CPDNRigid<Scalar, Dim>::e_step()
    {
        if (!this->fgt_)
        {
            correspondences();
            this->P1_ = this->corres_ * TVector(this->N_).setOnes();
            this->PT1_ = this->corres_.transpose() * TVector(this->M_).setOnes();
            this->PX_ = this->corres_ * this->data_;
        }
        else
        {
            Scalar c = pow((2*M_PI*paras_.sigma2_), 0.5*Dim) * (this->w_/(1-this->w_)) * (Scalar(this->M_)/this->N_);
            TMatrix KT1 = fgt<Scalar, Dim>(this->T_, this->data_, TVector(this->M_).setOnes(), sqrt(2*paras_.sigma2_), this->fgt_eps_);
            TVector a = (TVector(KT1) + c*TVector(this->N_).setOnes()).cwiseInverse();

            TMatrix aX = MatrixType<Scalar, Dim>::Matrix::Zero(this->N_, Dim);
            for (size_t i = 0; i < Dim; i ++)
            {
                aX.col(i) = this->data_.col(i).cwiseProduct(a);
            }

            this->PT1_ = TVector(this->N_).setOnes() - c * a;
            this->P1_ = fgt<Scalar, Dim>(this->data_, this->T_, a, sqrt(2*paras_.sigma2_), this->fgt_eps_);
            this->PX_ = fgt<Scalar, Dim>(this->data_, this->T_, aX, sqrt(2*paras_.sigma2_), this->fgt_eps_);
        }
    }
예제 #20
0
파일: Tmatrix.cpp 프로젝트: elf11/GPGPU
TVector &TMatrix33::multiply(const TMatrix33 &m1, const TVector &v, TVector &result) {

	result = TVector(

   	m1._Mx[0][0]*v.X() + m1._Mx[0][1]*v.Y() + m1._Mx[0][2]*v.Z(),

		m1._Mx[1][0]*v.X() + m1._Mx[1][1]*v.Y() + m1._Mx[1][2]*v.Z(),

		m1._Mx[2][0]*v.X() + m1._Mx[2][1]*v.Y() + m1._Mx[2][2]*v.Z() );

	return result;

}
예제 #21
0
파일: tvector.cpp 프로젝트: csko/Pool
TVector::TVector(const TRay &ray1, const TRay &ray2) {

	TVector point1, point2;

	if (ray1.adjacentPoints(ray2, point1, point2))

		*this = (point1 + point2)*0.5;

	else

		*this = TVector();

}
예제 #22
0
void CollisionBox::updateCollisionBoxAngle(float angleWithX)
{
	if(life)
	{
		this->angleWithX = angleWithX;
		
		radAngle =  M_PI*angleWithX/180.0;

		xNormal = TVector(cos(radAngle), 0.0, -sin(radAngle));
		yNormal = TVector(0.0, 1.0, 0.0);
		zNormal = TVector(sin(radAngle), 0.0, cos(radAngle));
		
		collisionSquare[0].updateCollisionSquare(yNormal, center + yNormal*yHeight);
		collisionSquare[1].updateCollisionSquare(-yNormal, center - yNormal*yHeight);

		collisionSquare[2].updateCollisionSquare(-xNormal, center - xNormal*xLong);
		collisionSquare[3].updateCollisionSquare(xNormal, center + xNormal*xLong);

		collisionSquare[4].updateCollisionSquare(-zNormal, center - zNormal*zWidth);
		collisionSquare[5].updateCollisionSquare(zNormal, center + zNormal*zWidth);	
	}
}
예제 #23
0
// -----------------------------------------------------------------------------
// CRain::DrawPlane
// Draws the ground plane.
// -----------------------------------------------------------------------------
//
void CRain::DrawPlane()
	{
    glBindTexture(  GL_TEXTURE_2D, iGrassTexture.iID );
    glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST );

    glLoadIdentity();
	T3DModel::MakeWorldViewMatrix(iCamera, TVector(0.0f, 0.0f, 0.0f));
	glScalef( 1000, 0, 1000 );

    glVertexPointer( 3, GL_BYTE, 0, planeVertices );
	glTexCoordPointer( 2, GL_BYTE, 0, planeTextureCoords );
    glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles );
	}
예제 #24
0
파일: game.cpp 프로젝트: fidy1995/Quidditch
bool const Game::stopped() const {
	for (int i = 0; i < 7; i++) {
		if (spheres[i]->getVelocity() != TVector(0, 0, 0)) {
			return false;
		}
	}
	for (int i = 7; i < 13; i++) {
		if (spheres[i]->getVelocity().model() - 0.125 > 0.00001
			|| spheres[i]->getVelocity().model() - 0.125 < -0.00001) {
			return false;
		}
	}
	return true;
}
예제 #25
0
파일: main.cpp 프로젝트: ArthurAlensky/Tank
void myInit()
{

	glActiveTexture(GL_TEXTURE0);
	//make the background look like the sky
	float blue[4] = {0.5,0.5,1.0,0.0};
	glClearColor(0.5, 0.5, 1.0, 0.0);

	glShadeModel(GL_SMOOTH);

	
	glEnable(GL_FOG);
	glFogfv(GL_FOG_COLOR,blue);
	glFogf(GL_FOG_MODE, GL_EXP2);
	glFogf(GL_FOG_START, 200);
	glFogf(GL_FOG_END, 1000);
	glFogf(GL_FOG_DENSITY, gFogDensity);

	//initial terrain
	myTerrain.initializeTerrain("../Data/Texture/Terrain/sand.tga", "../Data/Texture/Terrain/cactus.tga");

	//initial ground collision square
	groundCollSquare.setParameters(TVector(0.0, 1.0, 0.0), gCenterPoint);


	//initial tank
	tankHeightPos = myTerrain.GetHeight(gCenterPoint.X()+100.0, gCenterPoint.Z());

	myTank.setParameters("T-90.3DS", "../T-90/",TVector(gCenterPoint.X()-600.0, tankHeightPos + 9.0, gCenterPoint.Z()-20), 0.0, &myTerrain, &collisionBoxArray, &wall);
	myTank.initTank();	

	unsigned int brickTexture;

	createTexture("../Data/Texture/Brick/brick.bmp", brickTexture);

	wall.Init(myTank.getPosition().X() + 50, myTank.getPosition().Y()-8, myTank.getPosition().Z() + 20, NUM_BRICKS, brickTexture, &myTerrain);
}
예제 #26
0
void CollisionBox::setParameters(TVector center, float angleWithX, float xLong, float yHeight, float zWidth)
{
	this->center = center;
	this->angleWithX = angleWithX;
	this->xLong = xLong;
	this->yHeight = yHeight;
	this->zWidth = zWidth;
	
	radAngle = M_PI*angleWithX/180.0;

	xNormal = TVector(cos(radAngle), 0.0, -sin(radAngle));
	yNormal = TVector(0.0, 1.0, 0.0);
	zNormal = TVector(sin(radAngle), 0.0, cos(radAngle));


	collisionSquare[0].setParameters(yNormal,  center + yNormal*yHeight );
	collisionSquare[1].setParameters(-yNormal, center - yNormal*yHeight);

	collisionSquare[2].setParameters(-xNormal, center - xNormal*xLong);
	collisionSquare[3].setParameters(xNormal, center + xNormal*xLong);

	collisionSquare[4].setParameters(-zNormal, center - zNormal*zWidth);
	collisionSquare[5].setParameters(zNormal, center + zNormal*zWidth);	
}
예제 #27
0
//
//  Attempt to process the specification for a vector.  
//  If there is an error, return true.
//
bool TSubdiv::addVertex (const string& rktVALUE)
{
  Byte    bMatched;
  char    acName[256];
  float   fX, fY, fZ;

  bMatched = sscanf (rktVALUE.c_str(), " %255s < %f , %f , %f > ", 
                     acName, &fX, &fY, &fZ); 
  if ( bMatched != 4 )
    return true;

  tPoints[acName] = new TSubdivVert (rktVALUE, TVector (fX, fY, fZ));

  return false;

}  /* addVertex() */
예제 #28
0
TPolyhedron *TMaze::NewCrystal() // Creates new crystal
{
	TPolyhedron *p = new TPolyhedron("Crystal.Dat");

	Assert(p);

	// New destination coordinate
	Dest = Random();
	TVector v = Maze.Vector(Dest.CrdX(), Dest.CrdY(), Dest.CrdZ());

	*p *=
	 TPivotScale(0.2, 0.2, 0.2, TVector()) *
	 TShift(v.CrdX(), v.CrdY(), v.CrdZ());

	return p;
}
예제 #29
0
void CSPCharacter::StandOnNearestPlanet()
{
	CPlanet* pPlanet = GetNearestPlanet(FINDPLANET_ANY);
	if (!pPlanet)
		return;

	CScalableVector vecPlanetOrigin = pPlanet->GetGlobalOrigin();
	CScalableVector vecCharacterOrigin = GetGlobalOrigin();
	CScalableVector vecCharacterDirection = (vecCharacterOrigin - vecPlanetOrigin).Normalized();

	SetMoveParent(pPlanet);

	TVector vecPoint, vecNormal;
	pPlanet->CollideLocal(vecCharacterDirection * (pPlanet->GetRadius()*2.0f), TVector(), vecPoint, vecNormal);

	SetLocalOrigin(vecPoint);
}
예제 #30
0
// -----------------------------------------------------------------------------
// CRain::DrawTree
// Draws a tree.
// -----------------------------------------------------------------------------
//
void CRain::DrawTree(GLfloat aX, GLfloat aZ)
	{
    glLoadIdentity();

	//Turns the tree so that it always faces the camera.
	T3DModel::MakeBillboardWorldViewMatrix(iCamera, TVector(aX, 0.0f, aZ));
	glScalef( 10, 30, 10 );

    glBindTexture(  GL_TEXTURE_2D, iTreeTexture.iID );
    glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST );

	glVertexPointer( 3, GL_BYTE, 0, treeVertices );
	glTexCoordPointer( 2, GL_BYTE, 0, treeTextureCoords );
    glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, treeTriangles );

	}