Пример #1
0
bool CBubble::bInitialize( float32 i_fRadius, uint32 i_iStacks, uint32 i_iSlices )
{
	CGraphics *pGraphics = m_pParent->pGetParent()->pGetGraphics();
	CMuli3DDevice *pM3DDevice = pGraphics->pGetM3DDevice();

	if( FUNC_FAILED( pM3DDevice->CreateVertexFormat( &m_pVertexFormat, VertexDeclaration, sizeof( VertexDeclaration ) ) ) )
		return false;

	// Construct a sphere
	m_iNumVertices = i_iStacks * i_iSlices * 4;
	m_iNumPrimitives = i_iStacks * i_iSlices * 2;

	if( FUNC_FAILED( pM3DDevice->CreateVertexBuffer( &m_pVertexBuffer, sizeof( vertexformat ) * m_iNumVertices ) ) )
		return false;

	if( FUNC_FAILED( pM3DDevice->CreateIndexBuffer( &m_pIndexBuffer, sizeof( uint16 ) * m_iNumPrimitives * 3, m3dfmt_index16 ) ) )
		return false;

	vertexformat *pDestVertices = 0;
	if( FUNC_FAILED( m_pVertexBuffer->GetPointer( 0, (void **)&pDestVertices ) ) )
		return false;

	uint16 *pDestIndices = 0;
	if( FUNC_FAILED( m_pIndexBuffer->GetPointer( 0, (void **)&pDestIndices ) ) )
		return false;

	const float32 fStepV = 1.0f / (float32)i_iStacks;
	const float32 fStepU = 1.0f / (float32)i_iSlices;

	uint32 iCurVertex = 0;

	float32 fV = 0.0f;
	for( uint32 i = 0; i < i_iStacks; ++i, fV += fStepV )
	{
		float32 fNextV = fV + fStepV;

		float32 fU = 0.0f;
		for( uint32 j = 0; j < i_iSlices; ++j, fU += fStepU )
		{
			float32 fNextU = fU + fStepU;
			
			// create a quad
			// 0 -- 1
			// |    |
			// 2 -- 3

			float32 x[4], y[4], z[4];

			x[0] = i_fRadius * sinf( fV * M3D_PI ) * cosf( fU * 2.0f * M3D_PI );
			z[0] = i_fRadius * sinf( fV * M3D_PI ) * sinf( fU * 2.0f * M3D_PI );
			y[0] = i_fRadius * cosf( fV * M3D_PI );

			x[1] = i_fRadius * sinf( fV * M3D_PI ) * cosf( fNextU * 2.0f * M3D_PI );
			z[1] = i_fRadius * sinf( fV * M3D_PI ) * sinf( fNextU * 2.0f * M3D_PI );
			y[1] = i_fRadius * cosf( fV * M3D_PI );

			x[2] = i_fRadius * sinf( fNextV * M3D_PI ) * cosf( fU * 2.0f * M3D_PI );
			z[2] = i_fRadius * sinf( fNextV * M3D_PI ) * sinf( fU * 2.0f * M3D_PI );
			y[2] = i_fRadius * cosf( fNextV * M3D_PI );

			x[3] = i_fRadius * sinf( fNextV * M3D_PI ) * cosf( fNextU * 2.0f * M3D_PI );
			z[3] = i_fRadius * sinf( fNextV * M3D_PI ) * sinf( fNextU * 2.0f * M3D_PI );
			y[3] = i_fRadius * cosf( fNextV * M3D_PI );

			pDestVertices->vPosition = vector3( x[0], y[0], z[0] );
			pDestVertices->vTex = vector2( fU, fV );
			pDestVertices++;

			pDestVertices->vPosition = vector3( x[1], y[1], z[1] );
			pDestVertices->vTex = vector2( fNextU, fV );
			pDestVertices++;

			pDestVertices->vPosition = vector3( x[2], y[2], z[2] );
			pDestVertices->vTex = vector2( fU, fNextV );
			pDestVertices++;

			pDestVertices->vPosition = vector3( x[3], y[3], z[3] );
			pDestVertices->vTex = vector2( fNextU, fNextV );
			pDestVertices++;

			*pDestIndices++ = iCurVertex;
			*pDestIndices++ = iCurVertex + 1;
			*pDestIndices++ = iCurVertex + 2;

			*pDestIndices++ = iCurVertex + 1;
			*pDestIndices++ = iCurVertex + 3;
			*pDestIndices++ = iCurVertex + 2;

			iCurVertex += 4;
		}
	}

	m_pVertexShader = new CBubbleVS;
	m_pPixelShader = new CBubblePS;

	// Load textures ...
	CResManager *pResManager = m_pParent->pGetParent()->pGetResManager();
	m_hRainbowFilm = pResManager->hLoadResource( "rainbowfilm_smooth.png" );
	if( !m_hRainbowFilm )
		return false;

	m_hEnvironment = pResManager->hLoadResource( "room.cube" );
	if( !m_hEnvironment )
		return false;

	return true;
}
Пример #2
0
my2Darray_vector2::my2Darray_vector2(int row_, int col_): row(row_), col(col_){
	data.clear();
	for(int i=0; i<row; i++)
		for(int j=0; j<col; j++)
			data.push_back(vector2());
}
Пример #3
0
vector2 vector2::operator+(vector2 & b){
	return vector2(x+b.x, y+b.y);
}
Пример #4
0
void SelectSpider::PlayerSelect(){
	if (select){
		Graphic::GetInstance().DrawTexture(TEXTURE_ID::THREAD_BACK_TEXTURE,
			vector2(pos.x, pos.y - 40.0f),
			vector2(0.6f, 0.6f),
			red == true ? D3DXCOLOR(1, 0, 0, 1.0f) : D3DXCOLOR(0, 0, 1, 1),
			vector2(0.5f, 0.5f),
			0.0f,
			0.0f,
			1,
			1.0f);

		Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
			vector2(pos.x - 245.0f, pos.y + 50.0f),
			vector2(0.20f, 0.35f),
			0.6f,
			"L1",
			vector3(1, 1, 1),
			1,
			true);

		Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
			vector2(pos.x + 260.0f, pos.y + 50.0f),
			vector2(0.20f, 0.35f),
			0.6f,
			"R1",
			vector3(1, 1, 1),
			1,
			true);
	}
	Graphic::GetInstance().DrawTexture(TEXTURE_ID::MENU_ARROW_LEFT_TEXTURE,
		vector2(pos.x - 250.0f, pos.y),
		vector2(1.0f, 1.0f)* (select == true ? 1.5f : 1.0f),
		D3DXCOLOR(1, 1, 1, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);

	Graphic::GetInstance().DrawTexture(TEXTURE_ID::MENU_ARROW_RIGHT_TEXTURE,
		vector2(pos.x + 250.0f, pos.y),
		vector2(1.0f, 1.0f)* (select == true ? 1.5f : 1.0f),
		D3DXCOLOR(1, 1, 1, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);
	TEXTURE_ID tID;
	TEXTURE_ID whitetID;
	if (spiderSelect->ReturnTarantula()){
		if (red){
			tID = TEXTURE_ID::TARENTULA_RED_TEXTURE;
			whitetID = TEXTURE_ID::TARENTULA_WHITE_R_TEXTURE;
		}
		else{
			tID = TEXTURE_ID::TARENTULA_BLUE_TEXTURE;
			whitetID = TEXTURE_ID::TARENTULA_WHITE_L_TEXTURE;
		}
	}
	else{
		if (red){
			tID = TEXTURE_ID::NEPHILA_RED_TEXTURE;
			whitetID = TEXTURE_ID::NEPHILA_WHITE_R_TEXTURE;
		}
		else{
			tID = TEXTURE_ID::NEPHILA_BLUE_TEXTURE;
			whitetID = TEXTURE_ID::NEPHILA_WHITE_L_TEXTURE;
		}
	}
	Graphic::GetInstance().DrawTexture(whitetID,
		vector2(pos.x, pos.y),
		vector2(1.0f, 1.0f) * (select == true ? 1.5f : 1.0f),
		spiderSelect->ReturnMyPlayerParam(playerNum) == SelectPlayerParam::P1 ?
		red ?
		D3DXCOLOR(1, 0, 0, 1) : D3DXCOLOR(0, 0, 1, 1) :
		spiderSelect->ReturnMyPlayerParam(playerNum) == SelectPlayerParam::NONE ?
		D3DXCOLOR(1, 1, 1, 1) : D3DXCOLOR(0, 1, 0, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);

	Graphic::GetInstance().DrawTexture(tID,
		vector2(pos.x, pos.y),
		vector2(1.0f, 1.0f)* (select == true ? 1.5f : 1.0f),
		D3DXCOLOR(1, 1, 1, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);

	Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
		pos,
		vector2(0.40f, 0.7f),
		0.6f,
		sppString[spiderSelect->ReturnMyPlayerParam(playerNum)],
		spiderSelect->ReturnMyPlayerParam(playerNum) == SelectPlayerParam::P1 ?
		red ?
		vector3(1, 0, 0) : vector3(0, 0, 1) :
		spiderSelect->ReturnMyPlayerParam(playerNum) == SelectPlayerParam::NONE ?
		vector3(1, 1, 1) : vector3(0, 1, 0),
		1,
		true);
}
Пример #5
0
bool CSphericalLight::bInitialize( float32 i_fRadius, uint32 i_iStacks, uint32 i_iSlices, float32 i_fFlareWidth, float32 i_fFlareHeight )
{
	CGraphics *pGraphics = m_pParent->pGetParent()->pGetGraphics();
	CMuli3DDevice *pM3DDevice = pGraphics->pGetM3DDevice();

	if( FUNC_FAILED( pM3DDevice->CreateVertexFormat( &m_pVertexFormatSphere, VertexDeclarationSphere, sizeof( VertexDeclarationSphere ) ) ) )
		return false;

	if( FUNC_FAILED( pM3DDevice->CreateVertexFormat( &m_pVertexFormatFlare, VertexDeclarationFlare, sizeof( VertexDeclarationFlare ) ) ) )
		return false;

	// Construct a sphere
	m_iNumVertices = i_iStacks * i_iSlices * 4;
	m_iNumPrimitives = i_iStacks * i_iSlices * 2;

	if( FUNC_FAILED( pM3DDevice->CreateVertexBuffer( &m_pVertexBufferSphere, sizeof( vertexformatsphere ) * m_iNumVertices ) ) )
		return false;

	vertexformatsphere *pDestVerticesSphere = 0;
	if( FUNC_FAILED( m_pVertexBufferSphere->GetPointer( 0, (void **)&pDestVerticesSphere ) ) )
		return false;

	const float32 fStepV = 1.0f / (float32)i_iStacks;
	const float32 fStepU = 1.0f / (float32)i_iSlices;

	float32 fV = 0.0f;
	for( uint32 i = 0; i < i_iStacks; ++i, fV += fStepV )
	{
		float32 fNextV = fV + fStepV;

		float32 fU = 0.0f;
		for( uint32 j = 0; j < i_iSlices; ++j, fU += fStepU )
		{
			float32 fNextU = fU + fStepU;
			
			// create a quad
			// 0 -- 1
			// |    |
			// 2 -- 3

			float32 x[4], y[4], z[4];

			x[0] = i_fRadius * sinf( fV * M3D_PI ) * cosf( fU * 2.0f * M3D_PI );
			z[0] = i_fRadius * sinf( fV * M3D_PI ) * sinf( fU * 2.0f * M3D_PI );
			y[0] = i_fRadius * cosf( fV * M3D_PI );

			x[1] = i_fRadius * sinf( fV * M3D_PI ) * cosf( fNextU * 2.0f * M3D_PI );
			z[1] = i_fRadius * sinf( fV * M3D_PI ) * sinf( fNextU * 2.0f * M3D_PI );
			y[1] = i_fRadius * cosf( fV * M3D_PI );

			x[2] = i_fRadius * sinf( fNextV * M3D_PI ) * cosf( fU * 2.0f * M3D_PI );
			z[2] = i_fRadius * sinf( fNextV * M3D_PI ) * sinf( fU * 2.0f * M3D_PI );
			y[2] = i_fRadius * cosf( fNextV * M3D_PI );

			x[3] = i_fRadius * sinf( fNextV * M3D_PI ) * cosf( fNextU * 2.0f * M3D_PI );
			z[3] = i_fRadius * sinf( fNextV * M3D_PI ) * sinf( fNextU * 2.0f * M3D_PI );
			y[3] = i_fRadius * cosf( fNextV * M3D_PI );

			pDestVerticesSphere->vPosition = vector3( x[0], y[0], z[0] );
			pDestVerticesSphere++;

			pDestVerticesSphere->vPosition = vector3( x[1], y[1], z[1] );
			pDestVerticesSphere++;

			pDestVerticesSphere->vPosition = vector3( x[2], y[2], z[2] );
			pDestVerticesSphere++;

			pDestVerticesSphere->vPosition = vector3( x[3], y[3], z[3] );
			pDestVerticesSphere++;
		}
	}

	m_pPrimitiveAssemblerSphere = new CSpherePrimitiveAssembler;

	m_pVertexShader = new CSphericalLightVS;
	m_pPixelShader = new CSphericalLightPS;

	// Initialize data for the flare
	if( FUNC_FAILED( pM3DDevice->CreateVertexBuffer( &m_pVertexBufferFlare, sizeof( vertexformatflare ) * 4 ) ) )
		return false;

	vertexformatflare *pDestVerticesFlare = 0;
	if( FUNC_FAILED( m_pVertexBufferFlare->GetPointer( 0, (void **)&pDestVerticesFlare ) ) )
		return false;

	pDestVerticesFlare[0].vPosition = vector3( i_fFlareWidth * -0.5f, i_fFlareHeight * 0.5f, 0.0f );
	pDestVerticesFlare[0].vTex = vector2( 0.0f, 0.0f );
	pDestVerticesFlare[1].vPosition = vector3( i_fFlareWidth * 0.5f, i_fFlareHeight * 0.5f, 0.0f );
	pDestVerticesFlare[1].vTex = vector2( 1.0f, 0.0f );
	pDestVerticesFlare[2].vPosition = vector3( i_fFlareWidth * 0.5f, i_fFlareHeight * -0.5f, 0.0f );
	pDestVerticesFlare[2].vTex = vector2( 1.0f, 1.0f );
	pDestVerticesFlare[3].vPosition = vector3( i_fFlareWidth * -0.5f, i_fFlareHeight * -0.5f, 0.0f );
	pDestVerticesFlare[3].vTex = vector2( 0.0f, 1.0f );

	CResManager *pResManager = m_pParent->pGetParent()->pGetResManager();
	m_hFlare = pResManager->hLoadResource( "Flare.png" );
	if( !m_hFlare )
		return false;

	return true;
}
Пример #6
0
void ActionBar::draw(void)
{
	vector2 screen = vector2(800, 600);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0.0, screen.x, screen.y, 0.0, -1.0, 10.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_TEXTURE_2D);

	int locationx = (screen.x / 10);
	for (auto & element : icons)
	{
		glColor3f(element.second.color.x, element.second.color.y, element.second.color.z);

		glBindTexture(GL_TEXTURE_2D, element.second.texture);
		glBegin(GL_QUADS);

		glTexCoord2f(1, 1); glVertex2f(locationx + element.second.size.x, (screen.y - (screen.y / 6))); //left top
		glTexCoord2f(1, 0); glVertex2f(locationx + element.second.size.x, (screen.y - (screen.y / 18))); //left bottom
		glTexCoord2f(0, 0); glVertex2f(locationx, (screen.y - (screen.y / 18))); //right bottom
		glTexCoord2f(0, 1); glVertex2f(locationx, (screen.y - (screen.y / 6))); //right top

		glEnd();
		locationx += element.second.size.x + 1;
	}


	glBindTexture(GL_TEXTURE_2D, texture);

	glBegin(GL_QUADS);

	glTexCoord2f(1,1); glVertex2f(screen.x / 10, (screen.y - (screen.y / 6))); //left top
	glTexCoord2f(1, 0); glVertex2f(screen.x / 10, (screen.y - (screen.y / 18))); //left bottom
	glTexCoord2f(0,0); glVertex2f(screen.x - screen.x / 10, (screen.y - (screen.y / 18))); //right bottom
	glTexCoord2f(0, 1); glVertex2f(screen.x - screen.x / 10, (screen.y - (screen.y / 6))); //right top

	glEnd();

	/*int locationx = (screen.x / 10) + 1;
	for (auto & element : icons)
	{
		glBindTexture(GL_TEXTURE_2D, element.second.texture);

		glBegin(GL_QUADS);

		glTexCoord2f(1, 1); glVertex2f(locationx, (screen.y - (screen.y / 6))); //left top
		glTexCoord2f(1, 0); glVertex2f(locationx, (screen.y - (screen.y / 18))); //left bottom
		glTexCoord2f(0, 0); glVertex2f(locationx + element.second.size.x, (screen.y - (screen.y / 18))); //right bottom
		glTexCoord2f(0, 1); glVertex2f(locationx + element.second.size.x, (screen.y - (screen.y / 6))); //right top



		glEnd();
	}*/


	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}
Пример #7
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;
}
Пример #8
0
		BOHGE_FORCEINLINE vector2 operator- () const
		{
			return vector2( -m_x , -m_y );
		}
