Example #1
0
//==============================================================================
// プレイヤー判定スキップ
//==============================================================================
void CGame::PushBackBattleArea(void)
{
	// 判定
	CPlayer*	pPlayerCurrent = nullptr;		// 対象オブジェクト
	for (int cntPlayer = 0; cntPlayer < PLAYER_MAX; ++cntPlayer)
	{
		// 対象オブジェクトを取得
		pPlayerCurrent = Player[cntPlayer];

		// 対象のステートを確認
		if (NeedsSkipPlayer(pPlayerCurrent))
		{
			continue;
		}

		// 押し戻し
		VECTOR3	vectorPlayerToCenter = Ground->Pos() - pPlayerCurrent->Pos();
		vectorPlayerToCenter.y = 0.0f;
		float	distanceFromCenter = vectorPlayerToCenter.x * vectorPlayerToCenter.x + vectorPlayerToCenter.y * vectorPlayerToCenter.y + vectorPlayerToCenter.z * vectorPlayerToCenter.z;
		if (distanceFromCenter > (RADIUS_AREA_BATTLE - RADIUS_PUSH_CHARACTER) * (RADIUS_AREA_BATTLE - RADIUS_PUSH_CHARACTER))
		{
			float	distancePushBack = sqrtf(distanceFromCenter) - (RADIUS_AREA_BATTLE - RADIUS_PUSH_CHARACTER);
			vectorPlayerToCenter.Normalize();
   pPlayerCurrent->AddPos(vectorPlayerToCenter * distancePushBack);
   pPlayerCurrent->AddDestPos(vectorPlayerToCenter * distancePushBack);
		}
	}
}
void IMainGame::mFunction_GameOverAnimationInit(BOOL hasPlayerWon)
{
	static std::default_random_engine rndEngine;
	static std::uniform_real_distribution<float> unitDist(-1.0f, 1.0f);

	if (hasPlayerWon)
	{
		mMainGameState = GameState::MainGame::GS_DeathExplode;
		//clear bullets
		mBulletMgr.KillAllBullet();
		//player WIN
		mIsPlayerVictorious = TRUE;
		//set camera to look at chicken
		gCamera.SetLookAt(mChickenBoss.GetPosition());
		//..explode fireworks
		for (int i = 0;i < 2000;++i)
		{
			//shoot direction (add some random offset)
			VECTOR3 dir = { unitDist(rndEngine),unitDist(rndEngine) ,unitDist(rndEngine) };
			//Y direction offset ( a whole column of bullets)
			dir.Normalize();
			mBulletMgr.SpawnBullet(mChickenBoss.GetPosition(), dir, VECTOR3(1, 0,0));
		}
	}
	else
	{
		mMainGameState = GameState::MainGame::GS_DeathExplode;
		//clear bullets
		mBulletMgr.KillAllBullet();
		//player LOSE
		mIsPlayerVictorious = FALSE;
		//..explode fireworks
		for (int i = 0;i < 2000;++i)
		{
			//shoot direction (add some random offset)
			VECTOR3 dir = { unitDist(rndEngine),unitDist(rndEngine) ,unitDist(rndEngine) };
			//Y direction offset ( a whole column of bullets)
			dir.Normalize();
			mBulletMgr.SpawnBullet(mPlayer.GetPosition(), dir, VECTOR3(1, 0, 0));
		}

		//move to another position to watch the explosion
		gCamera.SetPosition(mPlayer.GetPosition() + VECTOR3(300.0f,300.0f,300.0f));
		gCamera.SetLookAt(mPlayer.GetPosition());
	}
}
Example #3
0
//==============================================================================
// 着弾地点判定
//==============================================================================
void CGame::HitBulletToField(void)
{
	VECTOR3		nor;
	float		height;
	CBillboard* mark;
	VECTOR3		markPos;
	CBallistic* ballistic = Player[CManager::netData.charNum]->GetBallistic();
	CPolygon3D* landing = ballistic->GetLanding();

	for(int cnt = 0; cnt < MARK_MAX; ++cnt)
	{
		// 初期化
		nor = VECTOR3(0.0f,0.0f,0.0f);
		height = 0.0f;

		// マーク情報
		mark = ballistic->GetMark(cnt);
		markPos = mark->Pos();

		// 高さ判定
		height = Ground->GetHeight(markPos - VECTOR3(0.0f, BULLET_SIZE * 0.5f, 0.0f), &nor);
		if(height >= markPos.y)
		{
			// 回転を求める
			VECTOR3	vectorUp(0.0f, 1.0f, 0.0f);		// 上方向ベクトル
			VECTOR3	vectorAxisRotation;				// 回転軸
			float	rotation = 0.0f;				// 回転量
			VECTOR3::Cross(&vectorAxisRotation, nor, vectorUp);
			if (vectorAxisRotation.x < FLT_EPSILON && vectorAxisRotation.x > -FLT_EPSILON)
			{
				if (vectorAxisRotation.z < FLT_EPSILON && vectorAxisRotation.z > -FLT_EPSILON)
				{
					if (vectorAxisRotation.y < FLT_EPSILON && vectorAxisRotation.y > -FLT_EPSILON)
					{
						vectorAxisRotation.y = 1.0f;
					}
				}
			}
			vectorAxisRotation.Normalize();
			rotation = VECTOR3::Dot(nor, vectorUp);
			if (rotation <= 1.0f && rotation >= -1.0f)
			{
				rotation = RAD_TO_DEG * acosf(rotation);
			}
			else
			{
				rotation = 0.0f;
			}

			// 着弾マークに設定する
			landing->SetPos(VECTOR3(markPos.x, height + 0.5f, markPos.z));
			landing->SetAxisRotation(vectorAxisRotation);
			landing->SetRotationAxis(rotation);
			break;
		}
	}
}
Example #4
0
//==============================================================================
// オブジェクトの地形による押し戻し
//==============================================================================
void CGame::PushBackObjectByField(CObject* pObject, float offsetY)
{
	// 地形とのあたり判定
	VECTOR3	NormalGround;		// 地形の法線
	float	HeightGround;		// 地形の高さ
	HeightGround = Ground->GetHeight(pObject->Pos(), &NormalGround) + offsetY;

	//********************************************************
	// 2015_02_12 姿勢制御用の処理を追加 ここから
	//********************************************************
	// 回転を求める
	VECTOR3	vectorUp(0.0f, 1.0f, 0.0f);		// 上方向ベクトル
	VECTOR3	vectorAxisRotation;				// 回転軸
	float	rotation = 0.0f;				// 回転量
	VECTOR3::Cross(&vectorAxisRotation, NormalGround, vectorUp);
	if (vectorAxisRotation.x < FLT_EPSILON && vectorAxisRotation.x > -FLT_EPSILON)
	{
		if (vectorAxisRotation.z < FLT_EPSILON && vectorAxisRotation.z > -FLT_EPSILON)
		{
			if (vectorAxisRotation.y < FLT_EPSILON && vectorAxisRotation.y > -FLT_EPSILON)
			{
				vectorAxisRotation.y = 1.0f;
			}
		}
	}
	vectorAxisRotation.Normalize();
	rotation = VECTOR3::Dot(NormalGround, vectorUp);
	if (rotation <= 1.0f && rotation >= -1.0f)
	{
		rotation = RAD_TO_DEG * acosf(rotation);
	}
	else
	{
		rotation = 0.0f;
	}

	// キャラクターに設定する
 pObject->SetPosY(HeightGround);
 pObject->SetDestPosY(HeightGround);
	pObject->SetAxisRotation(vectorAxisRotation);
	pObject->SetRotationAxis(rotation);
	//********************************************************
	// 2015_02_12 姿勢制御用の処理を追加 ここまで
	//********************************************************
}
Example #5
0
int GetListOrder()
{
	register int order=0;

	glPushMatrix();
	glLoadIdentity();
	object.trackball.apply_inverse_transform();
	GLdouble m[16];
	glGetDoublev(GL_MODELVIEW_MATRIX, m);
	matrix4f tm(m[0], m[4], m[8],  m[12],
			   m[1], m[5], m[9],  m[13],
			   m[2], m[6], m[10], m[14],
			   m[3], m[7], m[11], m[15]);
	
	tm = tm.inverse();
	tm = tm.transpose();
	
	vec3f splat_normal(0, 0, 1);
	tm.mult_matrix_vec(splat_normal);
	splat_normal.normalize();

	float max = -1;
	float dm;
	for (int i=0; i<SORTED_LIST_NUM; i++){
		VECTOR3 s(splat_normal[0], splat_normal[1], splat_normal[2]);
		VECTOR3 t = viewer.eyes[i];
		t.Normalize();
		dm = dot(t, s);

		if (dm>max){
			order = i;
			max = dm;
		}
	}

	glPopMatrix();
	return order;
}
Example #6
0
//load seeds
float* get_grid_vec_data(int* grid_res)//get vec data at each grid point
{
	osuflow->GetFlowField()->getDimension(grid_res[0],grid_res[1],grid_res[2]);

	float * vectors=new float[grid_res[0]*grid_res[1]*grid_res[2]*3];
	for(int k=0; k<grid_res[2];k++)
	{
		for(int j=0; j<grid_res[1];j++)
		{
			for(int i=0; i<grid_res[0];i++)
			{
				VECTOR3 data;
				osuflow->GetFlowField()->at_vert(i,j,k,0,data);//t=0, static data
				int idx=i+j*grid_res[0]+k*grid_res[0]*grid_res[1];

				data.Normalize();
				vectors[idx*3+0]=data.x();
				vectors[idx*3+1]=data.y();
				vectors[idx*3+2]=data.z();
			}
		}
	}
	return vectors;
}
void IPlayer::mFunction_UpdateMovement(float timeElapsed)
{
	//--------------------------keyboard------------------------------
	VECTOR3 moveVector = { 0,0,0 };
	if (IS_KEY_DOWN('A'))
	{
		moveVector.x -= 1.0f;
	}
	if (IS_KEY_DOWN('D'))
	{
		moveVector.x += 1.0f;
	}
	if (IS_KEY_DOWN('W'))
	{
		moveVector.z += 1.0f;
	}
	if (IS_KEY_DOWN('S'))
	{
		moveVector.z -= 1.0f;
	}
	if (IS_KEY_DOWN(VK_LCONTROL))
	{
		moveVector.y -= 1.0f;
	}
	if (IS_KEY_DOWN(VK_SPACE))
	{
		moveVector.y += 1.0f;
	}


	//in case that camera moves faster if 3 directions has projection of speed
	moveVector.Normalize();
	moveVector *= (0.2f*timeElapsed);
	gCamera.fps_MoveRight(moveVector.x);
	gCamera.fps_MoveForward(moveVector.z);
	gCamera.fps_MoveUp(moveVector.y);

	//restrict player movement to a Box
	VECTOR3 camPos = gCamera.GetPosition();
	/*camPos = { Clamp(camPos.x,-c_halfMovementRestrictBoxWidth,c_halfMovementRestrictBoxWidth),
		Clamp(camPos.y,-c_halfMovementRestrictBoxWidth,c_halfMovementRestrictBoxWidth),
		Clamp(camPos.z,-c_halfMovementRestrictBoxWidth,c_halfMovementRestrictBoxWidth) };
	gCamera.SetPosition(camPos);*/

	//update Position
	mLastPos = mCurrentPos;
	mCurrentPos = camPos;


	//-------------------------------cursor movement----------------------------------
	static POINT lastCursorPos = { 0,0 };
	static POINT currentCursorPos = { 0,0 };
	static const int scrWidth = ::GetSystemMetrics(SM_CXSCREEN);
	static const int scrHeight = ::GetSystemMetrics(SM_CYSCREEN);
	lastCursorPos = currentCursorPos;
	::GetCursorPos(&currentCursorPos);

	//if cursor reach the boundary, go to another side
	if (currentCursorPos.x == scrWidth - 1)
	{
		::SetCursorPos(0, currentCursorPos.y);
		lastCursorPos = { 0,currentCursorPos.y };
		currentCursorPos = lastCursorPos;
	}
	else
	{
		if (currentCursorPos.x == 0)
		{
			::SetCursorPos(scrWidth - 1, currentCursorPos.y);
			lastCursorPos = { scrWidth - 1,currentCursorPos.y };
			currentCursorPos = lastCursorPos;
		}
	}

	if (currentCursorPos.y == scrHeight - 1)
	{
		::SetCursorPos(currentCursorPos.x, 0);
		lastCursorPos = { currentCursorPos.x,0 };
		currentCursorPos = lastCursorPos;
	}
	else
	{
		if (currentCursorPos.y == 0)
		{
			::SetCursorPos(currentCursorPos.x, scrHeight - 1);
			lastCursorPos = { currentCursorPos.x,scrHeight - 1 };
			currentCursorPos = lastCursorPos;
		}
	}

	//camera rotation
	int cursorDeltaX = currentCursorPos.x - lastCursorPos.x;
	int cursorDeltaY = (currentCursorPos.y - lastCursorPos.y);
	gCamera.RotateY_Yaw(0.0002f * cursorDeltaX*timeElapsed);
	gCamera.RotateX_Pitch(0.0002f* cursorDeltaY*timeElapsed);

}
Example #8
0
void ColliderSphereSphere::collide(std::vector<Contact> &vContacts)
{
  const Real contactTolerance = 0.00005;
	VECTOR3 &vel1 = body0_->velocity_;
	VECTOR3 &pos1 = body0_->com_;

	Sphere<Real> *pSphere = dynamic_cast<Sphere<Real>* >(body0_->shape_);
	Real rad1 = pSphere->getRadius();

	VECTOR3 &vel2 = body1_->velocity_;
	VECTOR3 &pos2 = body1_->com_;

	pSphere = dynamic_cast<Sphere<Real>* >(body1_->shape_);
	Real rad2 = pSphere->getRadius();

	Real dist = std::numeric_limits<Real>::max();

	//calc distance and relative orientation
	//we first need to calculate the relative velocity and
	//the velocity along the normal
	VECTOR3 vn = pos1 - pos2;
	vn.Normalize();

	//calculate the relative velocity
	VECTOR3 v12 = vel1 - vel2;
	
  //calculate the velocity along the normal
	Real velalongnormal = vn * v12;

  //calculate the distance
  dist = (pos2-pos1).mag() - rad1 - rad2;
  Real dist1 = fabs(vn*vel1);
  Real dist2 = fabs(vn*vel2);
  Real distpertime = (dist1+dist2)*world_->timeControl_->GetDeltaT();  
  
  if(velalongnormal < -0.005 && distpertime >= dist)
  //if(relativeNormalVelocity < -0.005)
  { 
      Contact contact;
      contact.m_dDistance  = dist;
      contact.m_vNormal    = vn;
      contact.m_vPosition0 = pos1;
      contact.m_vPosition1 = pos2;
      contact.m_pBody0     = body0_;
      contact.m_pBody1     = body1_;
      contact.id0 = contact.m_pBody0->iID_;
      contact.id1 = contact.m_pBody1->iID_;
      contact.vn           = velalongnormal;
      contact.m_dPenetrationDepth = std::min(0.0,dist);
      contact.m_iState     = CollisionInfo::TOUCHING;      
      //std::cout<<"Pre-contact normal velocity: "<<velalongnormal<<" colliding contact"<<std::endl;
      //std::cout<<"Pre-contact angular velocity0: "<<contact.m_pBody0->GetAngVel();
      //std::cout<<"Pre-contact angular velocity1: "<<contact.m_pBody1->GetAngVel();
      //std::cout<<"Pre-contact  velocity0: "<<contact.m_pBody0->m_vVelocity;
      //std::cout<<"Pre-contact  velocity1: "<<contact.m_pBody1->m_vVelocity;
      vContacts.push_back(contact);
  }
  else if(velalongnormal < 0.00001 && dist < contactTolerance)
  {
    Contact contact;
    contact.m_dDistance  = dist;
    contact.m_vNormal    = vn;
    contact.m_vPosition0 = pos1;
    contact.m_vPosition1 = pos2;
    contact.m_pBody0     = body0_;
    contact.m_pBody1     = body1_;    
    contact.id0          = contact.m_pBody0->iID_;
    contact.id1          = contact.m_pBody1->iID_;
    contact.vn           = velalongnormal;
    contact.m_iState     = CollisionInfo::TOUCHING;
    vContacts.push_back(contact);
  }
  else if(dist < 0.1*rad1)
  {
    Contact contact;
    contact.m_dDistance  = dist;
    contact.m_vNormal    = vn;
    contact.m_vPosition0 = pos1;
    contact.m_vPosition1 = pos2;
    contact.m_pBody0     = body0_;
    contact.m_pBody1     = body1_;    
    contact.id0          = contact.m_pBody0->iID_;
    contact.id1          = contact.m_pBody1->iID_;
    contact.vn           = velalongnormal;
    contact.m_iState     = CollisionInfo::TOUCHING;
    vContacts.push_back(contact);
  }
  else
  {
    return;
    Contact contact;
    contact.m_dDistance  = dist;
    contact.m_vNormal    = vn;
    contact.m_vPosition0 = pos1;
    contact.m_vPosition1 = pos2;
    contact.m_pBody0     = body0_;
    contact.m_pBody1     = body1_;
    contact.id0 = contact.m_pBody0->iID_;
    contact.id1 = contact.m_pBody1->iID_;
    contact.vn           = velalongnormal;
    contact.m_iState     = CollisionInfo::VANISHING_CLOSEPROXIMITY;      
    vContacts.push_back(contact);    
  }

}
void
CPointRendererSplat::_TraversePoints_Splat()
{
	printf( "Rendering particles with splatting ... \n" );
	
	// Initialize local variables
	const list<vtListSeedTrace*>* sl_list = (const list<vtListSeedTrace*>*)this->pDataSource;
	int iT=0;
	int bincount = 20;
	float *z = new float[2];
	int *offsetToBins = new int[bincount];
	int *pcountOfBins = new int[bincount];
	for(int i=0; i<bincount; i++)
	{
		offsetToBins[i] = 0;
		pcountOfBins[i] = 0;
	}

	// Get total number of particles to begin
	maxT = 0;
	particlecount = _CountParticles( &maxT, &numT );	
	printf("Total number of particles: %d\n", particlecount); 
	printf("Max Lifetime of a particle: %d\n", maxT ); 

	// Allocate memory for rendering quads
	if( triangleArray != NULL ) delete [] triangleArray;
	if( colorArray != NULL ) delete [] colorArray;
	if( normalArray != NULL ) delete [] normalArray;	

	triangleArray = new float[particlecount * 3 * 3];
	colorArray = new float[particlecount * 3 * 3];
	normalArray = new float[particlecount * 3 * 3];

	int binid = -1;
	float binlength = 0;
	if( sortEnabled == 1 )
	{
		// Get current modelview matrix
		_CurrentModelview();
	
		// Compute min-max z values in world space
		_ZMinMaxEyeSpace( z );
		printf("Z-range: [%f %f]\n", z[0], z[1]); 

		// Compute width of each bin
		binlength = (z[1] - z[0]) / (float)bincount;
	}

	// Scan through all points and asssign bins to them
	iT = 0;
	int offset = 0;	
	for(list<vtListSeedTrace*>::const_iterator
			pIter =  sl_list->begin(); 
		pIter!=sl_list->end(); 
		pIter++, iT++) 
	{
	    // Get next trace
		const vtListSeedTrace *trace = *pIter; 
		int l = trace->size();

		int iP = 0;
		VECTOR3 p, nextp;
		for(list<VECTOR3*>::const_iterator
				pnIter = trace->begin(); 
			pnIter!= trace->end(); 
			pnIter++, iP++) 
		{
			// Get next particle
			p = **pnIter; 

			// If this is not the last point of the trace,
			// Get subsequent particle
			if(iP != (l-1))
			{
				list<VECTOR3*>::const_iterator tmpIter = pnIter;
				tmpIter++;
				nextp = **tmpIter;
			}
			else
			{
				nextp.Set( p(0), p(1), p(2) );
			}

			//printf( "P:%f, %f, %f\n", p(0), p(1), p(2) );
			//printf( "nextP:%f, %f, %f\n", nextp(0), nextp(1), nextp(2) );
						
			// Get World Space Coordinates of the particle
			VECTOR4 p4( p );
			p4 = modelview * p4; 

			if( sortEnabled == 1 )
			{
				// Compute bin id
				binid = (int)floor( p4(2) - z[0]) / binlength;
				if( binid<0 ) binid = 0;
				if( binid>=bincount ) binid = bincount - 1;
	
				// Compute array offset for this particle
				offset = (offsetToBins[binid] + pcountOfBins[binid]);

				// Shift array 
				int nParticlesToShift = 0;
				for(int i=binid+1; i<bincount; i++)
					nParticlesToShift += pcountOfBins[i];			
				memmove( (triangleArray+offset*9+9), (triangleArray+offset*9), nParticlesToShift * 9 * sizeof(float) );
				memmove( (colorArray+offset*9+9), (colorArray+offset*9), nParticlesToShift * 9 * sizeof(float) );
			}
	
			VECTOR3 dir = nextp - p;
			//dir.Normalize();
			
			float frac = 0.5f;
			float highx = p(0) + dir(0)*frac;//*g;
			float highy = p(1) + dir(1)*frac;//*g;
			float highz = p(2) + dir(2)*frac;//*g;
			
			//printf( "P:%f, %f, %f\n", p(0), p(1), p(2) );
			//printf( "nextP:%f, %f, %f\n", nextp(0), nextp(1), nextp(2) );
			//printf( "high:%f, %f, %f\n", highx, highy, highz );

			triangleArray[offset*9] = p(0);		triangleArray[offset*9+1] = p(1)+0.1f;	triangleArray[offset*9+2] = p(2);
			triangleArray[offset*9+3] = p(0);	triangleArray[offset*9+4] = p(1)-0.1f;	triangleArray[offset*9+5] = p(2);
			triangleArray[offset*9+6] = highx;	triangleArray[offset*9+7] = highy;		triangleArray[offset*9+8] = highz;

			// Calculate Normals
			if( lightEnabled == 1 )
			{
				VECTOR3 e1( triangleArray[offset*9+3]-triangleArray[offset*9],
					       triangleArray[offset*9+4]-triangleArray[offset*9+1],
						   triangleArray[offset*9+5]-triangleArray[offset*9+2] );
				VECTOR3 e2( triangleArray[offset*9+6]-triangleArray[offset*9+3],
					       triangleArray[offset*9+7]-triangleArray[offset*9+4],
						   triangleArray[offset*9+8]-triangleArray[offset*9+5] );		
				VECTOR3 e3( triangleArray[offset*9]-triangleArray[offset*9+6],
					       triangleArray[offset*9+1]-triangleArray[offset*9+7],
						   triangleArray[offset*9+2]-triangleArray[offset*9+8] );	
				
				e1.Normalize();
				e2.Normalize();
				e3.Normalize();

				VECTOR3 norm( e3(1)*e1(2) - e3(2)*e1(1), 
							  e3(2)*e1(0) - e3(0)*e1(2),
							  e3(0)*e1(1) - e3(1)*e1(0) );
				norm.Normalize();
				normalArray[offset*9] = norm(0);
				normalArray[offset*9+1] = norm(1);
				normalArray[offset*9+2] = norm(2);

				norm.Set( e1(1)*e2(2) - e1(2)*e2(1), 
							  e1(2)*e2(0) - e1(0)*e2(2),
							  e1(0)*e2(1) - e1(1)*e2(0) );
				norm.Normalize();
				normalArray[offset*9+3] = norm(0);
				normalArray[offset*9+4] = norm(1);
				normalArray[offset*9+5] = norm(2);

				norm.Set( e2(1)*e2(2) - e3(2)*e2(1), 
							  e2(2)*e2(0) - e3(0)*e2(2),
							  e2(0)*e2(1) - e3(1)*e2(0) );
				norm.Normalize();
				normalArray[offset*9+6] = norm(0);
				normalArray[offset*9+7] = norm(1);
				normalArray[offset*9+8] = norm(2);

				//VECTOR3 norm( (e1(0) + e2(0)) / 2.0f, (e1(1) + e2(1)) / 2.0f, (e1(2) + e2(2)) / 2.0f );
				//norm.Normalize();
		

			}

			if( sortEnabled == 1 )
			{
				// Update bin frequency
				pcountOfBins[binid] += 1;
			
				// Update bin offsets
				for(int i=binid+1; i<bincount; i++)
					offsetToBins[i] += 1;
			}

			if( currentColorScheme == 0 )
			{
				// Assign color based on time
				float f = (float)iP / (float)maxT;
				float f1 = (float)(iP+1) / (float)maxT;
				f = 0.2f + 0.8f * f;
				f1 = 0.2f + 0.8f * f1;
				colorArray[offset*9] = f;	colorArray[offset*9+1] = 0.4f; colorArray[offset*9+2] = 1-f;
				colorArray[offset*9+3] = f;	colorArray[offset*9+4] = 0.4f; colorArray[offset*9+5] = 1-f;
				colorArray[offset*9+6] = f1;	colorArray[offset*9+7] = 0.4f; colorArray[offset*9+8] = 1-f1;
			}
			else if( currentColorScheme == 1 )
			{
				// Assign color based on Glyph direction
				dir.Normalize();
				dir[0] = 0.2f + 0.8f * dir(0);
				dir[1] = 0.2f + 0.8f * dir(1);
				dir[2] = 0.2f + 0.8f * dir(2);

				colorArray[offset*9] = dir(0);		colorArray[offset*9+1] = dir(1); colorArray[offset*9+2] = dir(2);
				colorArray[offset*9+3] = dir(0);	colorArray[offset*9+4] = dir(1); colorArray[offset*9+5] = dir(2);
				colorArray[offset*9+6] = dir(0);	colorArray[offset*9+7] = dir(1); colorArray[offset*9+8] = dir(2);
			}

			// Increment offset, if no sorting
			if( sortEnabled == 0 )	offset ++;
		
		}// end inner for: for each trace

	}// end outer for

	delete [] z;
	delete [] offsetToBins;
	delete [] pcountOfBins;
}
VECTOR4 IRenderPipeline3D::mFunction_VertexLighting(const VECTOR3& vPosW, const VECTOR3& vNormalW)
{
	//---------For Each Vertex, Perform Gouraud Shading------------

	VECTOR4 outColor = { 0.0f,0.0f,0.0f,1.0f };

	//traverse every lights
	for (UINT i = 0;i < c_maxLightCount;++i)
	{
		if (mDirLight[i].mIsEnabled == TRUE)
		{
			//normalized light vector
			VECTOR3 unitIncomingLightVec = mDirLight[i].mDirection;
			unitIncomingLightVec.Normalize();

			//vector from current vertex to Camera(Eye),used when compute specular
			VECTOR3 toEye = mCameraPos - vPosW;
			toEye.Normalize();

			//unit vertex normal
			VECTOR3 unitNormal = vNormalW;
			unitNormal.Normalize();

			//Ambient Color
			VECTOR3 currentAmbient = mMaterial.ambient* mDirLight[i].mAmbientColor * mMaterial.diffuse;

			//diffuse Factor (first make sure that angle <normal,light> is less than PI/2
			VECTOR3 currentDiffuse = { 0,0,0 };
			VECTOR3 currentSpecular = { 0,0,0 };

			float diffuseFactor = mDirLight[i].mDiffuseIntensity*Math::Vec3_Dot((-1)*unitIncomingLightVec, unitNormal);
			if (diffuseFactor > 0.0f)
			{
				//diffuse color (eye pos independent)
				currentDiffuse = diffuseFactor * mDirLight[i].mDiffuseColor;

				//if Texture Mapping is disabled, then use pure diffuse color of material
				if (m_pTexture == nullptr)
				{
					//component-wise
					currentDiffuse = currentDiffuse* mMaterial.diffuse;
				}
				//else the color will be passed down to pixel shader to multiply by 
				//per-pixel sample diffuse color


				//Specular color - eye position dependent
				/*VECTOR3 unitOutgoingLightVec = Vec3_Reflect(unitIncomingLightVec, unitNormal);
				float specFactor =
					mDirLight[i].mSpecularIntensity *
					pow(max(Vec3_Dot(unitOutgoingLightVec, toEye), 0.0f), mMaterial.specularSmoothLevel);

				//Vector3 * vector3 means component-wise mult , return vec3(x1*x2,y1*y2,z1*z2)
				currentSpecular = specFactor* mMaterial.specular * mDirLight[i].mSpecularColor;*/

			}

			VECTOR3 outColor3 = currentAmbient+currentDiffuse+currentSpecular;
			outColor += VECTOR4(outColor3.x, outColor3.y, outColor3.z, 0.0f);
		}
	}

	return outColor;
}
void IChickenMonster::mFunction_Fire(VECTOR3 shootDir)
{

	//different types of bullets have various cool down time
	const float fireTimeThreshold_common = 500.0f;
	const float fireTimeThreshold_rotate1 = 200.0f;
	const float fireTimeThreshold_rotate2 = 300.0f;
	const float fireTimeThreshold_explode = 2000.0f;
	static std::default_random_engine rndEngine;
	static std::uniform_real_distribution<float> dirDist1(-0.1f,0.1f);
	static std::uniform_real_distribution<float> dirDist2(-0.5f, 0.5f);
	static std::uniform_real_distribution<float> dirDist3(-1.0f, 1.0f);

	//update time counter
	attackPatternTimeCounter += gTimeElapsed;

	switch (mAttackState)
	{
	case CHICKEN_ATTACK_STATE_CHASE_PLAYER:
	{
		if (attackPatternTimeCounter > fireTimeThreshold_common)
		{
			shootDir.Normalize();

			for (int i = 0;i < 5;++i)
			{
				//shoot direction (add some random offset)
				VECTOR3 dir = shootDir + VECTOR3(dirDist1(rndEngine), dirDist1(rndEngine), dirDist1(rndEngine));
				m_pBulletMgr->SpawnBullet(mPos, dir*0.5f, VECTOR3(1.0f, 0, 0));
			}

			//time counter reset
			attackPatternTimeCounter = 0.0f;
		}
	}
	break;

	case CHICKEN_ATTACK_STATE_TYPE1:
	{
		if (attackPatternTimeCounter > fireTimeThreshold_rotate1)
		{
			shootDir.Normalize();

			for (int i = 0;i < 20;++i)
			{
				//shoot direction (add some random offset)
				VECTOR3 dir = { shootDir.x,0,shootDir.z };
				//Y direction offset ( a whole column of bullets)
				dir.y += ((-10 + i) * 0.1f);
				dir.Normalize();
				m_pBulletMgr->SpawnBullet(mPos, dir*0.5f, VECTOR3(1.0f, 0, 0));
			}

			//time counter reset
			attackPatternTimeCounter = 0.0f;
		}
		break;
	}

	case CHICKEN_ATTACK_STATE_TYPE2:
	{
		if (attackPatternTimeCounter > fireTimeThreshold_rotate2)
		{
			shootDir.Normalize();

			for (int i = 0;i < 20;++i)
			{
				VECTOR3 dir = shootDir + VECTOR3(dirDist2(rndEngine), dirDist2(rndEngine), dirDist2(rndEngine));
				m_pBulletMgr->SpawnBullet(mPos, dir, VECTOR3(0,1.0f, 0));
			}

			//time counter reset
			attackPatternTimeCounter = 0.0f;
		}
		break;
	}

	case CHICKEN_ATTACK_STATE_ULTIMATE_EXPLODE:
	{
		if (attackPatternTimeCounter > fireTimeThreshold_explode)
		{
			for (int i = 0;i < 1000;++i)
			{
				//shoot direction (add some random offset)
				VECTOR3 dir = { dirDist3(rndEngine),dirDist3(rndEngine) ,dirDist3(rndEngine) };
				//Y direction offset ( a whole column of bullets)
				dir.Normalize();
				m_pBulletMgr->SpawnBullet(mPos, dir, VECTOR3(0, 0, 1.0f));
			}
			attackPatternTimeCounter = 0.0f;
		}
		break;
	}

	default:
		break;
	}

}