Introdution to 3D Game Programming With DirectX11 第2章 习题解答

16 篇文章 0 订阅

8 .不是

9.不是

18.

// Win32Project1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	int m;
	int n;
	cout << "Please type the row number:" << endl;
	cin >> m;
	cout << "Please type the col number:" << endl;
	cin >> n;
	cout << "Please type the Matrix[" << m << "]" << "[" << n << "] elemnts" << endl;
	double **Matrix = new double *[m];
	for(int i = 0; i < m; i++)
	{
		Matrix[i] = new double[n];
	}
	for(int i = 0; i < m; i++)
	{
		for(int j = 0; j < n; j++)
		{
			cin >> Matrix[i][j];
		}
	}

	cout << "The Matrix is:" << endl;
	for(int i = 0; i < m; i++)
	{
		for(int j = 0; j < n; j++)
		{
			cout << Matrix[i][j] << " ";
		}
		cout << endl;
	}

	cout << "The Transform Matrix is:" << endl;
	for(int j = 0; j < n; j++)
	{
		for(int i = 0; i < m; i++)
		{
			cout << Matrix[i][j] << " ";
		}
		cout << endl;
	}


	for(int i = 0; i < m; i++)
	{
		delete []Matrix[i];
	}
	delete []Matrix;	
	

	return 0;
}

19.

// Win32Project2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;
double det4(double M[4][4]);
double det3(double M[3][3]);
double (*mirrorA(double M[4][4], int r, int c,double (&Matrix)[3][3]))[3];
double (*transpose(double M[4][4], double(&transposeMatrix)[4][4]))[4];
double (*cofactorMatrix(double M[4][4], double (&cMatrix)[4][4]))[4];


int _tmain(int argc, _TCHAR* argv[])
{
	double Matrix[4][4];
	cout << "Please type the Matrix element:" << endl;
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
		{
			cin >> Matrix[i][j];
		}
	cout << "The Matrix is:" << endl;
	for(int i = 0; i < 4; i++)
	{
		for(int j = 0; j < 4; j++)
		{
			cout << Matrix[i][j] <<" ";
		}
		cout << endl;
	}
	cout << "The Matrix det is:" << endl;
	double det;
	det = det4(Matrix);
	cout << det << endl;
	double coMatrix[4][4];
	cofactorMatrix(Matrix, coMatrix);
	double adjointMtric[4][4];
	transpose(coMatrix, adjointMtric);
	cout << "The Inverse Matrix det is:" << endl;

	double inverseMatrix[4][4];
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
		{
			inverseMatrix[i][j] = adjointMtric[i][j] / det;
		}
	for(int i = 0; i < 4; i++)
		{
			for(int j = 0; j < 4; j++)
			{
				cout << inverseMatrix[i][j] << " ";
			}
			cout << endl;
		}
	return 0;
}

double det4(double M[4][4])
{
	double det =  M[0][0]*(M[1][1]*(M[2][2]*M[3][3] -M[2][3]*M[3][2]) -M[1][2]*(M[2][1]*M[3][3] -M[2][3]*M[3][1]) +M[1][3]*(M[2][1]*M[3][2] -M[2][2]*M[3][1]))
		         -M[0][1]*(M[1][0]*(M[2][2]*M[3][3] -M[2][3]*M[3][2]) -M[1][2]*(M[2][0]*M[3][3] -M[2][3]*M[3][0]) +M[1][3]*(M[2][0]*M[3][2] -M[2][2]*M[3][0]))
				 +M[0][2]*(M[1][0]*(M[2][1]*M[3][3] -M[2][3]*M[3][1]) -M[1][1]*(M[2][0]*M[3][3] -M[2][3]*M[3][0]) +M[1][3]*(M[2][0]*M[3][1] -M[2][1]*M[3][0]))
				 -M[0][3]*(M[1][0]*(M[2][1]*M[3][2] -M[2][2]*M[3][1]) -M[1][1]*(M[2][0]*M[3][2] -M[2][2]*M[3][0]) +M[1][2]*(M[2][0]*M[3][1] -M[2][1]*M[3][0]));
	return det;
}

double det3(double M[3][3])
{
	double det = M[0][0]*(M[1][1]*M[2][2] -M[1][2]*M[2][1]) -M[0][1]*(M[1][0]*M[2][2] -M[1][2]*M[2][0]) +M[0][2]*(M[1][0]*M[2][1] -M[1][1]*M[2][0]);
	return det;
}

double (*mirrorA(double M[4][4], int r, int c,double (&Matrix)[3][3]))[3]
{
	int m,n;
	//double Matrix[3][3];
	for(int i = 0; i < 4; i++)
	{
		if(i == r)
		{
			continue;
		}else if(i < r)
		{
			m = i;
		}else if(i > r)
		{
			m = i-1;
		}

		for(int j = 0; j < 4; j++)
		{
			if(j == c)
			{
				continue;
			}else if(j < c)
			{
				n = j;
			}else if(j > c)
			{
				n = j-1;
			}
			Matrix[m][n] = M[i][j];
		}
	}
	return Matrix;
}

double (*transpose(double M[4][4], double(&transposeMatrix)[4][4]))[4]
{
	//double transposeMatrix[4][4];
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
		{
			transposeMatrix[i][j] = M[j][i];
		}
		return transposeMatrix;
}

double (*cofactorMatrix(double M[4][4], double (&cMatrix)[4][4]))[4]
{
	//double cMatrix[4][4];
	double mMatrix[3][3];
	for(int i = 0; i < 4; i++)
		for(int j = 0; j < 4; j++)
		{
			cMatrix[i][j] = pow((-1),(i+j))*det3(mirrorA(M, i, j, mMatrix));
		}
		return cMatrix;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <com.example.myapplication.GameView android:id="@+id/gameView" android:layout_width="match_parent" android:layout_height="match_parent"/> <TextView android:id="@+id/score" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:paddingTop="10dp" android:text="0" android:textColor="@color/black" android:textSize="18dp" /> <RelativeLayout android:visibility="gone" android:id="@+id/relative" android:layout_width="300dp" android:layout_height="200dp" android:layout_centerInParent="true" android:background="@drawable/introdution" > <TextView android:id="@+id/scoreText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:backgroundTint="@color/black" android:text="分数:" android:textSize="18dp" /> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:backgroundTint="#0068B5" android:text="重新开始" android:textSize="18dp" /> </RelativeLayout> <RelativeLayout android:id="@+id/introdution" android:layout_width="300dp" android:layout_height="200dp" android:layout_centerInParent="true" android:background="@drawable/shuoming"> <Button android:id="@+id/btn_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:backgroundTint="#0068B6" android:text="开始游戏" android:textSize="18dp" /> </RelativeLayout> </RelativeLayout>解释这段布局文件代码
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值