Пример #9
0
		//单个的数字
		BOHGE_FORCEINLINE vector2 operator/ (T num) const
		{
			return vector2( m_x/num , m_y/num );
		}
Пример #10
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);
        }
  }
Пример #11
0
		BOHGE_FORCEINLINE vector2 operator* (const Matrix22<T>& m) const
		{
			return vector2( m_x * m.a11 + m_y * m.a21 , m_x * m.a12 + m_y * m.a22 );
		}
Пример #12
0
 vector2 ViewPort::transform(const vector2& p, const vector2& dir) const
 {
     return p + vector2(1 * dir[0] * tile_sz_[0],
                        1 * dir[1] * tile_sz_[1]);
 }
Пример #13
0
    void    ViewPort::draw()
    {
        //
        //
        //                      ================
        //      === A quick overview of the variables used below ===
        //              for displaying a part of a TileMap. 
        //                      ================
        //                  
        //  The idea is only to display 
        //  n_tiles_x_ * n_tiles_y_ number of tiles from the TileMap
        //  starting from tile pos_in_tilemap. The number of tiles displayed
        //  can be changed dynamically by modifying the mag_ property, which
        //  sets the 'magnification' of the ViewPort.
        //
        //   TileMap
        //     (0,0)
        //       F G L Q
        //       J K M R
        //       N O P S
        //       T U V W
        //
        //       e.g. pos_in_tilemap == (0,0) == F
        //              n_tiles_x_ == 2 and n_tiles_y_ == 2 by default, so
        //              by default four tiles are drawn: F, G, J, K.
        //
        //          ViewPort
        //                pos_              (p_start = pos_ + start_)
        //                  start_
        //                      [------------]
        //
        //                   tile_sz_[0]
        //                       < >                ^
        //           tile_sz[1] ^ F        G        '
        //                      v
        //                                      V_height
        //                        J        K        
        //                                          '
        //                      [------------]      v
        //                                  end_
        //
        //                      <- V_width ->
        //
        //                      n_tiles_x_ = [F, G, ...].size() 
        //                      n_tiles_y_ = [F, J, ...].size()
        //
        
        const float& V_width  = end_[0] - start_[0]; 
        const float& V_height = end_[1] - start_[1];

        unsigned int n_x_flr = std::floor(n_tiles_xy_[0]),
                     n_y_flr = std::floor(n_tiles_xy_[1]);

        vector2 tile_sz(V_width  / n_x_flr,
                        V_height / n_y_flr);

        // x, y will be small
        Tile*       cmt = 0;
        vector2     t_p(0.0, 0.0);

        tm_.setScale(tile_sz);

        for (unsigned int y = 0; y < n_y_flr; ++y) {
            for (unsigned int x = 0; x < n_x_flr; ++x) {

                // TODO: move this loop into a separate fn, that can
                // have a function pointer passed in, so that it's
                // easy to iterate over the ViewPort
                
                t_p[0] = x + pos_in_tm_[0] ;
                t_p[1] = y + pos_in_tm_[1] ;
                
                cmt = tm_.tile(t_p[0], t_p[1]);
                if (cmt != 0) {
                    cmt->setSize(tile_sz);
                    cmt->setPosition(vector2(x, y));
                    cmt->setDisplayOffset(start_);
                    
                    cmt->draw();
                }
            }
        }
    }
