为什么更改“相机”的Z位置不会显示原语?

时间:2017-10-03 00:28:36

标签: c++ camera directx directx-9

我有一个未转换的结构,其顶点坐标将形成一个三角形:

struct utVertex ut_Vertex[] =
{
    { 2.5f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), }, //a
    { 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), }, //b
    { -2.5f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },//c
};

enter image description here

上面的图像应该(不确定,因为z轴可以被反转,+可能应该在哪里 - 是)根据我的代码是正确的:

D3DXMatrixLookAtLH(&matView,
        &D3DXVECTOR3(0.0f, 0.0f, 10.0f),
        &D3DXVECTOR3(0.0f, 0.0f, 0.0f),
        &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
    d3dDevice->SetTransform(D3DTS_VIEW, &matView);

上图中的蓝点应该是基于此代码的相机位置。 (请告诉我,如果我错了)。

这会在屏幕上正确绘制三角形。

enter image description here

现在,如果我将相机位置更改为-10.0f而不是10.0f (我认为),这就是相机的位置:

enter image description here

但是仍然在关注0.0f, 0.0f, 0.0f。 如果是这样,那么为什么改变'相机'的Z位置不会显示基元(三角形)?

没有显示: enter image description here

1 个答案:

答案 0 :(得分:1)

您使用的多边形是单面的,因此从后面看时它们不可见。要在反转相机时显示三角形,您需要添加另一个具有相同点但在相反方向上列出的多边形 - (a,c,b)而不是(a,b,c) - 或在clc clear N(1) = 2.5; %1st gear N(2) = 2.0; %2nd ^ N(3) = 1.0; %3rd ^ Diff = 2.3; %Final drive u = 0.8; fr = 0.015; Rt = .303; %Tire radius in m W = 13400; %Weight in N rho = 1.25; %Air density in kg/m^3 A = 2.10; %Frontal alrea in m^2 Cd = 0.38; %Coeff of drag L = 2.61; %Wheelbase in m LH = 3.93; %L/H ratio FR = 51.5; %F/R weight ratio theta1 = 0; %Road incline theta2 = 5; %Road incline Ftmax = 3000; m = W/9.81; w = 0.001; xdot = 0.001; dbstop if error % T = -(0.00108*w^2)+0.50143+111.77086 %Engine tq lookup for i = 1:0.001:200 %Total time of 200 seconds in 0.001 second intervals % if i<.001 % end T(i) = -(0.00108*w(i)^2)+0.50143*w(i)+111.77086; %Engine tq lookup Ft(i) = T(i)*N(1)*Diff/Rt; %Calculate tractive force if Ft>Ftmax %Check for traction limit Ft = Ftmax; end xddot(i) = (1/m)*(Ft(i)/xdot(i)-W*u*(1+xdot(i)*3.6/160)-0.5*rho*Cd*A*xdot(i)^2-W*sin(theta1));% Using m/s for velocity xdot(i) = xddot(i)*0.001+xdot(i); %Velocity calculation w(i) = xdot(i)/Rt*N(1)*Diff; %Engine speed calculation end 数组中交换其中两个点。