Esempio n. 1
0
	//----------------------------------------------------------------------------------------------------
	//need to be recasted
	void EERotateProcess(EEObject* _object, float _time, float _radians, const FLOAT3& _center, float _delay, bool _isInfinite, float _startTime)
	{
		try
		{
			float remainTime = _delay + _time;
			float progress = _startTime;
			float speed = _radians / _time;

			while (1)
			{
				EEThreadSleep(20);
				std::lock_guard<std::mutex> mutex(_object->GetThreadMutex());

				float currTime = (float)EECore::s_EECore->GetTotalTime();
				float deltaTime = currTime - progress;
				progress = currTime;
				if (remainTime <= deltaTime + _time)
				{
					remainTime = _time;
					break;
				}
				else
				{
					remainTime -= deltaTime;
				}
			}

			while (1)
			{
				EEThreadSleep(20);
				std::lock_guard<std::mutex> mutex(_object->GetThreadMutex());

				float currTime = (float)EECore::s_EECore->GetTotalTime();
				float deltaTime = currTime - progress;
				progress = currTime;
				if (remainTime <= deltaTime && !_isInfinite)
				{
					MATRIX centerToOrigin = MatrixTranslation(-_center.x, -_center.y, -_center.z);
					MATRIX rotation = MatrixRotationAxisN(FLOAT3(0.0f, 0.0f, 1.0f), speed * remainTime);
					MATRIX originToCenter = MatrixTranslation(_center.x, _center.y, _center.z);
					_object->SetRotation(_object->GetRotation() * centerToOrigin * rotation * originToCenter);
					remainTime = 0.f;
					return;
				}
				else
				{
					MATRIX centerToOrigin = MatrixTranslation(-_center.x, -_center.y, -_center.z);
					MATRIX rotation = MatrixRotationAxisN(FLOAT3(0.0f, 0.0f, 1.0f), speed * deltaTime);
					MATRIX originToCenter = MatrixTranslation(_center.x, _center.y, _center.z);
					_object->SetRotation(_object->GetRotation() * centerToOrigin * rotation * originToCenter);
					remainTime -= deltaTime;
				}
			}
		}
		catch (boost::thread_interrupted&)
		{
			return;
		}
	}
Esempio n. 2
0
void C3d::Open(const TriFile &tfile)
{
	Cleanup();
	rotation = true;
	if( FAILED( g_pd3dDevice->CreateVertexBuffer(tfile.header.numVertices*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL)))
		return;
	CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
		return;
	vcount = tfile.header.numVertices;
	if(tfile.hasTangentsBinormals)
	{
		for( DWORD i=0; i<tfile.header.numVertices; i++ )
		{
			pVertices[i].position = tfile.verticestb(i)->vertexPosition;
			pVertices[i].normal   = tfile.verticestb(i)->vertexNormal;
			pVertices[i].uv   = tfile.verticestb(i)->vertexUV;
		}
	}else{
		for( DWORD i=0; i<tfile.header.numVertices; i++ )
		{
			pVertices[i].position = tfile.verticesc(i)->vertexPosition;
			pVertices[i].normal   = tfile.verticesc(i)->vertexNormal;
			pVertices[i].uv   = tfile.verticesc(i)->vertexUV;
		}
	}
	ComputeBoundingSphere(pVertices, vcount, &vCenter, &vRadius);
	g_pVB->Unlock();
	D3DVIEWPORT9 vp;
	g_pd3dDevice->GetViewport(&vp);
	vp.MinZ = -((int)vRadius/300)*55.0f;
	g_pd3dDevice->SetViewport(&vp);
	D3DXMatrixIdentity( &matWorld );
	MatrixTranslation( &matWorld, vCenter.x, -vCenter.y, -vCenter.z );
	DWORD *indices=NULL;
	
	ClearIndexes();
	ClearTextures();
	g_pTexture.resize(tfile.header.numSurfaces);
	for(unsigned int i = 0; i < tfile.header.numSurfaces; i++)
			g_pTexture[i] = NULL;
	g_pIB.resize(tfile.header.numSurfaces);
	fcount.resize(tfile.header.numSurfaces);
	for(dword i = 0; i < tfile.header.numSurfaces; i++)
	{
		g_pd3dDevice->CreateIndexBuffer(tfile.surfaces[i].numTriangles*3*4,D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &g_pIB[i], NULL);
		g_pIB[i]->Lock( 0, 0, (void**)&indices, 0 );

		for(dword c = 0; c < tfile.surfaces[i].numTriangles; c++)
		{
			indices[3*c] = tfile.triangles[i][c][0];
			indices[3*c+1] = tfile.triangles[i][c][1];
			indices[3*c+2] = tfile.triangles[i][c][2];
		}
		g_pIB[i]->Unlock();

		fcount[i] = tfile.surfaces[i].numTriangles;
	}
	loaded = true;
}
Esempio n. 3
0
 Camera2D::Camera2D(const lost::math::Rect& inViewport)
 : Camera(inViewport)
 {
   mDepth = lost::math::Vec2(-1.0, 1.0);
   float offset = .375f;
   mViewMatrix = MatrixTranslation(Vec3(offset, offset, .0f));
 }
