空間用の、点クラスを作ります。
#ifndef ___MYPOINT3D
#define ___MYPOINT3D
//
// 空間座標
//
#include <math.h>
#include <MyMath.h>
#include <MyPoint.h>
class MyPoint3D : public MyPoint{
public:
double x3, y3, z3;
// コンストラクタ
MyPoint3D(){
x3 = y3 = z3 =0;
}
// 座標を代入する
void set(double x1, double y1, double z1){
int xx = 35; // x軸からの角度
int yy = 30; // xy平面からの角度
x3 = x1;
y3 = y1;
z3 = z1;
x = -x3 * sin(DegreeToRadian(xx)) + y3 * cos(DegreeToRadian(xx));
y = -x3 * cos(DegreeToRadian(xx)) * sin(DegreeToRadian(yy))
- y3 * sin(DegreeToRadian(xx)) * sin(DegreeToRadian(yy))
+ z3 * cos(DegreeToRadian(yy));
}
};
#endif
座標軸を描いてみます。
//
// MyApp.h
//
#include <MyPoint3D.h>
#include <MyDC.h>
class MyApp : public MyMainWnd{
public:
// WM_PAINT
void wmPaint(HDC hdc){
RECT rc;
MyPoint3D p0, p;
GetClientRect(hWnd, &rc);
myTrans.set(50, 0, 0, -50, rc.right / 2, rc.bottom / 2);
// 座標軸を描く----------------------------
p0.set(0, 0, 0); // 原点
// x軸
MoveToEx(hdc, p0.px(), p0.py(), NULL);
p.set(3, 0, 0),
LineTo(hdc, p.px(), p.py());
// y軸
MoveToEx(hdc, p0.px(), p0.py(), NULL);
p.set(0, 3, 0),
LineTo(hdc, p.px(), p.py());
// z軸
MoveToEx(hdc, p0.px(), p0.py(), NULL);
p.set(0, 0, 3),
LineTo(hdc, p.px(), p.py());
}
};
実行画面です。