Exemplo n.º 1
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

}
Exemplo n.º 2
0
void MatrixOrthoRH(
	MATRIX	&mOut,
	const float w,
	const float h,
	const float zn,
	const float zf,
	const bool  bRotate)
{
	mOut.f[ 0] = 2 / w;
	mOut.f[ 1] = 0;
	mOut.f[ 2] = 0;
	mOut.f[ 3] = 0;

	mOut.f[ 4] = 0;
	mOut.f[ 5] = 2 / h;
	mOut.f[ 6] = 0;
	mOut.f[ 7] = 0;

	mOut.f[ 8] = 0;
	mOut.f[ 9] = 0;
	mOut.f[10] = 1 / (zn - zf);
	mOut.f[11] = zn / (zn - zf);

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

	if (bRotate)
	{
		MATRIX mRotation, mTemp = mOut;
		MatrixRotationZ(mRotation, -90.0f*PIf/180.0f);
		MatrixMultiply(mOut, mRotation, mTemp);
	}
}
inline void  GraphicsSystem::MatrixRotate(float x, float y, float z, float a)
{
	MatrixStack[curMatrix].X.x = 1.0f;
	MatrixStack[curMatrix].X.y = 0.0f;
	MatrixStack[curMatrix].Y.x = 0.0f;
	MatrixStack[curMatrix].Y.y = 1.0f;
	MatrixStack[curMatrix].Z.z = 1.0f;
// 	MatrixStack[curMatrix] *= Quat(AxisAngle(x, y, z, a));
	MatrixStack[curMatrix] *= MatrixRotationZ(z);
    ResetViewMatrix();
}
Exemplo n.º 4
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

}
Exemplo n.º 5
0
void MatrixPerspectiveFovRH(
	MATRIX	&mOut,
	const float	fFOVy,
	const float	fAspect,
	const float	fNear,
	const float	fFar,
	const bool  bRotate)
{
	float f, n, fRealAspect;

	if (bRotate)
		fRealAspect = 1.0f / fAspect;
	else
		fRealAspect = fAspect;

	// cotangent(a) == 1.0f / tan(a);
	f = 1.0f / (float)tan(fFOVy * 0.5f);
	n = 1.0f / (fNear - fFar);

	mOut.f[ 0] = f / fRealAspect;
	mOut.f[ 1] = 0;
	mOut.f[ 2] = 0;
	mOut.f[ 3] = 0;

	mOut.f[ 4] = 0;
	mOut.f[ 5] = f;
	mOut.f[ 6] = 0;
	mOut.f[ 7] = 0;

	mOut.f[ 8] = 0;
	mOut.f[ 9] = 0;
	mOut.f[10] = (fFar + fNear) * n;
	mOut.f[11] = -1;

	mOut.f[12] = 0;
	mOut.f[13] = 0;
	mOut.f[14] = (2 * fFar * fNear) * n;
	mOut.f[15] = 0;

	if (bRotate)
	{
		MATRIX mRotation, mTemp = mOut;
		MatrixRotationZ(mRotation, -90.0f*PIf/180.0f);
		MatrixMultiply(mOut, mTemp, mRotation);
	}
}
Exemplo n.º 6
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 );
}
Exemplo n.º 7
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 );
}
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);
}
void NodeControlViewImpl::RemoveRoll(const float *pCOI3)
{
	collada::Property* pProp = m_transform;

	float4x4 w2 = m_node->GetWorld(NULL);
	float4x4 upA = m_context->GetUpAxis();

	float4x4 w2Up = w2*upA;

	float4x4 rot;
	float xz2 = sqrt(w2Up._11*w2Up._11+w2Up._13*w2Up._13);
	float alpha = -atan(w2Up._12/xz2);

	MatrixRotationZ(&rot, alpha);

	float4x4 m0;
	pProp->GetValue(m0);
	MatrixTranspose(&m0, &m0);


	if( pCOI3 )
	{
		float4x4 mcoi(w2);

		mcoi(3,0) = pCOI3[0]; // x
		mcoi(3,1) = pCOI3[1]; // y
		mcoi(3,2) = pCOI3[2]; // z

		float4x4 wI = m_node->GetWorldI(NULL);
		float4x4 toCOI = mcoi*wI;
		float4x4 fromCOI;
		MatrixInverse(&fromCOI, 0, &toCOI);
		rot = fromCOI*rot*toCOI;
	}
	float4x4 m = rot*m0;
	MatrixTranspose(&m, &m);
	pProp->SetValue(m);
}
Exemplo n.º 10
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);
        }