Esempio n. 4
0
Matrix
LookAt(float eyex,    float eyey,    float eyez,
       float centerx, float centery, float centerz,
       float upx,     float upy,     float upz)
{
    Vector3 z(eyex - centerx, eyey - centery, eyez - centerz);
    Vector3Normalize(z, z);

    Vector3 x(
          upy * z[2] -  upz * z[1],
         -upx * z[2] +  upz * z[0],
          upx * z[1] -  upy * z[0]);

    Vector3 y(
         z[1] * x[2] - z[2] * x[1],
        -z[0] * x[2] + z[2] * x[0],
         z[0] * x[1] - z[1] * x[0]);

    Vector3Normalize(x, x);
    Vector3Normalize(y, y);

    Matrix mat(
        x[0], y[0], z[0], 0,
        x[1], y[1], z[1], 0,
        x[2], y[2], z[2], 0,
        0,    0,    0,    1);

    Matrix mat2;
    MatrixTranslation(mat2, -eyex, -eyey, -eyez);

    Matrix ret;
    MatrixMultiply(ret, mat, mat2);

    return ret;
}
Esempio n. 5
0
//see http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=Quaternion_Camera_Class
void SimpleCamera::getLookAt(MATRIX &look)
{
	MATRIX m1, m2, m3, translation;
	QUATERNION q;

	// Make the Quaternions that will represent our rotations
	MatrixQuaternionRotationAxis(_qPitch, Vec3(1.0f, 0.0f, 0.0f), _pitchRadians);
	MatrixQuaternionRotationAxis(_qHeading, Vec3(0.0f, 1.0f, 0.0f), _headingRadians);

	// Combine the pitch and heading rotations and store the results in q
	MatrixQuaternionMultiply(q, _qHeading, _qPitch);
	MatrixRotationQuaternion(m1, q);
	
	// Create a matrix from the pitch Quaternion and get the j vector 
	// for our direction.
	MatrixRotationQuaternion(m3, _qPitch);
	_direction.y = m3.f[9];

	// Combine the heading and pitch rotations and make a matrix to get
	// the i and j vectors for our direction.
	MatrixQuaternionMultiply(q, _qPitch, _qHeading);
	MatrixRotationQuaternion(m2, q);
	_direction.x = m2.f[8];
	_direction.z = -m2.f[10];

	// Increment our position by the vector
	_position += (_direction * _forwardVelocity);

	// Translate to our new position.
	MatrixTranslation(translation, -_position.x, -_position.y, -_position.z);
	MatrixMultiply(look, translation, m1);
}
Esempio n. 6
0
void DrawSpritesRot2D(float x, float y, float layer, float dx, float dy, u32 rgba, float angle)
{
    dx /= 2.0f; dy /= 2.0f;

    MATRIX matrix;
    
    // rotate and translate the sprite
    matrix = MatrixRotationZ(angle);
    matrix = MatrixMultiply(matrix, MatrixTranslation(x + dx, y + dy, 0.0f));
    
    // fix ModelView Matrix
    tiny3d_SetMatrixModelView(&matrix);
   
    tiny3d_SetPolygon(TINY3D_QUADS);

    tiny3d_VertexPos(-dx, -dy, layer);
    tiny3d_VertexColor(rgba);
    tiny3d_VertexTexture(0.0f , 0.0f);

    tiny3d_VertexPos(dx , -dy, layer);
    tiny3d_VertexTexture(0.99f, 0.0f);

    tiny3d_VertexPos(dx , dy , layer);
    tiny3d_VertexTexture(0.99f, 0.99f);

    tiny3d_VertexPos(-dx, dy , layer);
    tiny3d_VertexTexture(0.0f , 0.99f);

    tiny3d_End();

    tiny3d_SetMatrixModelView(NULL); // set matrix identity

}
Esempio n. 7
0
void XGraphicsOpenGL::FillRect( float x, float y, float w, float h, XCOLOR color )
{
	
	CHECK_GL_ERROR();
	
	if( w == 0 || h == 0 )	return;
		if( w < 0 )    {
				w = -w;     // w는 부호 바꿈
				x -= w;     // 좌측 좌표를 -w만큼 이동시켜주고
		}
		if( h < 0 )    {
				h = -h;
				y -= h;
		}
	if( x > GetViewportRight() || y > GetViewportBottom() )
		return;
	if( x + w < 0 || y + h < 0 )
		return;
	
	GLfloat r, g, b, a;
	r = XCOLOR_RGB_R(color) / 255.0f;
	g = XCOLOR_RGB_G(color) / 255.0f;
	b = XCOLOR_RGB_B(color) / 255.0f;
	a = XCOLOR_RGB_A(color) / 255.0f;
	
	// width-1이 맞나? 안하는게 맞나?
	GLfloat pos[8] = { 0, h, w, h, 0, 0, w, 0 };
	GLfloat col[16] = {  r,g,b,a,
						 r,g,b,a,
						 r,g,b,a,
						 r,g,b,a	};
		MATRIX mMVP;
		MATRIX mModel;
		MatrixTranslation( mModel, x, y, 0 );
		MatrixMultiply( mMVP, mModel, XE::x_mViewProjection );
		GetpColorShader()->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f );

	glEnable(GL_BLEND);
#ifdef _XVAO
		glBindVertexArrayOES( 0 );
#endif
		
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		glEnableVertexAttribArray( XE::ATTRIB_POS );
		glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos);
//    glDisableVertexAttribArray( XE::ATTRIB_TEXTURE );
		glEnableVertexAttribArray( XE::ATTRIB_COLOR );
		glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	CHECK_GL_ERROR();
	