Пример #14
0
Data PlaneGenerator::generate()
{
	Data data;
	DataWriter writer(&data);

	if (m_info.segments[0] <= 0 || m_info.segments[1] <= 0)
	{
		writer.getLastErrorRef() = "Segments values must be >= 1";
		return data;
	}

	if (m_info.size.x <= 0 || m_info.size.y <= 0)
	{
		writer.getLastErrorRef() = "Size of a plane must not be <= 0.0";
		return data;
	}

	int sx = m_info.segments[0] + 1;
	int sy = m_info.segments[1] + 1;
	int verticesCount = sx * sy;

	writer.getMeshesRef().resize(1);
	writer.getMeshesRef()[0].offsetInIB = 0;
	writer.getMeshesRef()[0].indicesCount = m_info.segments[0] * m_info.segments[1] * 6;

	writer.getVerticesCountRef() = verticesCount;
	writer.getAdditionalUVsCountRef() = 0;
	writer.getBoundingBoxRef().vmin = vector3(-0.5f * m_info.size.x, -0.1f, -0.5f * m_info.size.y);
	writer.getBoundingBoxRef().vmax = vector3(0.5f * m_info.size.x, 0.1f, 0.5f * m_info.size.y);

	writer.getVertexBufferRef().resize(verticesCount * sizeof(Data::Vertex));
	for (int y = 0; y < sy; y++)
	{
		float pz = (float(y) / float(sy - 1) - 0.5f) * m_info.size.y;
		for (int x = 0; x < sx; x++)
		{
			int i = y * sx + x;
			float px = (float(x) / float(sx - 1) - 0.5f) * m_info.size.x;
			Data::Vertex* vertex = reinterpret_cast<Data::Vertex*>(writer.getVertexBufferRef().data() + i * sizeof(Data::Vertex));
			vertex->position = vector3(px, 0, pz);
			vertex->normal = vector3(0.0f, 1.0f, 0.0f);
			vertex->tangent = vector3(0.0f, 0.0f, 1.0f);
			vertex->binormal = vector3(1.0f, 0.0f, 0.0f);
			vertex->texCoord0 = vector2(float(x) * m_info.uvSize.x / float(sx - 1), float(y) * m_info.uvSize.y / float(sy - 1));
		}
	}

	writer.getIndexBufferRef().resize(writer.getMeshesRef()[0].indicesCount);
	unsigned int currentIndex = 0;
	for (int y = 0; y < m_info.segments[1]; y++)
	{
		unsigned int offset = (unsigned int)y * (unsigned int)sx;
		for (int x = 0; x < m_info.segments[0]; x++)
		{
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)x;
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)(x + sx);
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)(x + sx + 1);
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)(x + sx + 1);
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)(x + 1);
			writer.getIndexBufferRef()[currentIndex++] = offset + (unsigned int)x;
		}
	}

	return data;
}
Пример #15
0
Results ModelClass::LoadOBJ(String a_sFileName)
{
	String sAbsoluteRoute;
	sAbsoluteRoute = m_pSystem->m_pFolder->Root;
	sAbsoluteRoute += m_pSystem->m_pFolder->Data;
	sAbsoluteRoute += m_pSystem->m_pFolder->MOBJ;
	sAbsoluteRoute += a_sFileName;

	m_sModelName = a_sFileName;
	//m_sModelName = "";
	//int nLenght = static_cast<int>(a_sFileName.size());
	//for(int i = 0; i < nLenght -4; i++)
	//{
	//	m_sModelName += a_sFileName[i];
	//}
	
	FileReaderClass reader;
	Results result = reader.ReadFile(sAbsoluteRoute);
	if(result != Results::ERROR_FREE)
		return result;

#ifdef DEBUG
	std::cout << "File read @: " << sAbsoluteRoute << std::endl;
#endif

	reader.Rewind();
	int nGroupIndex = -1;
	std::vector<vector3> vPosition; //Vector of Vertices
	std::vector<vector3> vNormal; //Vector of Normals
	std::vector<vector2> vUV; //vector of UVS
	int nMaterial = 0;

	while(reader.ReadNextLine() != DONE)
	{
		char* sTemp = new char[reader.m_sLine.size() +1];
		String sWord = GetFirstWord(reader.m_sLine);
#pragma region Vertex
		if(reader.m_sLine[0] == 'v')
		{
			float x = 0.0f, y = 0.0f, z = 0.0f;
			if(reader.m_sLine[1] == ' ')
			{
				sscanf_s(reader.m_sLine.c_str(), "v %f %f %f", &x, &y, &z);
				vPosition.push_back(vector3( x, y, z ));
			}
			else if(reader.m_sLine[1] == 't')
			{
				sscanf_s(reader.m_sLine.c_str(), "vt %f %f", &x, &y);
				vUV.push_back( vector2(x, y));
			}
			else if(reader.m_sLine[1] == 'n')
			{
				sscanf_s(reader.m_sLine.c_str(), "vn %f %f %f", &x, &y, &z);
				vNormal.push_back(vector3( x, y, z ));
			}
		}
#pragma endregion
#pragma region Group
		else if(reader.m_sLine[0] == 'g')
		{
			//Verify if new group or existing one
			//If different from current Group, change nGroup Index
			String sName;

			int nLineSize = static_cast<int>(reader.m_sLine.size()) + 1;
			char* zsTemp = new char[nLineSize];
			strcpy_s(zsTemp, nLineSize, reader.m_sLine.c_str());
			
			char seps[] = " ,\t\n";

			char *token, *next_token;

			token = strtok_s(zsTemp, seps, &next_token);
			//nEmptyGroups will count the number of Empty groups at the end of the group name
			int nemprtyGroups = 0;
			String sGroupNames;
			sGroupNames = "";
			while (token != NULL)//Go to next word
			{
				sName = token;
				if(sName[0] == 'N')
				{
					if(sName[1] == 'U')
					{
						if(sName[2] == 'L')
						{
							if(sName[3] == 'L')
							{
								if(sName[4] == '_')
								{
									//This is an Empty group
								}
								else
								{
									sGroupNames += sName;
									sGroupNames + " ";
								}
							}
							else
							{
								sGroupNames += sName;
								sGroupNames += " ";
							}
						}
						else
						{
							sGroupNames += sName;
							sGroupNames += " ";
						}
					}
					else
					{
						sGroupNames += sName;
						sGroupNames += " ";
					}
				}
				else
				{
					sGroupNames += sName;
					sGroupNames += " ";
				}
				if(token != NULL)
					token = strtok_s(NULL, seps, &next_token);
			}
			delete[] zsTemp;
			zsTemp = 0;
			zsTemp = new char [sGroupNames.size() +1];
			strcpy_s(zsTemp, sGroupNames.size() +1, sGroupNames.c_str());
			token = strtok_s(zsTemp, seps, &next_token);
			while (token != NULL)//Go to next word
			{
				sName = token;

				if(token != NULL)
					token = strtok_s(NULL, seps, &next_token);
			}
			delete[] zsTemp;
			zsTemp = 0;

			if(sName != "default")
			{
				int nTemp = -1;
				for(int n = 0; n < static_cast<int> (m_vShape.size()); ++n)
				{
					if(m_vShape[n].Name == sName)
					{
						nTemp = n;
						break;
					}
				}

				if(nTemp >= 0) //Did exist
				{
					nGroupIndex = nTemp;
				}
				else //New group
				{
					ShapeClass group;
					group.Name = sName;
					m_vShape.push_back(group);
					nGroupIndex = static_cast<int>(m_vShape.size()) -1;
				}
			}
		}
#pragma endregion
#pragma region Faces
		else if(reader.m_sLine[0] == 'f')
		{
			int nP1 = 0, nT1 = 0, nN1 = 0;
			int nP2 = 0, nT2 = 0, nN2 = 0;
			int nP3 = 0, nT3 = 0, nN3 = 0;

			sscanf_s( reader.m_sLine.c_str(), "f %d/%d/%d %d/%d/%d %d/%d/%d",
																				&nP1, &nT1, &nN1,
																				&nP2, &nT2, &nN2,
																				&nP3, &nT3, &nN3);
			m_vShape[nGroupIndex].AddVertexPosition(vPosition[nP1-1]);
			m_vShape[nGroupIndex].AddVertexPosition(vPosition[nP2-1]);
			m_vShape[nGroupIndex].AddVertexPosition(vPosition[nP3-1]);

			m_vShape[nGroupIndex].AddVertexColor(vector3(1.0f,1.0f,1.0f));
			m_vShape[nGroupIndex].AddVertexColor(vector3(1.0f,1.0f,1.0f));
			m_vShape[nGroupIndex].AddVertexColor(vector3(1.0f,1.0f,1.0f));

			m_vShape[nGroupIndex].AddVertexUV(vUV[nT1-1]);
			m_vShape[nGroupIndex].AddVertexUV(vUV[nT2-1]);
			m_vShape[nGroupIndex].AddVertexUV(vUV[nT3-1]);

			m_vShape[nGroupIndex].AddVertexNormal(vNormal[nN1-1]);
			m_vShape[nGroupIndex].AddVertexNormal(vNormal[nN2-1]);
			m_vShape[nGroupIndex].AddVertexNormal(vNormal[nN3-1]);

			glm::vec3 up = glm::vec3(0, 1, 0);
			if(glm::abs(glm::normalize(vNormal[nN1-1])) != up){
				m_vShape[nGroupIndex].AddVertexTangent(glm::cross(vNormal[nN1-1], up));
			}else{
				m_vShape[nGroupIndex].AddVertexTangent(glm::vec3(1, 0, 0));
			}
			if(glm::abs(glm::normalize(vNormal[nN2-1])) != up){
				m_vShape[nGroupIndex].AddVertexTangent(glm::cross(vNormal[nN2-1], up));
			}else{
				m_vShape[nGroupIndex].AddVertexTangent(glm::vec3(1, 0, 0));
			}
			if(glm::abs(glm::normalize(vNormal[nN3-1])) != up){
				m_vShape[nGroupIndex].AddVertexTangent(glm::cross(vNormal[nN3-1], up));
			}else{
				m_vShape[nGroupIndex].AddVertexTangent(glm::vec3(1, 0, 0));
			}

			m_vShape[nGroupIndex].m_nMaterialIndex = nMaterial;
		}
#pragma endregion
#pragma region Material Library
		else if(sWord == "mtllib")
		{
			sscanf_s(reader.m_sLine.c_str(), "mtllib %s", sTemp, reader.m_sLine.size());
			LoadMTL(static_cast<String>(sTemp));
		}
#pragma endregion
#pragma region Use Material
		else if(sWord == "usemtl")
		{
			sscanf_s(reader.m_sLine.c_str(), "usemtl %s", sTemp, reader.m_sLine.size());
			String sTempMaterial = m_sModelName + "\\" + sTemp;
			nMaterial = m_pMaterialManager->IdentifyMaterial(sTempMaterial);
		}
#pragma endregion
		delete[] sTemp;
	}
	for(unsigned int i = 0; i < m_vShape.size(); i++)
		m_vShape[i].InitGPU();
	return Results::ERROR_FREE;
}
Пример #16
0
		BOHGE_FORCEINLINE vector2 operator- (T num) const
		{
			return vector2( m_x-num , m_y-num );
		}
