LANGUAGE | スカ友 | 俺、関東の国王だけど
お読みください:
VM を作りました (x86 ではない!) + ASM
UIライブラリ(2D)を作りました | 4Dエンジン (画像)
虫は宇宙人です | 人類の品種 | 言葉の起源
日本語は海豚の言葉に由来します | ペンギン(ウルトラマン)
こんな日本語の文字を考案しました(画像) | こんな人工言語を作りました
関東無政府主義国へようこそ!
万有引力シミュレーション(太陽系・3D)
0   Γεντευ      2013年1月17日 木 7:35
前スレ(2D版) http://x0000.net/topic.aspx?id=1398-0

namespace Test03 {

using namespace std;
using namespace inst;

typedef double R;
typedef Matrix<R,3,1> R3, R31;
typedef Matrix<R,1,3> R13;
typedef Matrix<R,3,3> R33;
#define DE_R3(X) (X)(0), (X)(1), (X)(2)

inline R3 Cross(const R3& a, const R3& b) { return R3(a(1,0) * b(2,0) - a(2,0) * b(1,0), a(2,0) * b(0,0) - a(0,0) * b(2,0), a(0,0) * b(1,0) - a(1,0) * b(0,0)); }

extern R dTimeLogic, dTimeShell;
static R FpsLogic() { return 1.0 / dTimeLogic; }
static R FpsShell() { return 1.0 / dTimeShell; }

extern R TimeZoom;

extern R t;
extern R dt; // = dTimeLogic * TimeZoom

void Init();
void UpdateShell();
void Destroy();

void InitLogic();
void UpdateLogic();

const R KmPerAU = 149597870.691; // km
const R G = 6.67300e-20; // km3*kg-1*s-2
const R k = 1.3806503e-17; // km2*kg*s-2*K-1

const R m_sun = 1.98892e30; // kg

const R m_mercury = 3.3022e23; // kg
const R d_mercury = 57910000; // avg, km
const R v_mercury = 47.8725; // avg, km/s

const R m_venus = 4.8685e24; // kg
const R d_venus = 108208930; // avg, km
const R v_venus = 35.0214; // avg, km/s

const R m_earth = 5.9742e24; // kg
const R d_earth = 149597870.7; // avg, km
const R v_earth = 29.780; // avg, km/s

const R m_moon = 7.347673e22; // kg
const R d_moon = 384400; // avg, km
const R v_moon = 1.022; // avg, km/s

const R m_mars = 6.4185e23; // kg
const R d_mars = 227936640; // avg, km
const R v_mars = 24.1309; // avg, km/s

class CObject;

extern vector<SmartPtr<CObject>> AllObjects;
//typedef vector<SmartPtr<CObject>>::iterator IterAllObjects;

class CObject : public virtual IRefCount
{
public:
R3 s, v;
R m;

CObject(R3 _s, R3 _v, R _m) { s = _s; v = _v; m = _m; }

R3 f_g(const CObject *o) const
{
INST_ASSERT(o != this);

R3 Δs = o->s - s;
R norm_Δs = Norm(Δs);
return G * o->m * Δs / (norm_Δs * norm_Δs * norm_Δs);
}

R3 g_total() const
{
R3 ret;
for(int i=0; i<AllObjects.size(); i++)
if (this != AllObjects[i])
ret += f_g(AllObjects[i]);
return ret;
}

virtual R3 f_F_others(const CObject *o) const { return R3(); }

R3 F_others_total() const
{
R3 ret;
for(int i=0; i<AllObjects.size(); i++)
if (this != AllObjects[i])
ret += f_F_others(AllObjects[i]);
return ret;
}

R3 a_total() const { return g_total() + F_others_total() / m;}

R3 _v() const { return v + (a_total()) * dt; }
R3 _s() const { return s + v * dt; }


virtual void Update()
{
s = _s();
v = _v();
}
};

class CElecObject : virtual public CObject
{
public:
R e;

CElecObject(R3 _s, R3 _v, R _m, R _e)
: CObject(_s, _v, _m)
{
e = _e;
}

virtual R3 f_F_others(const CObject *o) const
{
INST_ASSERT(o != this);

SmartPtr<const CElecObject> _o = dynamic_cast<const CElecObject *>(o);

if (_o == null) return R3();

R3 D_s = _o->s - s;
R norm_D_s = Norm(D_s);
return - k * _o->e * e * D_s / (norm_D_s * norm_D_s * norm_D_s);
}
};

class CObjectX : virtual public CObject
{
public:
wstring name;
int radius;
dword color;

CObjectX(wstring _name, R3 _s, R3 _v, R _m, int _radius, dword _color)
: CObject(_s, _v, _m)
{
name = _name;
radius = _radius;
color = _color;
}
};

class CElecObjectX : virtual public CElecObject, virtual public CObjectX
{
public:
CElecObjectX(wstring _name, R3 _s, R3 _v, R _m, R _e, int _radius, dword _color)
: CElecObject(_s, _v, _m, _e), CObjectX(_name, _s, _v, _m, _radius, _color), CObject(_s, _v, _m)
{ }
};

inline SmartPtr<CObject> GetObject(int i) { return (i >=0 && i < AllObjects.size()) ? AllObjects[i] : null; }

extern R FovDeg;
inline R Fov() { return FovDeg / 180; }

extern int Stands, Looks;
inline R3 ParentCamPos() { return GetObject(Stands) ? GetObject(Stands)->s : R3(0.0, 0.0, - KmPerAU * 5.0); }
inline R3 ParentCamTarget() { return GetObject(Looks) ? GetObject(Looks)->s : R3(); }
inline R3 ParentCamK() { return Normalize(ParentCamTarget() - ParentCamPos()); }
inline R3 ParentCamI() { return Normalize(Cross(GetObject(Stands) ? R3(0,0,1) : R3(0,1,0), ParentCamK())); }
inline R3 ParentCamJ() { return Cross(ParentCamK(), ParentCamI()); }
inline R33 MatParentCamBasis() { return ParentCamI() || ParentCamJ() || ParentCamK(); }

//const R3 ChildCamPos0(0.0, 0.0, 0.0), ChildCamFront0(0.0, 0.0, KmPerAU), ChildCamUp0(0.0, KmPerAU, 0.0);
const R3 ChildCamPos0(0.0, -KmPerAU/30, -KmPerAU/10), ChildCamFront0(0.0, KmPerAU/5, KmPerAU), ChildCamUp0(0.0, KmPerAU, 0.0);

extern R3 ChildCamPos, ChildCamFront, ChildCamUp;

inline R3 CamPos() { return ParentCamPos() + MatParentCamBasis() * ChildCamPos; }
inline R3 CamFront() { return MatParentCamBasis() * ChildCamFront; }
inline R3 CamUp() { return MatParentCamBasis() * ChildCamUp; }

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Collections::Generic;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace Microsoft::DirectX;
using namespace Microsoft::DirectX::Direct3D;

typedef Microsoft::DirectX::Matrix DXMatrix;

template <class T> inline Vector3 ToDXVec(const T& x) { return Vector3(x(0), x(1), x(2)); }
template <class T> inline T FromDXVec(Vector3 x) { return T(x.X, x.Y, x.Z); }

inline String^ ToString(const R3& x) { return L"(" + x(0).ToString() + L", " + x(1).ToString() + L", " + x(2).ToString() + L")"; }

ref class Form1;

public ref class G
{
public:
static Form1 ^Form1;

static Device ^Dev;
static List<VertexBuffer ^> ^const VBObjects = gcnew List<VertexBuffer ^>();
static VertexBuffer ^VBAxises;
};

value class VertObject
{
public:
Vector3 P;
float Size;
UInt32 Color;

VertObject(Vector3 p, float size, UInt32 color)
{
P = p;
Size = size;
Color = color;
}
};

value class VertAxis
{
public:
Vector3 P;
UInt32 Color;

VertAxis(Vector3 p, UInt32 color)
{
P = p;
Color = color;
}
};

}