//	glEnable( GL_TEXTURE_2D );
 
		
}
Esempio n. 8
0
void XGraphicsOpenGL::DrawRect( float x, float y, float w, float h, XCOLOR color )
{
	CHECK_GL_ERROR();
	if( w < 0 ) {
		x += w;
		w = -w;
	}
	if( h < 0 ) {
		y += h;
		h = -h;
	}
	//	if( x > GetScreenWidth() || y > GetScreenHeight() )
	if( x > GetViewportRight() || y > GetViewportBottom() )
		return;
	if( w < 0 || h < 0 )
		return;
	
	
	GLfloat r, g, b, a;
	r = XCOLOR_RGB_R(color) / 255.0f;
	g = XCOLOR_RGB_G(color) / 255.0f;
	b = XCOLOR_RGB_B(color) / 255.0f;
	a = XCOLOR_RGB_A(color) / 255.0f;
	//	if( a != 255 )	glEnable(GL_BLEND);		// 이거 자주불러주면 부하걸릴거 같다. 외부에서 블럭단위로 셋하게 하자.
	
	// width-1이 맞나? 안하는게 맞나?
//	GLfloat pos[8] = { 0, h, w, h, 0, 0, w, 0 };
	GLfloat pos[10] = { 0, 0, w, 0, w, h, 0, h, 0, 0 };
	GLfloat col[20] = {  r,g,b,a,
		r,g,b,a,
		r,g,b,a,
		r,g,b,a,
		r,g,b,a	};
		MATRIX mModel;
		MATRIX mMVP;
		MatrixTranslation( mModel, x, y, 0 );
		MatrixMultiply( mMVP, mModel, XE::x_mViewProjection );
		GetpColorShader()->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f );
//    GetpColorShader()->SetMatrixModel( mModel );
	glLineWidth( GetLineWidth() );
//	glDisable( GL_TEXTURE_2D );
	glBindBuffer(GL_ARRAY_BUFFER, 0);
		glEnableVertexAttribArray( XE::ATTRIB_POS );
		glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos);
		glEnableVertexAttribArray( XE::ATTRIB_COLOR );
		glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#ifdef _XVAO
		glBindVertexArrayOES( 0 );
#endif
	
	glDrawArrays(GL_LINE_STRIP, 0, 5);
		
//	glEnable( GL_TEXTURE_2D );	
	CHECK_GL_ERROR();
	
	}