Пример #17
0
GLFWwindow* Window::m_window = 0;
//横幅
int Window::m_w = 0;
int Window::m_h = 0;
//ウインドウの高さと幅の1/2の逆数
GLfloat Window::m_iw = 0;
GLfloat Window::m_ih = 0;

//透視投影変換行列
Matrix Window::mp=Matrix();

//ワールド座標に対するデバイス座標系の拡大率
GLfloat Window::m_s = 0;

//ワールド座標系に対する正規化デバイス座標系の拡大率
vector2 Window::m_scale = vector2(0,0);

//拡大率の算出
void Window::UpdateScale(){
	m_scale.set(m_s*m_iw, m_s*m_ih);
}

//コンストラクタ
Window::Window(){
}

void Window::CreateWindowStart(int width, int height, const char *title){

	m_window = glfwCreateWindow(width, height, title, NULL, NULL);
	m_iw = (2.0f / static_cast<GLfloat>(width));
	m_ih = (2.0f / static_cast<GLfloat>(height));
Пример #18
0
		BOHGE_FORCEINLINE vector2 operator+ (T num) const
		{
			return vector2( m_x+num , m_y+num );
		}
Пример #19
0
void UIRendererD3D11::renderLabel(gui::LabelPtr_T label)
{
	const Device& device = Application::instance()->getDevice();

	int fontId = label->getFont();
	const gui::Font& font = fontId < 0 ? gui::UIManager::instance().defaultFont() :
										 gui::UIManager::instance().fontManager()->getFont(fontId);
	if (!font.isValid()) return;
	auto fontResource = std::static_pointer_cast<FontResourceD3D11>(font.getResource().lock());

	if (label->getRenderingCache().get() != nullptr)
	{
		auto cachePtr = std::static_pointer_cast<LabelRenderingCache>(label->getRenderingCache());
		if (!cachePtr->isValid())
		{
			cachePtr->position = label->computeOnScreenPosition();
			cachePtr->size = label->computeOnScreenSize();
			cachePtr->characters = font.computeCharacters(label->getText(), cachePtr->position, cachePtr->size, 
														  label->getHorzFormatting(), label->getVertFormatting());
			cachePtr->setValid();
		}
		if (cachePtr->characters.empty()) return;

		vector2 halfScreeSize = gui::UIManager::instance().getScreenSize() * 0.5f;

		// set up text data
		TextData textData;
		textData.textColor = label->getColor();
		textData.halfScreenSize = vector4(halfScreeSize.x, halfScreeSize.y, 1.0f / halfScreeSize.x, -1.0f / halfScreeSize.y);
		textData.area = vector4(cachePtr->position.x, cachePtr->position.y,
								cachePtr->position.x + cachePtr->size.x, cachePtr->position.y + cachePtr->size.y);
		textData.textureSize = vector2(1.0f / (float)fontResource->getTexture()->getDesc2D().Width,
									   1.0f / (float)fontResource->getTexture()->getDesc2D().Height);
		m_textDataBuffer->setData(textData);
		m_textDataBuffer->applyChanges();

		// rendering
		if (m_textRendering->use())
		{
			Application::instance()->disableDepthTest()->apply();
			Application::instance()->defaultAlphaBlending()->apply();

			m_textRendering->setUniform<UIUniforms>(UIUF::TEXT_DATA, m_textDataBuffer);
			m_textRendering->setUniform<UIUniforms>(UIUF::CHARACTERS_MAP, fontResource->getTexture());
			m_textRendering->setUniform<UIUniforms>(UIUF::DEFAULT_SAMPLER, Application::instance()->anisotropicSampler());

			auto charIt = cachePtr->characters.begin();
			size_t callsCount = (cachePtr->characters.size() / MAX_CHARACTERS_PER_CALL) + 1;
			for (size_t call = 0; call < callsCount; call++)
			{
				// set up characters data
				size_t i = 0;
				for (; i < MAX_CHARACTERS_PER_CALL; i++, ++charIt)
				{
					if (charIt == cachePtr->characters.end()) break;
					CharacterData charDat;
					charDat.rectangle = charIt->box;
					charDat.uv = charIt->texturePos;
					m_charactersDataBuffer->setElement(i, std::move(charDat));
				}
				m_charactersDataBuffer->applyChanges();

				// draw
				m_textRendering->setUniform<UIUniforms>(UIUF::CHARACTERS_DATA, m_charactersDataBuffer);
				device.context->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST);
				device.context->DrawInstanced(1, i, 0, 0);
			}

			Application::instance()->disableDepthTest()->cancel();
			Application::instance()->defaultAlphaBlending()->cancel();
		}
	}
}
Пример #20
0
		BOHGE_FORCEINLINE vector2 operator* (const vector2& input) const
		{
			return vector2( m_x*input.m_x , m_y*input.m_y );
		}