.......................................................................................

namespace Test03 {

using namespace std;
using namespace inst;

R dTimeLogic = 0;
R dTimeShell = 0;

R TimeZoom = 10000.0;

R t = 0;
R dt;

vector<SmartPtr<CObject>> AllObjects;
typedef vector<SmartPtr<CObject>>::iterator IterAllObjects;

R3 DirXY(R angle) { return R3(cos(angle), sin(angle), 0.0); }

void InitLogic()
{
SmartPtr<CObjectX> pSun = new CObjectX(
L"sun",
R3(0, 0, 0),
R3(0, 0, 0),
m_sun,
15,
0xFFFFFF);
AllObjects.push_back(pSun.GetPtr());

SmartPtr<CObjectX> pMercury = new CObjectX(
L"mercury",
pSun->s + d_mercury * DirXY(0),
pSun->v + v_mercury * DirXY(-PI/2),
m_mercury,
5,
0x00FFFF);
AllObjects.push_back(pMercury.GetPtr());

SmartPtr<CObjectX> pVenus = new CObjectX(
L"venus",
pSun->s + d_venus * DirXY(0),
pSun->v + v_venus * DirXY(-PI/2),
m_venus,
8,
0xFFBB00);
AllObjects.push_back(pVenus.GetPtr());

SmartPtr<CObjectX> pEarth = new CObjectX(
L"earth",
pSun->s + d_earth * DirXY(0),
pSun->v + v_earth * DirXY(-PI/2),
m_earth,
8,
0x0000FF);
AllObjects.push_back(pEarth.GetPtr());

SmartPtr<CObjectX> pMoon = new CObjectX(
L"moon",
pEarth->s + d_moon * DirXY(0),
pEarth->v + v_moon * DirXY(-PI/2),
m_moon,
2,
0xFFFF00);
AllObjects.push_back(pMoon.GetPtr());

AllObjects.push_back(INST_NEW(CObjectX,
L"tmp",
pEarth->s + 8000 * DirXY(0),
pEarth->v + 9.91 * DirXY(-PI/2),
10.0,
1,
0x00FF00).GetPtr());

SmartPtr<CObjectX> pMars = new CObjectX(
L"mars",
pSun->s + d_mars * DirXY(0),
pSun->v + v_mars * DirXY(-PI/2),
m_mars,
5,
0xFF0000);
AllObjects.push_back(pMars.GetPtr());
}

void UpdateLogic()
{
dt = dTimeLogic * TimeZoom;

for (int i=0; i<AllObjects.size(); i++)
AllObjects[i]->Update();
}

R FovDeg = 75.0;

int Stands = -1, Looks = -1;

R3 ChildCamPos = ChildCamPos0, ChildCamFront = ChildCamFront0, ChildCamUp = ChildCamUp0;

void Init()
{
G::Form1 = gcnew Form1();
G::Form1->Show();

PresentParameters ^pp = gcnew PresentParameters();
       pp->Windowed = true;
pp->SwapEffect = SwapEffect::Copy;
       pp->BackBufferCount = 1;
       pp->BackBufferWidth = 800;
       pp->BackBufferHeight = 600;
pp->AutoDepthStencilFormat = DepthFormat::D32;
pp->DeviceWindow = G::Form1->pictureBox1;

G::Dev = gcnew Device(0, DeviceType::Hardware, G::Form1->pictureBox1, CreateFlags::HardwareVertexProcessing,
gcnew array<PresentParameters^> { pp });

G::VBAxises = gcnew VertexBuffer(VertAxis::typeid, 6, G::Dev, Usage::None,
VertexFormats::Position | VertexFormats::Diffuse,
Pool::Default);

G::VBAxises->SetData(
gcnew array<VertAxis>(6) {
VertAxis(Vector3(-100 * KmPerAU, 0, 0), 0xFFFF0000),
VertAxis(Vector3(100 * KmPerAU, 0, 0), 0xFFFF0000),
VertAxis(Vector3(0, -100 * KmPerAU, 0), 0xFF00FF00),
VertAxis(Vector3(0, 100 * KmPerAU, 0), 0xFF00FF00),
VertAxis(Vector3(0, 0, -100 * KmPerAU), 0xFF0000FF),
VertAxis(Vector3(0, 0, 100 * KmPerAU), 0xFF0000FF), },
0,
LockFlags::Discard);

InitLogic();

for (int i = 0; i < AllObjects.size(); i++)
{
VertexBuffer ^vb = gcnew VertexBuffer(VertObject::typeid, 1, G::Dev, Usage::None,
VertexFormats::Position | VertexFormats::Diffuse | VertexFormats::PointSize,
Pool::Default);

CObjectX *tmp = dynamic_cast<CObjectX *>(AllObjects[i].GetPtr());

vb->SetData(
gcnew VertObject(
Vector3(0, 0, 0),
tmp ? tmp->radius : 3.0f,
(tmp ? tmp->color : 0x00FF00) | 0xFF000000),
0,
LockFlags::Discard);

G::VBObjects->Add(vb);
}
}

void RenderObjects()
{

}

void UpdateShell()
{
G::Dev->RenderState->CullMode = Cull::None;
G::Dev->RenderState->Lighting = false;
G::Dev->RenderState->DiffuseMaterialSource = ColorSource::Color1;

G::Dev->Clear(ClearFlags::Target, 0, 0, 0);

G::Dev->BeginScene();

G::Dev->Transform->View = DXMatrix::LookAtLH(ToDXVec(CamPos()), ToDXVec(CamPos() + CamFront()), ToDXVec(CamUp()));
G::Dev->Transform->Projection = DXMatrix::PerspectiveFovLH(Fov(), 4.0f / 3, KmPerAU / 50, KmPerAU * 200);

for (int i = 0; i < AllObjects.size(); i++)
{
G::Dev->Transform->World = DXMatrix::Translation(Vector3(DE_R3(AllObjects[i]->s)));
G::Dev->SetStreamSource(0, G::VBObjects[i], 0);
G::Dev->VertexFormat = G::VBObjects[i]->Description.VertexFormat;
G::Dev->DrawPrimitives(PrimitiveType::PointList, 0, 1);
G::Dev->RenderState->DiffuseMaterialSource = ColorSource::Color1;
}

G::Dev->Transform->World = DXMatrix::Identity;

G::Dev->SetStreamSource(0, G::VBAxises, 0);
G::Dev->VertexFormat = G::VBAxises->Description.VertexFormat;
G::Dev->DrawPrimitives(PrimitiveType::LineList, 0, 3);

G::Dev->EndScene();

G::Dev->Present();

G::Form1->uiLooks->Text = Looks.ToString();
G::Form1->uiStands->Text = Stands.ToString();
G::Form1->uiFov->Text = FovDeg.ToString();
G::Form1->uiTimeZoom->Text = TimeZoom.ToString();

G::Form1->uiInfo->Text = "Kernel FPS: " + FpsLogic() + "\r\n"
+ "Shell FPS: " + FpsShell();
}

void Destroy()
{
}
}
.................................................................................................................................................
private: System::Void uiLooks_TextChanged(System::Object^  sender, System::EventArgs^  e) {
try
{
Looks = int::Parse(uiLooks->Text);
}
catch (Exception ^ex)
{
Looks = -1;
}

ChildCamFront = ChildCamFront0;
ChildCamUp = ChildCamUp0;
}
private: System::Void uiStands_TextChanged(System::Object^  sender, System::EventArgs^  e) {
try
{
Stands = int::Parse(uiStands->Text);
}
catch (Exception ^ex)
{
Stands = -1;
}

ChildCamPos = ChildCamPos0;
}
private: System::Void uiFov_TextChanged(System::Object^  sender, System::EventArgs^  e) {
try
{
FovDeg = R::Parse(uiFov->Text);
}
catch (Exception ^ex)
{
}
}
private: System::Void uiTimeZoom_TextChanged(System::Object^  sender, System::EventArgs^  e) {
try
{
TimeZoom = R::Parse(uiTimeZoom->Text);
}
catch (Exception ^ex)
{
}
}
private: Nullable<Point> oldMousePos;
private: System::Void pictureBox1_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
oldMousePos = e->Location;
}
private: System::Void pictureBox1_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
if (oldMousePos.HasValue == false)
return;