void NodeControlViewImpl::TranslateDelta(float x, float y, float z)
{
	assert(m_transform->GetSize() == 16);
	float4x4 m;
	m_transform->GetValue(m);
	MatrixTranspose(&m, &m);
	float4x4 t;
	MatrixTranslation(&t, x * m_scale, y * m_scale, z * m_scale);
	MatrixTranspose(&m, &(t*m));
	m_transform->SetValue(m);
}
Esempio n. 10
0
void Sound::DrawOverlay(X3DDrawContext* pDC)
{
	// TODO: not here
	if (m_selected)
	{
		pDC->m_renderContext->PushModelView(pDC->m_renderContext->modelViewMatrix() * MatrixTranslation(getLocation()));

		DrawAxis(pDC);

		pDC->m_renderContext->PopMatrix();
	//	pDC->m_renderContext->GetRT()->m_d3d10->m_device->OMSetDepthStencilState(depthStencilState, stencilRef);
	}
}
Esempio n. 11
0
void draw_twat(float x, float y, float angle)
{
    int n;

    float ang, angs = 6.2831853071796 / 8, angs2 = 6.2831853071796 / 32;

    MATRIX matrix;

    // rotate and translate the sprite
    matrix = MatrixRotationZ(angle);
    matrix = MatrixMultiply(matrix, MatrixTranslation(x , y , 65535.0f));

    // fix ModelView Matrix
    tiny3d_SetMatrixModelView(&matrix);

    tiny3d_SetPolygon(TINY3D_TRIANGLES);

    ang = 0.0f;

    for(n = 0; n <8; n++) {

        tiny3d_VertexPos(4.0f *sinf(ang), 4.0f *cosf(ang), 0);
        tiny3d_VertexColor(0xffffff30);
        tiny3d_VertexPos(7.0f *sinf(ang+angs/2), 7.0f *cosf(ang+angs/2), 0);
        tiny3d_VertexColor(0xff00ff40);
        tiny3d_VertexPos(4.0f *sinf(ang+angs), 4.0f *cosf(ang+angs), 0);
        tiny3d_VertexColor(0xffffff30);

        ang += angs;
    }

    tiny3d_End();

    tiny3d_SetPolygon(TINY3D_POLYGON);

    ang = 0.0f;

    for(n = 0; n <32; n++) {
        tiny3d_VertexPos(3.0f * sinf(ang), 3.0f * cosf(ang), 0);
        if(n & 1) tiny3d_VertexColor(0x80ffff40);
        else tiny3d_VertexColor(0xffffff40);
        ang += angs2;
    }

    tiny3d_End();

    tiny3d_SetMatrixModelView(NULL); // set matrix identity

}
Esempio n. 12
0
CameraInstance* CreateDefaultCamera(EditableScene *es, const char *camTag, const char *nodeTag, const char *instTag)
{
	Camera *pCamera = es->CreateCamera();
	pCamera->SetTag(camTag);
	Node *pNode = es->CreateNode(NULL);
	pNode->SetTag(nodeTag);
	CameraInstance *pCI = es->CreateCameraInstance(pNode, pCamera);
	pCI->SetTag(instTag);
	Property* pTransform = pNode->AppendTransform(Transform::MATRIX, Zero)->GetDelegate(NULL);

	AutoPtr<AccessProviderLocal> providerLocal;
	CreateAccessProviderLocal(&providerLocal);

	float3 aabb(es->GetSceneAABB(-1, 0, providerLocal));
	float3 center(es->GetSceneCenter(-1, 0, providerLocal));
	float4x4 ypr;
	MatrixRotationYawPitchRoll(&ypr, 3.141692f/4, -3.141692f/4, 0);

	float4x4 t0;
	MatrixTranslation(&t0, center.x, center.y, center.y);

	float4x4 t1;
	float bbD = Vec3Length(&aabb);
	MatrixTranslation(&t1, 0, 0, bbD*2);
	float4x4 up = es->GetUpAxis();
	float4x4 upI;
	MatrixInverse(&upI, 0, &up);
	float4x4 minusZ;
	MatrixScaling(&minusZ, 1,1,-1);
	float4x4 m = t1*ypr*t0*minusZ*upI;
	MatrixTranspose(&m, &m);
	pTransform->SetValue(m);
	pCamera->SetFar(10*bbD);

	return pCI;
}
Esempio n. 13
0
void BoxBrowser::SetZoomMatrix()
{
	MATRIX mtxScale = MatrixScale( zScale, zScale, zScale );
	MATRIX matrixX = MatrixRotationX( FROM_ANGLE( zRotX ) );
	MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zRotZ ) );

	// rotate and translate
	MATRIX mx = MatrixRotationY( FROM_ANGLE( zRotY ) );					//rotate
	mx = MatrixMultiply( mx, matrixX );
	mx = MatrixMultiply( mx, matrixZ );
	mx = MatrixMultiply( mx, mtxScale );								//scale this thing up

	mx = MatrixMultiply( mx, MatrixTranslation( zPosX, zPosY, zPosZ ) ); //translate into place

	//apply matrix
	tiny3d_SetMatrixModelView( &mx );
}
Esempio n. 14
0
void BoxBrowser::CreateMatrix( float xpos, float ypos, float zpos, float xrot, float yrot, float zrot, float scale )
{
	MATRIX mtxScale = MatrixScale( scale, scale, scale );
	MATRIX matrixX = MatrixRotationX( FROM_ANGLE( xrot ) );
	MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zrot ) );

	// rotate and translate
	MATRIX mx = MatrixRotationY( FROM_ANGLE( yrot ) );					//rotate
	mx = MatrixMultiply( mx, matrixX );
	mx = MatrixMultiply( mx, matrixZ );
	mx = MatrixMultiply( mx, mtxScale );								//scale this thing up

	mx = MatrixMultiply( mx, MatrixTranslation( xpos, ypos, zpos ) ); //translate into place

	//put this matrix in the list
	mtxBox.push_back( mx );
}
Esempio n. 15
0
void BoxBrowser::UpdateCamera()
{
	//adjust the camera a little bit
	MATRIX cam = MatrixRotationX( FROM_ANGLE( -3.5 ) );
	cam = MatrixMultiply( cam, MatrixTranslation( 0, camY, 0 ) );
	tiny3d_SetProjectionMatrix( &cam );
	if( !--camDelay )
	{
		camDelay = 3;
		camY += camdif;
		if( camY == 10 )
		{
			camdif = -1;
		}
		else if( !camY )
		{
			camdif = 1;
		}
	}
}
Esempio n. 16
0
void MatrixLookAtRH(
	MATRIX			&mOut,
	const VECTOR3	&vEye,
	const VECTOR3	&vAt,
	const VECTOR3	&vUp)
{
	VECTOR3 f, vUpActual, s, u;
	MATRIX	t;

	f.x = vAt.x - vEye.x;
	f.y = vAt.y - vEye.y;
	f.z = vAt.z - vEye.z;

	MatrixVec3Normalize(f, f);
	MatrixVec3Normalize(vUpActual, vUp);
	MatrixVec3CrossProduct(s, f, vUpActual);
	MatrixVec3CrossProduct(u, s, f);

	mOut.f[ 0] = s.x;
	mOut.f[ 1] = u.x;
	mOut.f[ 2] = -f.x;
	mOut.f[ 3] = 0;

	mOut.f[ 4] = s.y;
	mOut.f[ 5] = u.y;
	mOut.f[ 6] = -f.y;
	mOut.f[ 7] = 0;

	mOut.f[ 8] = s.z;
	mOut.f[ 9] = u.z;
	mOut.f[10] = -f.z;
	mOut.f[11] = 0;

	mOut.f[12] = 0;
	mOut.f[13] = 0;
	mOut.f[14] = 0;
	mOut.f[15] = 1;

	MatrixTranslation(t, -vEye.x, -vEye.y, -vEye.z);
	MatrixMultiply(mOut, t, mOut);
}
void ParticleData::MatrixMap(float x, float y, float z, float theta, float size, bool init, float speed){
	MATRIX mov;
	MATRIX rot;

	//シェーダーのコンスタントバッファーに各種データを渡す
	D3D11_MAPPED_SUBRESOURCE pData;
	CONSTANT_BUFFER_P cb;
	dx->pDeviceContext->Map(pConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &pData);
	MatrixRotationZ(&rot, theta);
	MatrixTranslation(&mov, x, y, z);
	MatrixMultiply(&dx->World, &rot, &mov);
	MatrixMultiply(&cb.WV, &dx->World, &dx->View);
	cb.Proj = dx->Proj;
	MatrixTranspose(&cb.WV);
	MatrixTranspose(&cb.Proj);
	cb.size.x = size;
	if (init)cb.size.y = 1.0f; else cb.size.y = 0.0f;
	cb.size.z = speed;
	memcpy_s(pData.pData, pData.RowPitch, (void*)(&cb), sizeof(cb));
	dx->pDeviceContext->Unmap(pConstantBuffer, 0);
}
Esempio n. 18
0
void MatrixLookAtRH(float *mOut, const vec3_t vEye, const vec3_t vAt, const vec3_t vUp)
{
	vec3_t f, vUpActual, s, u;
	float	t[16];
	
	f[0] = vAt[0] - vEye[0];
	f[1] = vAt[1] - vEye[1];
	f[2] = vAt[2] - vEye[2];
	
	Normalize3(f, f);
	Normalize3(vUpActual, vUp);
	Cross3(s, f, vUpActual);
	Cross3(u, s, f);
	
	mOut[ 0] = s[0];
	mOut[ 1] = u[0];
	mOut[ 2] = -f[0];
	mOut[ 3] = 0;
	
	mOut[ 4] = s[1];
	mOut[ 5] = u[1];
	mOut[ 6] = -f[1];
	mOut[ 7] = 0;
	
	mOut[ 8] = s[2];
	mOut[ 9] = u[2];
	mOut[10] = -f[2];
	mOut[11] = 0;
	
	mOut[12] = 0;
	mOut[13] = 0;
	mOut[14] = 0;
	mOut[15] = 1;
	
	MatrixTranslation(t, -vEye[0], -vEye[1], -vEye[2]);
	MatrixMultiply(mOut, t, mOut);
}
Esempio n. 19
0
        void Test5::Render() {
            Test3::Render();

            if (mesh1 != nullptr) {
                Matrix4f r;
                MatrixRotationZ(r, angle);

                Matrix4f s;
                MatrixScale(s, Vec3f(10));

                Matrix4f rot;
                MatrixMultiply(r, s, rot);

                Matrix4f transl;
                MatrixTranslation(transl, Vec3f(-100, 30, 0));

                Matrix4f model;
                MatrixMultiply(transl, rot, model);

                Matrix4f model_view;
                MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view);

                auto program = shaderProgram ? shaderProgram : shaderProgram2;
                GetGreng().GetRenderer().RenderMesh(
                    mesh1, 0, &tex6, 1, program, &model, nullptr,
                    &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1,
                    {}, {}, frameBuffer);
            }

            if (mesh2 != nullptr) {
                Matrix4f r;
                MatrixRotationZ(r, -angle);

                Matrix4f s;
                MatrixScale(s, Vec3f(10));

                Matrix4f rot;
                MatrixMultiply(r, s, rot);

                Matrix4f transl;
                MatrixTranslation(transl, Vec3f(100, 30, 0));

                Matrix4f model;
                MatrixMultiply(transl, rot, model);

                Matrix4f model_view;
                MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view);

                auto program = shaderProgram ? shaderProgram : shaderProgram2;
                GetGreng().GetRenderer().RenderMesh(
                    mesh2, 0, &tex2, 1, program, &model, nullptr,
                    &model_view, &GetCamera().GetProjectionMatrix().getValue(), &light1,
                    {}, {}, frameBuffer);
            }

            if (mesh3 != nullptr) {
                Matrix4f rangle;
                MatrixRotationY(rangle, 0);

                Matrix4f model;
                MatrixMultiply(rangle, mesh3ConstMatrix, model);

                Matrix4f model_view;
                MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view);

                greng::Texture* texts[6] = {
                    tex4, tex4normal, tex3, tex3normal, tex5, tex5normal
                };
                
                auto program = shaderProgram ? shaderProgram : shaderProgram4;
                for (unsigned int i = 0; i < 3; i++) {
                    GetGreng().GetRenderer().RenderMesh(
                        mesh3, i, &texts[i * 2], 2, program, &model,
                        nullptr, &model_view,
                        &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr,
                        &GetCamera().GetPos().Get(), frameBuffer);
                }
            }

            if (mesh4 != nullptr) {
                Matrix4f rangle;
                MatrixRotationY(rangle, 0);

                Matrix4f model_1;
                MatrixMultiply(rangle, mesh3ConstMatrix, model_1);

                Matrix4f trans;
                MatrixTranslation(trans, Vec3f(-150, 0, 0));

                Matrix4f model;
                MatrixMultiply(trans, model_1, model);

                Matrix4f model_view;
                MatrixMultiply(GetCamera().GetViewMatrix(), model, model_view);

                greng::Texture* texts[6] = {
                    tex7, tex7normal, tex7, tex7normal, tex7, tex7normal,
                };

                auto program = shaderProgram ? shaderProgram : shaderProgram4;
                for (unsigned int i = 0; i < 3; i++) {
                    GetGreng().GetRenderer().RenderMesh(
                        mesh4, i, &texts[i * 2], 2, program, &model,
                        nullptr, &model_view,
                        &GetCamera().GetProjectionMatrix().getValue(), &light1, nullptr,
                        &GetCamera().GetPos().Get(), frameBuffer);
                }
            }

            GetGreng().GetRenderer().DrawPoint(GetCamera(), light1.position, 10,
                                               Color4f(1, 1, 1, 1), false);
        }