Пример #21
0
void SelectSpider::SpiderSelect(){
	if (select){
		Graphic::GetInstance().DrawTexture(TEXTURE_ID::THREAD_BACK_TEXTURE,
			pos,
			vector2(1.0f, 1.0f),
			red == true ? D3DXCOLOR(1, 0, 0, 1.0f) : D3DXCOLOR(0, 0, 1, 1),
			vector2(0.5f, 0.5f),
			0.0f,
			0.0f,
			1,
			1.0f);

		Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
			vector2(50 + (red == true ? 0 : 1920 / 2), pos.y + 55.0f),
			vector2(0.2f, 0.35f),
			0.6f,
			"L1",
			vector3(1, 1, 1),
			1,
			true);

		Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
			vector2(1920 - 35 + (red != true ? 0 : -1920 / 2), pos.y + 55.0f),
			vector2(0.2f, 0.35f),
			0.6f,
			"R1",
			vector3(1, 1, 1),
			1,
			true);
	}
	Graphic::GetInstance().DrawFontDirect(FONT_ID::TEST_FONT,
		pos,
		vector2(0.3f, 0.5f) * (select == true ? 1.3f : 1.0f),
		0.6f,
		"SELECT YOUR SPIDER",
		red == true ? vector3(1, 0, 0) : vector3(0, 0, 1),
		1,
		true);

	Graphic::GetInstance().DrawTexture(TEXTURE_ID::MENU_ARROW_LEFT_TEXTURE,
		vector2(50 + (red == true ? 0 : 1920 / 2), pos.y + 6.0f),
		vector2(1.0f, 1.0f)* (select == true ? 1.5f : 1.0f),
		D3DXCOLOR(1, 1, 1, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);

	Graphic::GetInstance().DrawTexture(TEXTURE_ID::MENU_ARROW_RIGHT_TEXTURE,
		vector2(1920 - 50 + (red != true ? 0 : -1920 / 2), pos.y + 6.0f),
		vector2(1.0f, 1.0f)* (select == true ? 1.5f : 1.0f),
		D3DXCOLOR(1, 1, 1, 1),
		vector2(0.5f, 0.5f),
		0.0f,
		0.0f,
		1,
		1.0f);
}
Пример #22
0
 vector2 operator - (const vector2 & u, const vector2 & v)
 {
     return vector2(u) -= v;
 }