int dx = e->X - oldMousePos.Value.X;
int dy = e->Y - oldMousePos.Value.Y;
oldMousePos = e->Location;
   
R φ = (dx / 1000.0) * Fov();
R θ = (- dy / 1000.0) * Fov();

ChildCamFront = R3(cos(φ) * ChildCamFront(0) - sin(φ) * ChildCamFront(2),
ChildCamFront(1),
sin(φ) * ChildCamFront(0) + cos(φ) * ChildCamFront(2));
ChildCamUp = R3(cos(φ) * ChildCamUp(0) - sin(φ) * ChildCamUp(2),
ChildCamUp(1),
sin(φ) * ChildCamUp(0) + cos(φ) * ChildCamUp(2));

// or via base-trans
DXMatrix homoMat;
homoMat.RotateAxis(ToDXVec(Cross(ChildCamUp, ChildCamFront)), θ);
ChildCamFront = FromDXVec<R31>(Vector3::TransformNormal(ToDXVec(ChildCamFront), homoMat));
ChildCamUp = FromDXVec<R31>(Vector3::TransformNormal(ToDXVec(ChildCamUp), homoMat));
}
private: System::Void pictureBox1_MouseUp(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
oldMousePos = Nullable<Point>();
}
private: System::Void pictureBox1_MouseCaptureChanged(System::Object^  sender, System::EventArgs^  e) {
oldMousePos = Nullable<Point>();
}
この記事は 2019年8月28日 水 22:55 に作者によって編集されました
1   vbimkmmqe      2020年8月31日 月 20:49
万有引力シミュレーション(太陽系・3D) - アルファ・ラボ|学術掲示板群
vbimkmmqe http://www.g1er5wxq4b677m79a25vy4pzp9ok8798s.org/
[url=http://www.g1er5wxq4b677m79a25vy4pzp9ok8798s.org/]uvbimkmmqe[/url]
<a href="http://www.g1er5wxq4b677m79a25vy4pzp9ok8798s.org/">avbimkmmqe</a>
2   GScraper      2020年9月8日 火 21:28
3   GScraper      2020年9月10日 木 20:06
4   Featured      2020年9月12日 土 0:07
5   Chassis      2020年9月12日 土 3:45
6   Products      2020年9月12日 土 20:33
7   JACKET      2020年9月14日 月 14:25
8   Ferrule      2020年9月14日 月 22:25
9   Toesox      2020年9月17日 木 4:35
<a href="https://www.plasticspray.com/100ml-abs-bath-salt-container/">100ml ABS bath salt container</a>
<a href="http://www.hitechstore.fr/petit-portemonnaie-unisexe-en-toile-avec-fermeture-233clair-et-poign233e-motif-cerf-de-no235l-p-4898.html">Petit porte-monnaie unisexe en toile avec fermeture éclair et poignée Motif cerf de No?l</a>
<a href="http://www.acatostore.de/baqi-handgen228hten-kuhlederm228nner-loafers-bequemer-slipon-driving-freizeitschuh-weicher-unterer-big-size-3847schwarz38-p-21672.html">BAQI Handgen?hten Kuh-Leder-M?nner Loafers bequemer Slip-On Driving Freizeitschuh weicher unterer Big Size 38-47.Schwarz.38</a>
<a href="http://www.uastore.es/mochila-vintage-y-retro-de-lona-37-cm-135-litros-terracota-colorado-p-17579.html">Mochila Vintage y Retro de Lona. 37 cm. 13.5 litros. Terracota Colorado</a>
<a href="http://www.sonicstore.it/toesox-p-23280.html">Toesox</a>
ヒント: 今海豚がピザハットに出資しています
名前      編集用パスワード(省略可)    パスワードの記憶
数式 αβγ IPA http:// 画像 B I U
(添付ファイルは http://up.x0000.net/ にアップロードしてください)