Esempio n. 20
0
void XGraphicsOpenGL::DrawTexture( GLint idTexture, 
																	 float xpos, float ypos, 
																	 float width, float height, 
																	 BOOL bBlendAdd )
{
	
	CHECK_GL_ERROR();
	
	GLfloat tex[8] = { 0, 1.0f, 1.0f, 1.0f, 0, 0, 1.0f, 0 };
	GLfloat pos[8] = { xpos, ypos + height, xpos + width, ypos + height, xpos, ypos, xpos + width, ypos };
	GLfloat col[16] = { 
		1.0f, 1.0f, 1.0f, 1.0f,
		1.0f, 1.0f, 1.0f, 1.0f,
		1.0f, 1.0f, 1.0f, 1.0f,
		1.0f, 1.0f, 1.0f, 1.0f };
	MATRIX mTrans, mScale, mMVP;
	MatrixTranslation( mTrans, xpos, ypos, 0 );
	MatrixScaling( mScale, 1.f, 1.f, 1.f );
	MatrixIdentity( mMVP );
	MatrixMultiply( mMVP, mMVP, mScale );
	MatrixMultiply( mMVP, mMVP, mTrans );
	MatrixMultiply( mMVP, mMVP, XE::x_mViewProjection );
	// 8픽셀 크기로 블러가 되게 하려고 8픽셀 여유를 뒀다.
	// 현재 쉐이더를 얻어온다
	GRAPHICS_GL->sSetShader( GRAPHICS_GL->GetpShaderColTex() );
	XShader *pShader = XGraphicsOpenGL::sGetShader();
	pShader->SetUniformMVP( mMVP );
	pShader->SetUniformColor( 1.0f, 1.0f, 1.0f, 1.0f );
	//	pShader->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f );
	//    GRAPHICS_GL->GetpBaseShader()->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f );
	//    GRAPHICS_GL->GetpBaseShader()->SetShader( XE::x_mViewProjection, 1.0f, 1.0f, 1.0f, 1.0f );

	CHECK_GL_ERROR();
	
	glEnable( GL_BLEND );
	if( bBlendAdd )
		glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	else
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	//    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
#ifdef _XVAO
	glBindVertexArrayOES( 0 );
#endif
	CHECK_GL_ERROR();
	
	glBindBuffer( GL_ARRAY_BUFFER, 0 );
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
	glEnableVertexAttribArray( XE::ATTRIB_POS );
	glEnableVertexAttribArray( XE::ATTRIB_COLOR );
	glEnableVertexAttribArray( XE::ATTRIB_TEXTURE );
	glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos );
	glVertexAttribPointer( XE::ATTRIB_TEXTURE, 2, GL_FLOAT, GL_FALSE, 0, tex );
	glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col );
	glEnableVertexAttribArray( XE::ATTRIB_SIZE );
	CHECK_GL_ERROR();
	
	// bind texture
	XGraphicsOpenGL::sBindTexture( idTexture );
	CHECK_GL_ERROR();
	

	glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
	CHECK_GL_ERROR();
	
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	CHECK_GL_ERROR();
	
}
Esempio n. 21
0
void XGraphicsOpenGL::FillRect( float x, float y, float w, float h, XCOLOR collt, XCOLOR colrt, XCOLOR collb, XCOLOR colrb  )
{
	
	CHECK_GL_ERROR();
	
#define _XXR(C)	(XCOLOR_RGB_R(C) / 255.0f)
#define _XXG(C)	(XCOLOR_RGB_G(C) / 255.0f)
#define _XXB(C)	(XCOLOR_RGB_B(C) / 255.0f)
#define _XXA(C)	(XCOLOR_RGB_A(C) / 255.0f)
	if( w == 0 || h == 0 )	return;
		if( w < 0 )
		{
				x -= w;     // 좌측 좌표를 -w만큼 이동시켜주고
				w = -w;     // w는 부호 바꿈
		}
		if( h < 0 )
		{
				y -= h;
				h = -h;
		}
	if( x > GetViewportRight() || y > GetViewportBottom() )
		return;
	if( x + w < 0 || y + h < 0 )
		return;
	
	//	if( x > GetScreenWidth() || y > GetScreenHeight() )
	//		return;
	//	if( w < 0 || h < 0 )
	//		return;
	
	
//	GLfloat r, g, b, a;
//	r = XCOLOR_RGB_R(color) / 255.0f;
//	g = XCOLOR_RGB_G(color) / 255.0f;
//	b = XCOLOR_RGB_B(color) / 255.0f;
//	a = XCOLOR_RGB_A(color) / 255.0f;
	//	if( a != 255 )	glEnable(GL_BLEND);		// 이거 자주불러주면 부하걸릴거 같다. 외부에서 블럭단위로 셋하게 하자.
	
	// width-1이 맞나? 안하는게 맞나?
	GLfloat pos[8] = { 0, h, w, h, 0, 0, w, 0 } ;
	GLfloat col[16] = {  _XXR(collb), _XXG(collb),_XXB(collb),_XXA(collb),	// 좌하
						 _XXR(colrb), _XXG(colrb),_XXB(colrb),_XXA(colrb),	// 우하
						 _XXR(collt), _XXG(collt),_XXB(collt),_XXA(collt),	// 좌상
						 _XXR(colrt), _XXG(colrt),_XXB(colrt),_XXA(colrt)	};	// 우상
		MATRIX mModel;
		MATRIX mMVP;
		MatrixTranslation( mModel, x, y, 0 );
		MatrixMultiply( mMVP, mModel, XE::x_mViewProjection );
		GetpColorShader()->SetShader( mMVP, 1.0f, 1.0f, 1.0f, 1.0f );
//    GetpColorShader()->SetMatrixModel( mModel );
		
	glEnable(GL_BLEND);
//	glDisable( GL_TEXTURE_2D );
#ifdef _XVAO
		glBindVertexArray( 0 );
#endif
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
		glDisableVertexAttribArray( XE::ATTRIB_TEXTURE );
		glEnableVertexAttribArray( XE::ATTRIB_POS );
		glVertexAttribPointer( XE::ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, 0, pos);
		glEnableVertexAttribArray( XE::ATTRIB_COLOR );
		glVertexAttribPointer( XE::ATTRIB_COLOR, 4, GL_FLOAT, GL_FALSE, 0, col);
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	CHECK_GL_ERROR();
	

//	glEnable( GL_TEXTURE_2D );
	
}
Esempio n. 22
0
bool AppCore::render()
{	
#if !DISCARD_SKYBOX
	// Try to load textures if not already completed
	if (_staticTextureCompleteCount <= 6) loadStaticTextureIfAvailable();
#endif

	APIFactory::GetInstance().lock(OPENGL_LOCK);
	
	double timestamp = APIFactory::GetInstance().getTimeInMS();
	
#if !(RENDER_OCTREE_DEBUG_VOXELS || USE_STATIC_POINT_CLOUD)
	if		(   !(_currentCameraParameterRequest & 1) && 
				 (timestamp - _lastCameraParameterChangeTimestamp > WVS_RELOAD_DELAY[0]))
	{
		// Request 1/4 of screen resolution from WVS
		requestPointCloudForCurrentView(4);
		_currentCameraParameterRequest |= 1;
	}
	else if	(   !(_currentCameraParameterRequest & 2) && 
				 (timestamp - _lastCameraParameterChangeTimestamp > WVS_RELOAD_DELAY[1]))
	{
		// Request full screen resolution from WVS
		requestPointCloudForCurrentView(1);
		_currentCameraParameterRequest |= 3;
	}
#endif

	if (_isUserInputMode) _renderingRequired = true;
	if (_renderQuality < 1.0f) _renderingRequired = true;

#if !(RENDER_OCTREE_DEBUG_VOXELS || USE_STATIC_POINT_CLOUD)
	if (_isNewDataAvialable)
	{
		_renderingRequired = true;
		_isNewDataAvialable = false;
	}
#endif

	if (!_renderingRequired)
	{
		APIFactory::GetInstance().unlock(OPENGL_LOCK);
		APIFactory::GetInstance().processUserInterfaceEvents();
		return false;
	}
	_renderingRequired = false;
	
	// Updates the view frustum that is used for culling etc. based on the current
	// camera parameters
	_viewFrustum->updateCameraViewParameterCache();
	
	// Clear context
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
#if !DISCARD_SKYBOX
	// Render Skybox and ground plane
	if (_staticTextureCompleteCount > 0)
	{
		glUseProgram(_textureShaderProgram.handle);

		glUniformMatrix4fv(	_textureShaderProgram.uniforms[SHADER_UNIFORM_VIEW_PROJECTION_MATRIX],
							1, GL_FALSE, _viewFrustum->getViewProjectionMatrixCachePtr()->f);
							
		MATRIX model;
		MatrixTranslation(model,	_viewFrustum->getCameraPostionCachePtr()->x,
									_viewFrustum->getCameraPostionCachePtr()->y,
									_viewFrustum->getCameraPostionCachePtr()->z);
		glUniformMatrix4fv(	_textureShaderProgram.uniforms[SHADER_UNIFORM_MODEL_MATRIX],
							1, GL_FALSE, model.f);
		
		_skybox->render();
	}
#endif

	// Render points
    glUseProgram(_pointShaderProgram.handle);

	glUniform3fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_REGION_ORIGIN],
					OCTREE_LEAF_LEVEL + 1, _octree->getRegionOrginArray());
	
	glUniform1fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_VOXEL_INCIRCLE_DIAMETER],
					OCTREE_LEAF_LEVEL + 1,
					_octree->getVoxelIncircleDiameterArray());

	glUniform1fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_NODE_INCIRCLE_DIAMETER],
					OCTREE_LEAF_LEVEL + 1,
					_octree->getNodeIncircleDiameterArray());
					
	glUniform1fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_VOXEL_SCREENSIZE_CIRCUMCIRCLE_RADIUS],
					OCTREE_LEAF_LEVEL + 1,
					_voxelScreensizeCircumcircleRadius);
						
	// Set camera position (necessary for backface culling)
	glUniform3fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_CAMERA_POSITION],
					1, (GLfloat*)(_viewFrustum->getCameraPostionCachePtr()));
					
	glUniformMatrix4fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_PROJECTION_MATRIX],
						1, GL_FALSE, _viewFrustum->getProjectionMatrixCachePtr()->f);
						
	glUniformMatrix4fv(	_pointShaderProgram.uniforms[POINT_SHADER_UNIFORM_VIEW_MATRIX],
						1, GL_FALSE, _viewFrustum->getViewMatrixCachePtr()->f);
												

