ホーム › Devices.Sensors › VEC3D
VEC3D
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| X | FLOAT | 4 | +0 | +0 | 3次元ベクトルのX成分を表す単精度浮動小数点値。 |
| Y | FLOAT | 4 | +4 | +4 | 3次元ベクトルのY成分を表す単精度浮動小数点値。 |
| Z | FLOAT | 4 | +8 | +8 | 3次元ベクトルのZ成分を表す単精度浮動小数点値。 |
各言語での定義
#include <windows.h>
// VEC3D (x64 12 / x86 12 バイト)
typedef struct VEC3D {
FLOAT X;
FLOAT Y;
FLOAT Z;
} VEC3D;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct VEC3D
{
public float X;
public float Y;
public float Z;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure VEC3D
Public X As Single
Public Y As Single
Public Z As Single
End Structureimport ctypes
from ctypes import wintypes
class VEC3D(ctypes.Structure):
_fields_ = [
("X", ctypes.c_float),
("Y", ctypes.c_float),
("Z", ctypes.c_float),
]#[repr(C)]
pub struct VEC3D {
pub X: f32,
pub Y: f32,
pub Z: f32,
}import "golang.org/x/sys/windows"
type VEC3D struct {
X float32
Y float32
Z float32
}type
VEC3D = record
X: Single;
Y: Single;
Z: Single;
end;const VEC3D = extern struct {
X: f32,
Y: f32,
Z: f32,
};type
VEC3D {.bycopy.} = object
X: float32
Y: float32
Z: float32struct VEC3D
{
float X;
float Y;
float Z;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; VEC3D サイズ: 12 バイト(x64)
dim st, 3 ; 4byte整数×3(構造体サイズ 12 / 4 切り上げ)
; X : FLOAT (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; Y : FLOAT (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; Z : FLOAT (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global VEC3D
#field float X
#field float Y
#field float Z
#endstruct
stdim st, VEC3D ; NSTRUCT 変数を確保
st->X = 100
mes "X=" + st->X