アスペクト比を持つ-どのように行うのですか。(D3Dビューポートのセットアップ)

StackOverflow https://stackoverflow.com/questions/1222340

質問

Allrightえるし、私が質問したとして白濁していますね。可能にしてから接続し直してください。

私は3つのプロパティを設定処理のためのD3D装置 の解像度のデバイスが実行(フル画面).-身体面の比率をモニターとしての分画およびfloat:1です。4:3&1.33).-比源分解能(解像度そのもののような議論の余地がある問題と言って少以上の比率のレンダリングしたいという決議がなげていくことができれば理想で行います。

します:

// -- figure out aspect ratio adjusted VPs  -- 

m_nativeVP.Width = xRes;
m_nativeVP.Height = yRes;
m_nativeVP.X = 0;
m_nativeVP.Y = 0;
m_nativeVP.MaxZ = 1.f;
m_nativeVP.MinZ = 0.f;

FIX_ME // this does not cover all bases -- fix!
uint xResAdj, yResAdj;  
if (g_displayAspectRatio.Get() < g_renderAspectRatio.Get())
{
    xResAdj = xRes;
    yResAdj = (uint) ((float) xRes / g_renderAspectRatio.Get());
}
else if (g_displayAspectRatio.Get() > g_renderAspectRatio.Get())
{
    xResAdj = (uint) ((float) yRes * g_renderAspectRatio.Get());
    yResAdj = yRes;     
}
else // ==
{
    xResAdj = xRes;
    yResAdj = yRes;
}

m_fullVP.Width = xResAdj;
m_fullVP.Height = yResAdj;
m_fullVP.X = (xRes - xResAdj) >> 1; 
m_fullVP.Y = (yRes - yResAdj) >> 1; 
m_fullVP.MaxZ = 1.f;
m_fullVP.MinZ = 0.f;

現在のとg_displayAspectRatio equals の比率xRes/yRes(=わからデバイスの解像度)では、このコードはいかに期待されます。しかし、その2値な関係(例えば、人間は4:3の決議は、16:10画面のハードウェア-延伸)別のステップを補正するために必要で、私に戸惑うかがいます。

(およびp.sを使っていC-スタイル鋳原子の種類、生す:-))

役に立ちましたか?

解決

いと仮定して何を達成したいのは"広場"予測などき大きくしたいかという円できます。

だけでは遊びは投影(カメラ側面の比である。通常の場合、モニターに保つのピクセルスクエアとだけはカメラの縦横比等へのビューポートのアスペクト比:

viewport_aspect_ratio = viewport_res_x / viewport_res_y;
camera_aspect_ratio = viewport_aspect_ratio;

に伸びた場合について説明していただけま(4:3画像を伸ばして、16:10画面の例には、ピクセルがないの広場となっているかについて学び取ることを考慮にカメラのアスペクト比:

stretch_factor_x = screen_size_x / viewport_res_x;
stretch_factor_y = screen_size_y / viewport_res_y;
pixel_aspect_ratio = stretch_factor_x / stretch_factor_y;
viewport_aspect_ratio = viewport_res_x / viewport_res_y;
camera_aspect_ratio = viewport_aspect_ratio * pixel_aspect_ratio;

場所 screen_size_xscreen_size_y ている複数のサイズのモニターなど16:10)となります。

しかしながらだとスクエア画素数を持っていない場合、特定の理由などのモニターが誤った報告書の身体より一回り以上大きな情報システム、情報。モニタリングなストレッチ、鉱例えば、常に1:1ピクセルの縦横比を追加し黒境のための低解決にはつながりませんでした。

編集

したい場合は調整してビューポートの一部の縦横比を合わせで任意の解決そしてなにができるように:

viewport_aspect_ratio = 16.0 / 10.0; // The aspect ratio you want your viewport to have
screen_aspect_ratio = screen_res_x / screen_res_y;

if (viewport_aspect_ratio > screen_aspect_ratio) {
    // Viewport is wider than screen, fit on X
    viewport_res_x = screen_res_x;
    viewport_res_y = viewport_res_x / viewport_aspect_ratio;
} else {
    // Screen is wider than viewport, fit on Y
    viewport_res_y = screen_res_y;
    viewport_res_x = viewport_res_y * viewport_aspect_ratio;
}

camera_aspect_ratio = viewport_res_x / viewport_res_y;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top