#if COMPACT_NODE_REGION_ENCODING
	const uint32_t regionVoxelFactor = 1;
	const uint8_t regionLevelStride = 4;
	const uint32_t regionLevelDataType = GL_UNSIGNED_BYTE;
#else
	const uint32_t regionVoxelFactor = 2;
	const uint8_t regionLevelStride = 8;
	const uint32_t regionLevelDataType = GL_UNSIGNED_SHORT;
#endif

#if DIRECT_VBO
	#if DIRECT_VBO_DOUBLE_BUFFERED	
	if (bufferID == 0) bufferID = 1; else bufferID = 0;
	#endif

	glBindBuffer(GL_ARRAY_BUFFER, _dataVBO[bufferID]);
	uint32_t* const gpuBuffer = (uint32_t*)glMapBufferOES(GL_ARRAY_BUFFER, GL_WRITE_ONLY_OES);

	uint32_t* const regionLevelBuffer = gpuBuffer;
	uint32_t* const voxelBuffer = gpuBuffer + GPU_MAX_POINTS * regionVoxelFactor;
	
	glVertexAttribPointer(	POINT_SHADER_ATTRIBUTE_DATA1,
							4,
							GL_UNSIGNED_BYTE,
							GL_FALSE,
							0,
							(void *)(GPU_MAX_POINTS * regionLevelStride));
							
	glVertexAttribPointer(	POINT_SHADER_ATTRIBUTE_DATA2,
							4,
							regionLevelDataType,
							GL_FALSE,
							0,
							0);	

	glEnableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA1);	
	glEnableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA2);

	// Traverse octree, copy points into buffer and call rendering callback 
	_octree->copyPointsToBuffer(
		_renderQuality,
		!_isInteractiveMode,
		regionLevelBuffer,
		voxelBuffer,
		&_pointsToRenderCount,
		&_renderingRequired);
	
	glDisableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA1);
	glDisableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA2);
	
	glUnmapBufferOES(GL_ARRAY_BUFFER);
		
