「頂点」の版間の差分
ナビゲーションに移動
検索に移動
imported>Administrator |
imported>Administrator |
||
2行目: | 2行目: | ||
== 概要 == | == 概要 == | ||
− | 2つの頂点を使えば線を引ける。 | + | 2つの頂点を使えば線を引ける。[[8ビット]]時代の[[BASIC]]にもそんな描画命令よくあったな。 |
3つの頂点を使えば面を描ける。いわゆる[[ポリゴン]]だ。 | 3つの頂点を使えば面を描ける。いわゆる[[ポリゴン]]だ。 |
2018年8月31日 (金) 09:34時点における最新版
頂点(英語:vertex)とは、ベクトルで図形を描く際に用いられる制御点のことである。
概要[編集 | ソースを編集]
2つの頂点を使えば線を引ける。8ビット時代のBASICにもそんな描画命令よくあったな。
3つの頂点を使えば面を描ける。いわゆるポリゴンだ。
保持する情報[編集 | ソースを編集]
3Dのポリゴンであれば頂点は最低限度の情報として「XYZ座標」を持つ。これがないと始まらない。その他にも陰影をつけるライティングに使用する「法線」や「頂点カラー」、テクスチャを貼るための「UV座標」を持つこともある。
近代的なプログラマブルシェーダーであれば、頂点のデータ・フォーマットはある程度自由に定義することができる。たとえばMonoGameであれば以下のようにIVertexTypeインターフェースを継承すれば独自の頂点を定義できる。
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public struct VertexPositionColorNormalTexture : IVertexType
{
public Vector3 Position;
public Color Color;
public Vector3 Normal;
public Vector2 TextureCoordinate;
public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement((sizeof(float) * 3), VertexElementFormat.Color, VertexElementUsage.Color, 0),
new VertexElement((sizeof(float) * 3) + (4), VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement((sizeof(float) * 3 * 2) + (4), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
);
public VertexPositionColorNormalTexture(Vector3 position, Color color, Vector3 normal, Vector2 textureCoordinate)
{
Position = position;
Color = color;
normal.Normalize();
Normal = normal;
TextureCoordinate = textureCoordinate;
}
VertexDeclaration IVertexType.VertexDeclaration
{
get { return VertexDeclaration; }
}
}