Пример #23
0
Vector2 operator - (const Vector2& v){
	Vector2 result = vector2(-v.x, -v.y);
	return result;
}
Пример #24
0
 vector2 operator * (const real c, const vector2 & v)
 {
     return vector2(v) *= c;
 }
Пример #25
0
//ポジションとビューをセット
void Camera::SetCamera(Vector3 cameraPos, Vector3 cameraView,float frameTime){
	// 射影行列
	D3DXMatrixPerspectiveFovLH(&matProj, 3.1415926f / 2.0f, 4.0f / 3.0f/*1.5f*/, 0.1f, 100.0f);
	mCameraParam.InputAngle = Device::GetInstance().GetInput()->MouseVec();
	if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_UP))
		mCameraParam.InputAngle.y = 1.0f;
	if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_DOWN))
		mCameraParam.InputAngle.y = -1.0f;
	if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_RIGHT))
		mCameraParam.InputAngle.x = 1.0f;
	if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_LEFT))
		mCameraParam.InputAngle.x = -1.0f;
	//入力値をもとに計算
	mCameraParam.AngleH += mCameraParam.InputAngle.x * CAMERA_ANGLE_SPEED * frameTime;
	mCameraParam.AngleV += mCameraParam.InputAngle.y * CAMERA_ANGLE_SPEED * frameTime;
	//クランプ
	if (mCameraParam.AngleH > Math::radian(180))mCameraParam.AngleH = Math::radian(-180);
	else if (mCameraParam.AngleH < Math::radian(-180))mCameraParam.AngleH = Math::radian(180);
	if (mCameraParam.AngleV > Math::radian(180))mCameraParam.AngleV = Math::radian(-180);
	else if (mCameraParam.AngleV < Math::radian(-180))mCameraParam.AngleV = Math::radian(180);

	//テストフォント
	Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 485), vector2(0.20f, 0.25f), 0.5f,"AngleH:"+ std::to_string(Math::angle(mCameraParam.AngleH))+"f");
	Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 500), vector2(0.20f, 0.25f), 0.5f,"AngleV:"+ std::to_string(Math::angle(mCameraParam.AngleV))+"f");
	//ターゲットをプレイヤーより少し上にセット
	mCameraParam.Target = RCMatrix4::getPosition(mat) + RCVector3::normalize(RCMatrix4::getUp(mat)) * CAMERA_PLAYER_TARGET_HEIGHT;//* Time::DeltaTime;

	//ターゲットの位置のマトリックス取得
	Matrix4 t = RCMatrix4::translate(mCameraParam.Target);
	//プレイヤーの左を使う
	Vector3 left = RCVector3::normalize(RCMatrix4::getLeft(mat));
	//左を軸に上下の回転を求める
	Matrix4 pitchMat = RCQuaternion::rotate(left, Math::angle(mCameraParam.AngleV - angleC));
	//差分用(Player.h参照)
	angleC = mCameraParam.AngleV;
	//今の前にさっきの回転を掛ける
	Vector3 front = RCVector3::normalize(RCMatrix4::getFront(matrix) * pitchMat);
	//外積を用いて上を求める
	Vector3 up = RCVector3::normalize(RCVector3::cross(front, left));
	//正しい前を求める
	front = RCVector3::normalize(RCVector3::cross(left, up));

	//後ろに下げる
	Matrix4 trans = RCMatrix4::translate(front * CAMERA_PLAYER_LENGTH);
	//Targetの位置から後ろに下げる
	Matrix4 x = t* trans;
	//プレイヤーのけつ方向とカメラ方向のなす角
	float angle = Math::acos(RCVector3::dot(RCVector3::normalize(RCMatrix4::getFront(mat)), front));
	//回転行列をセット
	Matrix4 rotate = RCMatrix4::Identity();
	RCMatrix4::setLeft(rotate, left);
	RCMatrix4::setUp(rotate, up);
	RCMatrix4::setFront(rotate, front);
	matrix = rotate;

	//プレイヤーのけつ方向とカメラ方向のなす角が70度以上なら
	while (angle > 70.0f){
		//1度ずつ引いて求める
		if (RCVector3::cross(RCVector3::normalize(RCMatrix4::getFront(mat)), front) == left){
			mCameraParam.AngleV -= Math::radian(abs(angle) - 70.0f);
		}
		else{
			mCameraParam.AngleV += Math::radian(abs(angle) - 70.0f);
		}

		pitchMat = RCQuaternion::rotate(left, Math::angle(mCameraParam.AngleV - angleC));
		angleC = mCameraParam.AngleV;
		front = RCVector3::normalize(RCMatrix4::getFront(matrix) * pitchMat);
		up = RCVector3::normalize(RCVector3::cross(front, left));
		front = RCVector3::normalize(RCVector3::cross(left, up));
		angle = Math::acos(RCVector3::dot(RCVector3::normalize(RCMatrix4::getFront(mat)), front));
		rotate = RCMatrix4::Identity();
		RCMatrix4::setLeft(rotate, left);
		RCMatrix4::setUp(rotate, up);
		RCMatrix4::setFront(rotate, front);

		matrix = rotate;
		if (angle < 70.0f)break;
	}

	trans = RCMatrix4::translate(front * CAMERA_PLAYER_LENGTH);
	x = t* trans;
	mCameraParam.Eye = RCMatrix4::getPosition(x);//* Time::DeltaTime;
	
	//カメラとのあたり判定(2分探索法を用いて距離を短くしていく)
	bool hitNum = ModelCapsule(*stage->ReturnMat(), OCT_ID::STAGE_OCT, CreateCapsule(mCameraParam.Eye, mCameraParam.Target, CAMERA_COLLISION_SIZE)).colFlag;
	std::string s = (hitNum == true ? "TRUE" : "FALSE");
	Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 470), vector2(0.20f, 0.25f), 0.5f, "MODELCAPSULEFLAG:" +s );
	if (hitNum){
		float notHitLength = 0.0f;
		float cameraLen = CAMERA_PLAYER_LENGTH;
		do{
			float testLen = notHitLength + (cameraLen - notHitLength) / 2.0f;
			trans = RCMatrix4::translate(front * testLen);
			x = t* trans;
			mCameraParam.Eye = RCMatrix4::getPosition(x);//* Time::DeltaTime;
			bool hit = ModelCapsule(*stage->ReturnMat(), OCT_ID::STAGE_OCT, CreateCapsule(mCameraParam.Eye, mCameraParam.Target, CAMERA_COLLISION_SIZE)).colFlag;
			if (hit){
				cameraLen = testLen;
			}
			else{
				notHitLength = testLen;
			}
		} while (cameraLen - notHitLength > 0.01f);
	}

	mCameraParam.Up = up;//* Time::DeltaTime;
	// ビュー行列
	D3DXMatrixLookAtLH(&matView,
		&RConvert(&mCameraParam.Eye),
		&RConvert(&mCameraParam.Target),
		&RConvert(&mCameraParam.Up));
}
Пример #26
0
 vector2 operator + (const vector2 & u, const vector2 & v)
 {
     return vector2(u) += v;
 }
Пример #27
0
vector2 vector2::operator-(vector2 & b){
	return vector2(x-b.x, y-b.y);
}
Пример #28
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;

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

	Vec3f 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);
#if 0
			// compute the mean edge value:
			_meanEdgeSize += edge->GetaOEdge()->GetVec().norm();
#endif
		}

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

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

	return face;
}
Пример #29
0
vector2 vector2::operator*(float a){
	return vector2(x*a, y*a);
}
Пример #30
0
vector2 operator+(vector2& lh, vector2& rh)
{
	return vector2(lh.x + rh.x, lh.x + rh.x);
}