#elif NO_VBO
	uint32_t* const regionLevelBuffer = _gpuBuffer;
	uint32_t* const voxelBuffer = _gpuBuffer + GPU_MAX_POINTS * regionVoxelFactor;
	
	glVertexAttribPointer(	POINT_SHADER_ATTRIBUTE_DATA1, 
							4,
							GL_UNSIGNED_BYTE,
							GL_FALSE,
							4,
							voxelBuffer);
							
	glVertexAttribPointer(	POINT_SHADER_ATTRIBUTE_DATA2,
							4,
							regionLevelDataType,
							GL_FALSE,
							regionLevelStride,
							regionLevelBuffer);	

	glEnableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA1);	
	glEnableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA2);
	
	// Traverse octree, copy points into buffer and call rendering callback 	
	_octree->copyPointsToBuffer(
		_renderQuality,
		!_isInteractiveMode,
		regionLevelBuffer,
		voxelBuffer,
		&_pointsToRenderCount,
		&_renderingRequired);	

	glDisableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA1);
	glDisableVertexAttribArray(POINT_SHADER_ATTRIBUTE_DATA2);	
	
#endif
		
#ifdef OPENGL_ES
	const GLenum discard_attachments[] = { GL_DEPTH_ATTACHMENT };
	glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discard_attachments);
#endif

	if (_renderingRequired & Octree::OCTREE_RENDERING_CANCELED)
	{
		APIFactory::GetInstance().unlock(OPENGL_LOCK);
		
		//TODO: In case we overestimate the render quality by far this becomes a stupid loop
		_octree->estimateInteractiveRenderQuality(&_renderQuality, OCTREE_INTERACTIVE_RENDERING_POINT_THRESHOLD);
		return false;
	}

#if BENCHMARK_1_MILLION
	if (_pointsToRenderCount >= 1000000)
	{
		_renderingRequired = true;
		double time = APIFactory::GetInstance().getTimeInMS();
		printf("%f\n", time - _lastFrame);
		_lastFrame = time;
	}
#endif

	if (_isUserInputMode || ((timestamp - _lastCameraParameterChangeTimestamp) < 500))
	{
		// Within 500ms we consider any input as movement
		double_t renderingTimeInMS = APIFactory::GetInstance().getTimeInMS() - timestamp;
		if (renderingTimeInMS > (1000.0 / MINIMUM_FRAMERATE))
		{
			// Time to render last frame took longer than target framerate.
			// Lower render quality to speed up framerate.
			_renderQuality -= RENDER_QUALITY_FINE_ADJUSTMENT;
			_nodeRestoreQuota = 0;
		}
		else if (renderingTimeInMS < (1000.0 / MAXIMUM_FRAMERATE))
		{
			_renderQuality += RENDER_QUALITY_FINE_ADJUSTMENT;
			_nodeRestoreQuota = 32;
		}
		
		_renderingRequired = true;
	}
	else
	{
		// No movement with in the last 500ms. Increase render quality
		_renderQuality += RENDER_QUALITY_COARSE_ADJUSTMENT;
		_isInteractiveMode = false;
	}

	// Check range of render quality
	if (_renderQuality > 1.0f) _renderQuality = 1.0f;
	else if (_renderQuality < RENDER_QUALITY_FINE_ADJUSTMENT)
		_renderQuality = RENDER_QUALITY_FINE_ADJUSTMENT;
	
	APIFactory::GetInstance().unlock(OPENGL_LOCK);
	
	return true;
}