約 2,856,133 件
https://w.atwiki.jp/sampleisbest/pages/102.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Win32 プロジェクト プロジェクト名 filecopy アプリケーションの種類 Windows アプリケーション 追加のオプション 空のプロジェクト 文字セット Unicode 参考 複数ファイルのコピー (SHFileOperation) filecopy.c #include Windows.h #include "resource.h" // 関数プロトタイプ宣言 INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); void OnInitDialog(HWND hDlg); void OnButtonCopy(HWND hDlg); //============================================================================== int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), NULL, DialogProc); return 0; } //------------------------------------------------------------------------------ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { INT_PTR iRetVal = TRUE;// メッセージを処理した switch (uMsg) { case WM_COMMAND switch (LOWORD(wParam)) { case IDC_BUTTON_COPY OnButtonCopy(hDlg); break; case IDC_BUTTON_HELLO MessageBox(hDlg, TEXT("world"), TEXT("hello"), MB_OK); break; } break; case WM_INITDIALOG OnInitDialog(hDlg); iRetVal = TRUE;// SetFocusでフォーカスを設定した場合はFALSE break; case WM_CLOSE EndDialog(hDlg, IDOK); break; default iRetVal = FALSE;// メッセージを処理しなかった } return iRetVal; } //------------------------------------------------------------------------------ void OnInitDialog(HWND hDlg) { RECT rcDesktop; RECT rcDialog; GetWindowRect(GetDesktopWindow(), rcDesktop); GetWindowRect(hDlg, rcDialog); SetWindowPos(hDlg, HWND_TOP, (rcDesktop.right - (rcDialog.right - rcDialog.left)) / 2, (rcDesktop.bottom - (rcDialog.bottom - rcDialog.top)) / 2, 0, 0, SWP_NOSIZE); } //------------------------------------------------------------------------------ void OnButtonCopy(HWND hDlg) { SHFILEOPSTRUCT fop; int i; fop.hwnd= hDlg; fop.wFunc= FO_COPY; fop.pFrom= TEXT("C \\tmp\\hoge.mp4\0"); fop.pTo= TEXT("Z \\\0"); fop.fFlags= FOF_ALLOWUNDO; i = SHFileOperation( fop); } resource.h #define IDD_MAIN_DIALOG100 #define IDC_BUTTON_COPY1000 #define IDC_BUTTON_HELLO1001 filecopy.rc // リソース スクリプト #include windows.h #include "resource.h" IDD_MAIN_DIALOG DIALOGEX 0, 0, 320, 240 STYLE WS_POPUPWINDOW | WS_MINIMIZEBOX EXSTYLE WS_EX_APPWINDOW CAPTION "filecopy" FONT 9, "MS Pゴシック" BEGIN PUSHBUTTON"copy",IDC_BUTTON_COPY,12,12,48,16 PUSHBUTTON"hello",IDC_BUTTON_HELLO,12,40,48,16 END
https://w.atwiki.jp/sampleisbest/pages/208.html
開発環境 Microsoft Visual C# 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Windows Game (4.0) プロジェクト名 XnaBlock Game1.cs using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaBlock { class Game1 Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; Effect effect; Texture2D texture; // fps DateTime prevTime; int draw = 0; int fps = 0; const int blockMax = 20000; int blockNum = 0; VertexBuffer instanceBuffer; VertexBuffer geometryBuffer; IndexBuffer indexBuffer; VertexDeclaration instanceVertexDeclaration; VertexBufferBinding[] bindings; Matrix projection; // カメラ Vector3 camPos = new Vector3(50.5f, 1.5f, 50.5f); int camLat = 0; int camLong = 225; struct InstanceInfo { public Matrix World; public Vector2 AtlasCoordinate; } public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void Initialize() { sprite = new SpriteBatch(GraphicsDevice); prevTime = DateTime.Now; base.Initialize(); } protected override void LoadContent() { // ソリューション エクスプローラーの(Content)に追加しておく font = Content.Load SpriteFont ("SpriteFont1"); // 新しい項目:Sprite Font effect = Content.Load Effect ("HardwareInstancing"); // 新しい項目:Effect File (.fx) texture = Content.Load Texture2D ("Texture4"); // 既存の項目:Texture4.png GenerateGeometryBuffers(0.5f); GenerateInstanceVertexDeclaration(); GenerateInstanceInformation(); bindings = new VertexBufferBinding[2]; bindings[0] = new VertexBufferBinding(geometryBuffer, 0); bindings[1] = new VertexBufferBinding(instanceBuffer, 0, 1); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), GraphicsDevice.Viewport.AspectRatio, 0.1f, 2000); effect.CurrentTechnique = effect.Techniques["Instancing"]; effect.Parameters["cubeTexture"].SetValue(texture); base.LoadContent(); } void GenerateGeometryBuffers(float size) { VertexPositionTexture[] vertices = new VertexPositionTexture[24]; for (int n = 0; n 4; n++) { float u = size * ((n 1) * 2 - 1); float v = size * ((n 2) - 1); vertices[0 + n].Position = new Vector3(u, size, v); vertices[4 + n].Position = new Vector3(u, -size, -v); vertices[8 + n].Position = new Vector3(-size, -v, u); vertices[12 + n].Position = new Vector3(u, -v, size); vertices[16 + n].Position = new Vector3(size, -v, -u); vertices[20 + n].Position = new Vector3(-u, -v, -size); } for (int n = 0; n 4; n++) { int u = n 1; int v = (n 1) 1; vertices[0 + n].TextureCoordinate = new Vector2(0 + u, 0 + v); vertices[4 + n].TextureCoordinate = new Vector2(1 + u, 0 + v); vertices[8 + n].TextureCoordinate = new Vector2(2 + u, 0 + v); vertices[12 + n].TextureCoordinate = new Vector2(0 + u, 1 + v); vertices[16 + n].TextureCoordinate = new Vector2(1 + u, 1 + v); vertices[20 + n].TextureCoordinate = new Vector2(2 + u, 1 + v); } geometryBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture), 24, BufferUsage.WriteOnly); geometryBuffer.SetData(vertices); int[] indices = new int[36]; for (int n = 0; n 6; n++) { int n6 = n * 6; int n4 = n * 4; indices[n6 + 0] = n4 + 0; indices[n6 + 1] = n4 + 1; indices[n6 + 2] = n4 + 2; indices[n6 + 3] = n4 + 1; indices[n6 + 4] = n4 + 3; indices[n6 + 5] = n4 + 2; } indexBuffer = new IndexBuffer(GraphicsDevice, typeof(int), 36, BufferUsage.WriteOnly); indexBuffer.SetData(indices); } void GenerateInstanceVertexDeclaration() { VertexElement[] elements = new VertexElement[5]; for (int n = 0; n 4; n++) { elements[n] = new VertexElement(sizeof(float) * 4 * n, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, n + 1); } elements[4] = new VertexElement(sizeof(float) * 16, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 5); instanceVertexDeclaration = new VertexDeclaration(elements); } void GenerateInstanceInformation() { InstanceInfo[] instances = new InstanceInfo[blockMax]; // 地面 int n = 0; for (int z = 0; z 100; z++) { for (int x = 0; x 100; x++) { instances[n].World = Matrix.CreateTranslation( new Vector3(x + 0.5f, 0.5f, z + 0.5f)); instances[n].AtlasCoordinate = new Vector2(0, 0); n++; } } Random rnd = new Random(); for (; n blockMax; n++) { instances[n].World = Matrix.CreateFromYawPitchRoll( (float)rnd.NextDouble() * MathHelper.TwoPi, (float)rnd.NextDouble() * MathHelper.TwoPi, (float)rnd.NextDouble() * MathHelper.TwoPi) * Matrix.CreateTranslation( new Vector3(rnd.Next(100), rnd.Next(100), rnd.Next(100))); instances[n].AtlasCoordinate = new Vector2(0, 0); } blockNum = n; instanceBuffer = new VertexBuffer(GraphicsDevice, instanceVertexDeclaration, blockMax, BufferUsage.WriteOnly); instanceBuffer.SetData(instances); } protected override void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); if (state[Keys.Escape] == KeyState.Down) Exit(); if (state[Keys.Escape] == KeyState.Down) Exit(); if (state[Keys.W] == KeyState.Down) Move(0, 0); if (state[Keys.S] == KeyState.Down) Move(180, 0); if (state[Keys.A] == KeyState.Down) Move(0, -90); if (state[Keys.D] == KeyState.Down) Move(0, 90); if (state[Keys.Up] == KeyState.Down) camLat++; if (state[Keys.Down] == KeyState.Down) camLat--; if (state[Keys.Left] == KeyState.Down) camLong--; if (state[Keys.Right] == KeyState.Down) camLong++; if (state[Keys.PageUp] == KeyState.Down) Move(90, 0); if (state[Keys.PageDown] == KeyState.Down) Move(-90, 0); base.Update(gameTime); } void Move(int degLat, int degLong) { float rad = MathHelper.ToRadians(camLat + degLat); if (degLong == 0) { camPos.Y += (float)Math.Sin(rad) * 0.2f; } float r = (float)Math.Cos(rad) * 0.2f; rad = MathHelper.ToRadians(camLong + degLong); camPos.X += (float)Math.Cos(rad) * r; camPos.Z += (float)Math.Sin(rad) * r; } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.DepthStencilState = DepthStencilState.Default; float rad = MathHelper.ToRadians(camLat); float y = (float)Math.Sin(rad) + camPos.Y; float r = (float)Math.Cos(rad); rad = MathHelper.ToRadians(camLong); float x = camPos.X + (float)Math.Cos(rad) * r; float z = camPos.Z + (float)Math.Sin(rad) * r; Matrix view = Matrix.CreateLookAt(camPos, new Vector3(x, y, z), Vector3.Up); GraphicsDevice.Indices = indexBuffer; effect.Parameters["WVP"].SetValue(view * projection); effect.CurrentTechnique.Passes[0].Apply(); GraphicsDevice.SetVertexBuffers(bindings); GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, 24, 0, 12, blockNum); // フレームレート draw++; DateTime now = DateTime.Now; TimeSpan t = now - prevTime; if (t.TotalMilliseconds = 1000) { fps = draw; draw = 0; prevTime = now; } sprite.Begin(); string text = "fps=" + fps + " lat=" + camLat + " long=" + camLong + " block=" + blockNum; sprite.DrawString(font, text, new Vector2(0, 0), Color.White); text = string.Format("x={0 f1} y={1 f1} z={2 f1}", camPos.X, camPos.Y, camPos.Z); sprite.DrawString(font, text, new Vector2(0, 20), Color.White); sprite.End(); base.Draw(gameTime); } } } HardwareInstancing.fx /* Effect File プロジェクトのプロパティ [XNA Game Studio]タブ Use HiDef to access the complete API */ float4x4 WVP; texture cubeTexture; sampler TextureSampler = sampler_state { texture = cubeTexture ; mipfilter = LINEAR; minfilter = LINEAR; magfilter = LINEAR; }; struct InstancingVSinput { float4 Position POSITION0; float2 TexCoord TEXCOORD0; }; struct InstancingVSoutput { float4 Position POSITION0; float2 TexCoord TEXCOORD0; }; InstancingVSoutput InstancingVS( InstancingVSinput input, float4x4 instanceTransform TEXCOORD1, float2 atlasCoord TEXCOORD5) { InstancingVSoutput output; float4 pos = input.Position; pos = mul(pos, transpose(instanceTransform)); pos = mul(pos, WVP); output.Position = pos; output.TexCoord = float2( atlasCoord.x + (input.TexCoord.x / 4.0f), atlasCoord.y + (input.TexCoord.y / 4.0f)); return output; } float4 InstancingPS(InstancingVSoutput input) COLOR0 { return tex2D(TextureSampler, input.TexCoord); } technique Instancing { pass Pass0 { VertexShader = compile vs_3_0 InstancingVS(); PixelShader = compile ps_3_0 InstancingPS(); } }
https://w.atwiki.jp/sampleisbest/pages/547.html
vsync2.asm comment * MASM32 SDK ml /c /AT /Fl vsync2.asm link16 /t vsync2; * .modeltiny TABLEequ0028h; VSYNC VRAMSEGequ0a000h CLSequ1ah ESCAPEequ1bh .code org0100h mainproc movah, 02h movdl, CLS int21h callsetvect out64h, al; VSYNCリセット @@loop calldisp movah, 0bh; キーボードのステータスチェック int21h cmpal, 0 je@@loop movah, 07h; コンソールからの直接入力 int21h cmpal, ESCAPE jne@@loop callresvect movax, 4c00h int21h mainendp myint0aprocfar sti inccs count out64h, al; VSYNCリセット jmpcs [vect] ;iret myint0aendp setvectproc cli movax, 0000h moves, ax movsi, TABLE movax, es [si] movvect_off, ax movax, es [si+2] movvect_seg, ax movax, offset myint0a moves [si], ax movax, cs; = seg myint0a moves [si+2], ax inal, 02h andal, 0fbh; VSYNC割り込みマスク on out02h, al jmp$+2 sti ret setvectendp resvectproc cli inal, 02h oral, 04h; VSYNC割り込みマスク off out02h, al movax, 0000h moves, ax movsi, TABLE movax, vect_off moves [si], ax movax, vect_seg moves [si+2], ax jmp$+2 sti ret resvectendp dispproc movah, 00h; 日付・時刻の読み出し pushcs popes movbx, offset clock int1ch; カレンダ時計のBIOS moval, clock[5] cmpal, sec je@@skip movsec, al movax, count movdx, ax subax, fps movfps, dx movdi, offset buf calltodec5 @@skip movax, count movdi, offset buf + 6 calltodec5 movax, VRAMSEG moves, ax movsi, offset buf movdi, 0 cld movah, 0 movcx, 11 @@loop lodsb stosw loop@@loop ret dispendp ; ax=数値 di=バッファ todec5proc adddi, 5 movbx, 10 movcx, 5 @@loop movdx, 0 divbx adddl, 0 decdi mov[di], dl loop@@loop ret todec5endp vectlabeldword vect_offdw? vect_segdw? secdb-1 fpsdw0 countdw0 clockdb6 dup (?) bufdb xxxxx xxxxx endmain
https://w.atwiki.jp/sampleisbest/pages/176.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 空の CLR プロジェクト プロジェクト名 ClrD3D 参考 迷路を表示する ClrD3D_25.cpp /* #25 迷路 プロジェクトへの参照の追加(参照タブ) C \WINDOWS\Microsoft.NET\DirectX for Managed Code\1.0.2902.0 Microsoft.DirectX.dll Microsoft.DirectX.Direct3D.dll Microsoft.DirectX.Direct3DX.dll */ #pragma comment(linker, "/subsystem windows /entry main") // アセンブリ #using System.dll #using System.Drawing.dll #using System.Windows.Forms.dll // 名前空間 using namespace System; using namespace System Drawing; using namespace System Threading; using namespace System Windows Forms; using namespace Microsoft DirectX; using namespace Microsoft DirectX Direct3D; #define POST_NUM 4// 柱の数 #define MAZE_SIZE (POST_NUM * 2 + 3)// 迷路の大きさ ref class MainForm Form { private Device^ dev; PresentParameters^ pp; Mesh^ mesh; array int, 2 ^ nBlock; Vector3 vPos;// 位置 int nCamDir;// 向き Direct3D Font^ font; int nSec; int nFps; int nFrame; public MainForm() { MinimumSize = Drawing Size(160, 120); MaximizeBox = false; ClientSize = Drawing Size(640, 480); Text = "ClrD3D"; KeyDown += gcnew KeyEventHandler(this, MainForm OnKeyDown); } bool DXInitialize() { try { pp = gcnew PresentParameters; pp- Windowed = true; pp- SwapEffect = SwapEffect Discard; pp- AutoDepthStencilFormat = DepthFormat D16; pp- EnableAutoDepthStencil = true; dev = gcnew Device(0, DeviceType Hardware, this, CreateFlags HardwareVertexProcessing, pp); CreateMesh(); CreateFont(); MakeMaze(); vPos = Vector3(1.0f, -0.2f, 0.0f); nCamDir = 0; return true; } catch (Exception^) { return false; } } void Render() { if (dev == nullptr) return; if (WindowState == FormWindowState Minimized) return; nFrame++; if (nSec != DateTime Now.Second) { nSec = DateTime Now.Second; nFps = nFrame; nFrame = 0; } dev- RenderState- ZBufferEnable = true; dev- RenderState- ZBufferWriteEnable = true; // カメラの設定 float fDir = nCamDir * (float)Math PI / 180; float fTargetX = (float)Math Sin(fDir); float fTargetZ = (float)Math Cos(fDir); dev- Transform- View = Matrix LookAtLH( vPos, Vector3(vPos.X + fTargetX * 10.0f, 0.0f, vPos.Z + fTargetZ * 10.0f), Vector3(0.0f, 1.0f, 0.0f)); dev- Transform- Projection = Matrix PerspectiveFovLH((float)Math PI / 4, (float)ClientSize.Width / (float)ClientSize.Height, 0.1f, 10.0f); // ライトの設定 dev- Lights[0]- Direction = Vector3 Normalize(Vector3(-1, -2, 3)); dev- Lights[0]- Type = LightType Directional; dev- Lights[0]- Diffuse = Color FromArgb(0xff,0xff,0xff); dev- Lights[0]- Ambient = Color FromArgb(0x28,0x28,0x28); dev- Lights[0]- Enabled = true; dev- Lights[0]- Update(); dev- Clear(ClearFlags Target | ClearFlags ZBuffer, 0x7f7fff, 1.0f, 0); dev- BeginScene(); // メッシュ描画 ColorValue color(0.5f, 1.0f, 0.5f); for (int nRow = 0; nRow MAZE_SIZE; nRow++) { for (int nCol = 0; nCol MAZE_SIZE; nCol++) { switch (nBlock[nRow, nCol]) { case 1 DrawMesh(color, nRow, nCol, 0); break; case 2 DrawMesh(ColorValue(0.5f, 0.5f, 1.0f), nRow, nCol, -1); break; case 3 DrawMesh(ColorValue(1.0f, 0.5f, 0.5f), nRow, nCol, -1); break; } } } font- DrawText(nullptr, "fps=" + nFps, 0, 0, Color White); dev- EndScene(); try { dev- Present(); } catch (DeviceLostException^) { ResetDevice(); } } private void CreateMesh() { mesh = Mesh Box(dev, 1, 1, 1); } void DrawMesh(ColorValue color, int nRow, int nCol, int nAlt) { Material mat; mat.AmbientColor = color; mat.DiffuseColor = color; dev- Material = mat; Vector3 v((float)nRow, (float)nAlt, (float)nCol); dev- Transform- World = Matrix Translation(v); mesh- DrawSubset(0); } void CreateFont() { FontDescription fd; fd.Height = 20; fd.FaceName = "MS ゴシック"; font = gcnew Direct3D Font(dev, fd); } void ResetDevice() { int hResult; if (!dev- CheckCooperativeLevel(hResult)) { switch (hResult) { case ResultCode DeviceLost Thread Sleep(10); break; case ResultCode DeviceNotReset dev- Reset(pp); break; } } } void OnKeyDown(Object^ sender, KeyEventArgs^ e) { switch (e- KeyCode) { case Keys W Walk(0); break; case Keys S Walk(180); break; case Keys A Walk(-90); break; case Keys D Walk(90); break; case Keys Left nCamDir -= 5; break; case Keys Right nCamDir += 5; break; case Keys Up vPos.Y += 0.1f; break; case Keys Down vPos.Y -= 0.1f; break; case Keys Escape Close(); break; } } void Walk(int nDir) { float fDir = (nCamDir + nDir) * (float)Math PI / 180; float fX = (float)Math Sin(fDir) * 0.2f; float fZ = (float)Math Cos(fDir) * 0.2f; vPos.X += fX; vPos.Z += fZ; } // 迷路を作る(棒倒し法) void MakeMaze() { nBlock = gcnew array int, 2 (MAZE_SIZE, MAZE_SIZE); // 全体をクリア for (int nRow = 0; nRow MAZE_SIZE; nRow++) { for (int nCol = 0; nCol MAZE_SIZE; nCol++) { nBlock[nRow, nCol] = 0; } } // 外枠をセット for (int n = 0; n MAZE_SIZE; n++) { nBlock[0, n] = 1; nBlock[MAZE_SIZE - 1, n] = 1; nBlock[n, 0] = 1; nBlock[n, MAZE_SIZE - 1] = 1; } // 柱をセット for (int nPostRow = 1; nPostRow = POST_NUM; nPostRow++) { for (int nPostCol = 1; nPostCol = POST_NUM; nPostCol++) { nBlock[nPostRow * 2, nPostCol * 2] = 1; } } // 迷路作成 array int ^ aCol = {0, 1, 0, -1}; array int ^ aRow = {-1, 0, 1, 0}; Random^ rnd = gcnew Random; for (int nPostRow = 1; nPostRow = POST_NUM; nPostRow++) { for (int nPostCol = 1; nPostCol = POST_NUM; nPostCol++) { int nRow, nCol; do { int nDir = rnd- Next((nPostRow == 1) ? 4 3); nRow = nPostRow * 2 + aRow[nDir]; nCol = nPostCol * 2 + aCol[nDir]; } while (nBlock[nRow, nCol]); nBlock[nRow, nCol] = 1; } } // 入口・出口 nBlock[1, 0] = 2; nBlock[MAZE_SIZE - 2, MAZE_SIZE - 1] = 3; } }; int main() { MainForm^ form = gcnew MainForm; if (!form- DXInitialize()) { MessageBox Show("Direct3Dの初期化に失敗しました。", "ClrD3D"); return 0; } form- Show(); while (form- Created) { form- Render(); Application DoEvents(); } return 0; }
https://w.atwiki.jp/sampleisbest/pages/591.html
開発環境 Microsoft Visual Studio Community 2019 実行環境 Microsoft Windows 10 Home (64bit) プロジェクト テンプレート C++ 空のプロジェクト プロジェクト名 dx11sample1 dx11sample1.cpp #pragma comment(lib, "d3d11") #pragma comment(lib, "d3dcompiler") #include Windows.h #include wrl.h #include d3d11.h #include d3dcompiler.h #include DirectXMath.h using namespace Microsoft WRL; using namespace DirectX; struct SimpleVertex { XMFLOAT3 Pos; XMFLOAT3 Color; }; struct ConstantBuffer { XMMATRIX mWorld; }; ComPtr ID3D11Device g_pDevice; ComPtr ID3D11DeviceContext g_pContext; ComPtr IDXGISwapChain g_pSwapChain; ComPtr ID3D11RenderTargetView g_pRenderTargetView; ComPtr ID3D11VertexShader g_pVertexShader; ComPtr ID3D11PixelShader g_pPixelShader; ComPtr ID3D11InputLayout g_pVertexLayout; ComPtr ID3D11Buffer g_pVertexBuffer; ComPtr ID3D11Buffer g_pConstantBuffer; float g_theta = 0; // 関数宣言 HWND InitWindow(HINSTANCE hInst); HRESULT InitDevice(HWND hWnd); void CleanupDevice(); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); void Render(); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) { HWND hWnd = InitWindow(hInstance); if (!hWnd) return -1; if (FAILED(InitDevice(hWnd))) { CleanupDevice(); return -1; } ShowWindow(hWnd, nCmdShow); MSG msg = { 0 }; while (msg.message != WM_QUIT) { if (PeekMessage( msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage( msg); DispatchMessage( msg); } else { Render(); } } CleanupDevice(); return msg.wParam; } HWND InitWindow(HINSTANCE hInst) { WNDCLASSEX wc = { sizeof WNDCLASSEX }; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInst; wc.hCursor = LoadCursor(nullptr, IDC_ARROW); wc.hbrBackground = HBRUSH(COLOR_WINDOW + 1); wc.lpszClassName = L"dx11sample1"; if (!RegisterClassEx( wc)) return nullptr; DWORD dwStyle = WS_OVERLAPPEDWINDOW; RECT rc = { 0, 0, 400, 400 }; AdjustWindowRect( rc, dwStyle, FALSE); HWND hWnd = CreateWindow( wc.lpszClassName, L"dx11sample1", dwStyle, CW_USEDEFAULT, 0, rc.right - rc.left, rc.bottom - rc.top, nullptr, nullptr, hInst, nullptr); return hWnd; } HRESULT CompileShaderFromFile( LPCWSTR szFileName, LPCSTR szEntryPoint, LPCSTR szShaderModel, ID3DBlob** ppBlobOut) { DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS; ComPtr ID3DBlob pErrorBlob; HRESULT hr = D3DCompileFromFile(szFileName, nullptr, nullptr, szEntryPoint, szShaderModel, dwShaderFlags, 0, ppBlobOut, pErrorBlob); if (FAILED(hr)) { if (pErrorBlob) { OutputDebugStringA((LPCSTR)pErrorBlob- GetBufferPointer()); } return hr; } return S_OK; } HRESULT InitDevice(HWND hWnd) { HRESULT hr; UINT width = 400; UINT height = 400; DXGI_SWAP_CHAIN_DESC sd = { 0 }; sd.BufferDesc.Width = width; sd.BufferDesc.Height = height; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;// 符号なし正規化整数 sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = hWnd; sd.Windowed = TRUE; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; D3D_FEATURE_LEVEL featureLevel; hr = D3D11CreateDeviceAndSwapChain( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, sd, g_pSwapChain, g_pDevice, featureLevel, g_pContext); // レンダーターゲットビュー ComPtr ID3D11Texture2D pBackBuffer; hr = g_pSwapChain- GetBuffer(0, IID_PPV_ARGS( pBackBuffer)); if (FAILED(hr)) return hr; hr = g_pDevice- CreateRenderTargetView(pBackBuffer.Get(), nullptr, g_pRenderTargetView); if (FAILED(hr)) return hr; g_pContext- OMSetRenderTargets(1, g_pRenderTargetView.GetAddressOf(), nullptr); // ビューポート D3D11_VIEWPORT vp = { 0 }; vp.Width = (FLOAT)width; vp.Height = (FLOAT)height; vp.MinDepth = 0; vp.MaxDepth = 1; g_pContext- RSSetViewports(1, vp); // 頂点シェーダ ComPtr ID3DBlob pVSBlob; hr = CompileShaderFromFile(L"dx11sample1.fx", "VS", "vs_5_0", pVSBlob); if (FAILED(hr)) { return hr; } hr = g_pDevice- CreateVertexShader( pVSBlob- GetBufferPointer(), pVSBlob- GetBufferSize(), nullptr, g_pVertexShader); if (FAILED(hr)) return hr; // ピクセルシェーダ ComPtr ID3DBlob pPSBlob; hr = CompileShaderFromFile(L"dx11sample1.fx", "PS", "ps_5_0", pPSBlob); if (FAILED(hr)) { return hr; } hr = g_pDevice- CreatePixelShader( pPSBlob- GetBufferPointer(), pPSBlob- GetBufferSize(), nullptr, g_pPixelShader); if (FAILED(hr)) return hr; // g_pContext- IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // 入力レイアウト D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; hr = g_pDevice- CreateInputLayout(layout, ARRAYSIZE(layout), pVSBlob- GetBufferPointer(), pVSBlob- GetBufferSize(), g_pVertexLayout); if (FAILED(hr)) return hr; g_pContext- IASetInputLayout(g_pVertexLayout.Get()); // 頂点バッファ SimpleVertex vertices[] = { { XMFLOAT3(0, 0, 1), XMFLOAT3(0, 0, 1) }, { XMFLOAT3(0, 1, 0), XMFLOAT3(0, 1, 0) }, { XMFLOAT3(1, 0, 0), XMFLOAT3(1, 0, 0) }, }; D3D11_BUFFER_DESC vb = { 0 }; vb.ByteWidth = sizeof vertices; vb.Usage = D3D11_USAGE_DEFAULT; vb.BindFlags = D3D11_BIND_VERTEX_BUFFER; D3D11_SUBRESOURCE_DATA InitData = { 0 }; InitData.pSysMem = vertices; hr = g_pDevice- CreateBuffer( vb, InitData, g_pVertexBuffer); if (FAILED(hr)) return hr; UINT stride = sizeof SimpleVertex; UINT offset = 0; g_pContext- IASetVertexBuffers(0, 1, g_pVertexBuffer.GetAddressOf(), stride, offset); // 定数バッファ D3D11_BUFFER_DESC cb = { 0 }; cb.ByteWidth = sizeof ConstantBuffer; cb.Usage = D3D11_USAGE_DEFAULT; cb.BindFlags = D3D11_BIND_CONSTANT_BUFFER; hr = g_pDevice- CreateBuffer( cb, nullptr, g_pConstantBuffer); if (FAILED(hr)) return hr; return S_OK; } void CleanupDevice() { if (g_pContext) { g_pContext- ClearState(); } } LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (uMsg) { case WM_PAINT hdc = BeginPaint(hWnd, ps); EndPaint(hWnd, ps); break; case WM_DESTROY PostQuitMessage(0); break; default return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } void Render() { XMMATRIX world = XMMatrixRotationZ(g_theta); // float ClearColor[4] = { 0, 0, 0, 1 }; g_pContext- ClearRenderTargetView(g_pRenderTargetView.Get(), ClearColor); ConstantBuffer cb; //cb.mWorld = XMMatrixTranspose(world); cb.mWorld = world; g_pContext- UpdateSubresource(g_pConstantBuffer.Get(), 0, nullptr, cb, 0, 0); g_pContext- VSSetShader(g_pVertexShader.Get(), nullptr, 0); g_pContext- VSSetConstantBuffers(0, 1, g_pConstantBuffer.GetAddressOf()); g_pContext- PSSetShader(g_pPixelShader.Get(), nullptr, 0); g_pContext- Draw(3, 0); g_pSwapChain- Present(1, 0); // g_theta += 0.01f; } dx11sample1.fx cbuffer ConstantBuffer register(b0) { matrix World; }; struct VS_INPUT { float4 Pos POSITION; float4 Color COLOR; }; struct PS_INPUT { float4 Pos SV_Position; float4 Color COLOR; }; // Vertex Shader PS_INPUT VS(VS_INPUT input) { PS_INPUT output = (PS_INPUT)0; output.Pos = mul(World, input.Pos); output.Color = input.Color; return output; } // Pixel Shader float4 PS(PS_INPUT input) SV_Target { return input.Color; }
https://w.atwiki.jp/sampleisbest/pages/271.html
開発環境 Microsoft Visual C++ 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Win32 コンソール アプリケーション プロジェクト名 wave アプリケーションの種類 コンソール アプリケーション 追加のオプション 空のプロジェクト wave.cpp // 音階判定 #define _USE_MATH_DEFINES #include stdio.h #include math.h typedef unsigned char BYTE; // note number #define A133 #define A469 #define A581 #define SAMPLING_RATE11025 #define DATA_NUM201 #define WAVE_LEN33.45// 波長 // 関数プロトタイプ宣言 double LeastSquares(double freq, double wavelen); // 音階 const char *scale[] = {"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}; // 外部変数 BYTE waveformData[DATA_NUM]; //============================================================================== int main() { for (int i = 0; i DATA_NUM; i++) { double t = fmod(i / WAVE_LEN, 1.0); //double y = t 0.5 ? t * 2 (t - 1) * 2; double y = sin(2 * M_PI * t); waveformData[i] = BYTE(128 + 64 * y); //printf("%d %u\n", i, waveformData[i]); } int noteNum = -1; double jMin = 1.0; for (int n = A1; n = A5; n++) { double freq = 440.0 * pow(pow(2.0, n - A4), 1.0 / 12); double wavelen = SAMPLING_RATE / freq; double j = LeastSquares(freq, wavelen); printf("#%d %-2s%d %.2fHz %.2f %.6f\n", n, scale[n % 12], n / 12 - 1, freq, wavelen, j); if (j jMin) { noteNum = n; jMin = j; } } printf("%.2f Note#%d\n", WAVE_LEN, noteNum); return 0; } // 最小二乗法 double LeastSquares(double freq, double wavelen) { double sum = 0; int wl = (int)ceil(wavelen); for (int i = 0; i wl; i++) { double t = i * freq / SAMPLING_RATE; double y = sin(2 * M_PI * t); double d = (waveformData[i] - 128.0) / 128 - y; sum += d * d; //printf("%d t=%.6f y=%.6f\n", i, t, y); } return sum / wavelen; }
https://w.atwiki.jp/sampleisbest/pages/412.html
開発環境 メモ帳 実行環境 Windows 7 Home Premium (32bit)
https://w.atwiki.jp/sampleisbest/pages/255.html
開発環境 Microsoft Visual C# 2010 Express (SP1) 実行環境 Microsoft Windows XP Home Edition (SP3) プロジェクトの種類 Windows Game (4.0) プロジェクト名 XnaTexture2D 参考 Planet Earth Texture Maps Game1.cs /* * XnaTexture2D5 正距方位図法+日照 * * プロジェクトのプロパティ * [XNA Game Studio]タブ * Use HiDef to access the complete API */ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace XnaTexture2D { class Game1 Game { GraphicsDeviceManager graphics; SpriteBatch sprite; SpriteFont font; VertexBuffer vertexBuffer; Effect effect; BasicEffect basicEffect; Texture2D texture; VertexPositionColor[] cross; KeyboardState kStateOld = new KeyboardState(); EffectParameter fxLat; EffectParameter fxLon; EffectParameter fxAxis; float lat = 35; // 緯度 float lon = 135; // 経度 // fps int fpsSec = -1; int fpsDraw = 0; int fpsCount = 0; const double solarYear = 365.24219; // 太陽年(day) 365d5h48m45s const double anomalisticYear = 365.259643; // 近点年(day) 365d6h13m53.1552s const double earthRotationPerSec = (2 * Math.PI) / 86400; // 地球が1秒間に回転する角度 const double e = 0.01671022; // 離心率(Orbital eccentricity) readonly double K = Math.Sqrt((1 + e) / (1 - e)); // ケプラー方程式の定数 const double epsilon = 1.0e-14; DateTime dt = DateTime.UtcNow; int tz = 1; readonly string[] tzName = { "UTC", "JST-9" }; int cursor = 0; readonly int[] cursorPos = { 0, 5, 8, 11, 14, 15, 17 }; readonly int[] cursorLen = { 4, 2, 2, 2, 1, 1, 3 }; int repeatFrame = 0; double MJD; // 修正ユリウス日 double MJD_date; double MJD_time; double T; // 2000/1/1 12 00(UT)からのユリウス世紀(36525日) double obliquity; // 黄道傾斜角 double eclipticLon; // 黄径 public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 960; graphics.PreferredBackBufferHeight = 720; Content.RootDirectory = "Content"; IsMouseVisible = true; } protected override void LoadContent() { sprite = new SpriteBatch(GraphicsDevice); font = Content.Load SpriteFont ("SpriteFont1"); texture = Content.Load Texture2D ("earthmap1k"); effect = Content.Load Effect ("Effect1"); effect.Parameters["EarthMap"].SetValue(texture); effect.Parameters["aspect"].SetValue(GraphicsDevice.Viewport.AspectRatio); effect.Parameters["revision"].SetValue( (float)Math.Sin((0.533 / 2 + (35 * 60 + 8) / 3600.0) * Math.PI / 180)); fxLat = effect.Parameters["centerLatRad"]; fxLon = effect.Parameters["centerLonRad"]; fxAxis = effect.Parameters["axis"]; fxLat.SetValue(MathHelper.ToRadians(lat)); fxLon.SetValue(MathHelper.ToRadians(lon)); SetAxis(); basicEffect = new BasicEffect(GraphicsDevice); // 地図 VertexPositionTexture[] vertices = new VertexPositionTexture[4]; vertices[0] = new VertexPositionTexture(new Vector3(-1, 1, 0), new Vector2(0, 0)); vertices[1] = new VertexPositionTexture(new Vector3(1, 1, 0), new Vector2(1, 0)); vertices[2] = new VertexPositionTexture(new Vector3(-1, -1, 0), new Vector2(0, 1)); vertices[3] = new VertexPositionTexture(new Vector3(1, -1, 0), new Vector2(1, 1)); vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture), 4, BufferUsage.WriteOnly); vertexBuffer.SetData(vertices); // 照準 cross = new VertexPositionColor[4]; cross[0] = new VertexPositionColor(new Vector3(-0.05f, 0, 0), Color.White); cross[1] = new VertexPositionColor(new Vector3(0.05f, 0, 0), Color.White); cross[2] = new VertexPositionColor(new Vector3(0, -0.1f, 0), Color.White); cross[3] = new VertexPositionColor(new Vector3(0, 0.1f, 0), Color.White); CalcParameter(); base.LoadContent(); } void CalcParameter() { // 修正ユリウス日 int y = dt.Year; int m = dt.Month; int d = dt.Day; if (m 3) { y--; m += 12; } MJD_date = (int)(365.25 * y) + (y / 400) - (y / 100) + (int)(30.59 * (m - 2)) + d - 678912; MJD_time = (dt.Hour * 60 + dt.Minute) / 1440.0; MJD = MJD_date + MJD_time; // 黄道傾斜角 T = (MJD - 51544.5) / 36525; obliquity = (84381.406 - 46.836769 * T - 0.00059 * T * T + 0.001813 * T * T * T) / 3600; // 平均近点角(概算)近日点から次の近日点までの角度 double Ma = ModAngle((2 * Math.PI) * ((MJD / anomalisticYear - 0.1242853) % 1.0)); double E; double Ta; // 真近点角 KeplersEquation(Ma, out E, out Ta); // 春分点(vernal equinox)の真近点角 double MJDv = ((int)(MJD / solarYear - 0.3399541) + 0.3399541) * solarYear; double Mv = ModAngle((2 * Math.PI) * ((MJDv / anomalisticYear - 0.1242853) % 1.0)); double Tv; KeplersEquation(Mv, out E, out Tv); // 黄径(概算)春分点から次の春分点までの角度 eclipticLon = ModAngle(Ta - Tv); // 楕円効果と傾斜効果 int ellipseEffect = (int)Math.Round(Ma / earthRotationPerSec - Ta / earthRotationPerSec); int obliquityEffect = CalcObliquityEffect(obliquity, eclipticLon); int equationOfTime = ellipseEffect + obliquityEffect; // 均時差 float transit = (43200 - equationOfTime) / 86400.0f; // 南中時 // 天球上の太陽軌道の高さと半径 double solarDecl = Math.Sin(eclipticLon) * obliquity * Math.PI / 180; // 太陽の赤緯 double solarAlt = Math.Sin(solarDecl); double solarRad = Math.Cos(solarDecl); effect.Parameters["MJD_time"].SetValue((float)MJD_time); effect.Parameters["solarDecl"].SetValue((float)solarDecl); effect.Parameters["solarAlt"].SetValue((float)solarAlt); effect.Parameters["solarRad"].SetValue((float)solarRad); effect.Parameters["transit"].SetValue(transit); } double ModAngle(double angle) { while (angle = -Math.PI) angle += (2 * Math.PI); while (Math.PI angle) angle -= (2 * Math.PI); return angle; } // 傾斜効果の計算 int CalcObliquityEffect(double obliquity, double eclipticLon) { // 地球を基準とした太陽の公転 double x = Math.Cos(eclipticLon); double r = Math.Sin(eclipticLon); double y = Math.Cos(obliquity * Math.PI / 180) * r; double celestialEquator = Math.Atan2(y, x); // 天の赤道上の角度 return (int)Math.Round(eclipticLon / earthRotationPerSec - celestialEquator / earthRotationPerSec); } // 漸化式によりケプラー方程式を解く // M 平均近点角(mean anomaly) // E 離心近点角(Eccentric anomaly) // T 真近点角(true anomaly) void KeplersEquation(double M, out double E, out double T) { double E0 = M; // 初項 for (int i = 0; ; ) { i++; E = M + e * Math.Sin(E0); if ((E0 - epsilon E) (E E0 + epsilon)) { break; } if (10 = i) { Console.WriteLine(string.Format("計算打ち切り M={0} E={1}", M, E)); break; } E0 = E; } T = Math.Atan(K * Math.Tan(E / 2)) * 2; } protected override void Update(GameTime gameTime) { int delta = 0; KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.Escape)) Exit(); if (kState.IsKeyDown(Keys.Left) kStateOld.IsKeyUp(Keys.Left)) { cursor = (cursor + 6) % 7; } if (kState.IsKeyDown(Keys.Right) kStateOld.IsKeyUp(Keys.Right)) { cursor = (cursor + 1) % 7; } if (kState.IsKeyDown(Keys.Up)) delta = 1; if (kState.IsKeyDown(Keys.Down)) delta = -1; kStateOld = kState; if (delta == 0) { repeatFrame = 0; } else { if (--repeatFrame = 0) { switch (cursor) { case 0 dt = dt.AddYears(delta); break; case 1 dt = dt.AddMonths(delta); break; case 2 dt = dt.AddDays(delta); break; case 3 dt = dt.AddHours(delta); break; case 4 dt = dt.AddMinutes(delta * 10); break; case 5 dt = dt.AddMinutes(delta); break; case 6 tz = (tz + 1) % 2; break; } if (cursor != 6) { CalcParameter(); } repeatFrame = (repeatFrame == 0) ? 6 30; } } base.Update(gameTime); } void SetAxis() { float rad = MathHelper.ToRadians(lat); float y = (float)Math.Sin(rad); float r = (float)Math.Cos(rad); rad = MathHelper.ToRadians(lon); float z = (float)Math.Cos(rad) * r; float x = (float)Math.Sin(rad) * r; Vector3 v = new Vector3(x, y, z); v.Normalize(); fxAxis.SetValue(v); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; GraphicsDevice.SetVertexBuffer(vertexBuffer); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, cross, 0, 2); } // fps fpsDraw++; if (gameTime.TotalGameTime.Seconds != fpsSec) { fpsCount = fpsDraw; fpsDraw = 0; fpsSec = gameTime.TotalGameTime.Seconds; } sprite.Begin(); string text = new string( , cursorPos[cursor]) + new string( _ , cursorLen[cursor]); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); text = string.Format("{0} {1}", dt.AddHours(tz * 9).ToString("yyyy/MM/dd HH mm"), tzName[tz]); sprite.DrawString(font, text, new Vector2(0, 0), Color.White); text = string.Format("fps={0} lat={1 f1} lon={2 f1}", fpsCount, lat, lon); sprite.DrawString(font, text, new Vector2(0, 20), Color.White); sprite.End(); base.Draw(gameTime); } } } Effect1.fx // XnaTexture2D5 正距方位図法+日照 texture EarthMap; float centerLatRad; float centerLonRad; float aspect; float3 axis; float MJD_time; // 修正ユリウス日の時刻 float solarDecl; // 太陽の赤緯 float solarAlt; // 天球上の太陽軌道の高さ float solarRad; // 天球上の太陽軌道の半径 float transit; // 南中時 float revision; // 太陽の視角(0.533deg)と大気差(35m8s)による昼の長さの補正 sampler TextureSampler = sampler_state { texture = EarthMap ; mipfilter = linear; minfilter = linear; magfilter = linear; }; struct VertexShaderInput { float4 Position POSITION0; float2 TexCoord TEXCOORD0; }; struct VertexShaderOutput { float4 Position POSITION0; float2 TexCoord TEXCOORD0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; output.Position = input.Position; output.TexCoord = input.TexCoord; return output; } float4 MulQ(float4 q1, float4 q2) { float4 q; q.x = (q1.w * q2.x) + (q1.x * q2.w) + (q1.y * q2.z) - (q1.z * q2.y); q.y = (q1.w * q2.y) + (q1.y * q2.w) + (q1.z * q2.x) - (q1.x * q2.z); q.z = (q1.w * q2.z) + (q1.z * q2.w) + (q1.x * q2.y) - (q1.y * q2.x); q.w = (q1.w * q2.w) - (q1.x * q2.x) - (q1.y * q2.y) - (q1.z * q2.z); return q; } float4 PixelShaderFunction(VertexShaderOutput input) COLOR0 { float x = input.TexCoord.x * 2 - 1; // -1 - 1 float y = input.TexCoord.y * 2 - 1; // -1 - 1 x *= aspect; // 距離(=回転軸からの角度)0 - 1 float dist = sqrt(x * x + y * y); if (1 dist) { discard; } // 方位角(=回転する角度)-pi - pi float angleRad = atan2(x, -y); // 回転する座標 float4 p; float rad = centerLatRad + radians(dist * 180); p.y = sin(rad); float r = cos(rad); p.z = cos(centerLonRad) * r; p.x = sin(centerLonRad) * r; p.w = 0; // 回転 float4 rot; angleRad *= 0.5; rot.xyz = axis * sin(angleRad); rot.w = cos(angleRad); float4 conj; conj.xyz = -rot.xyz; conj.w = rot.w; float4 q = MulQ(MulQ(conj, p), rot); // 緯度、経度 float latRad = asin(q.y); float lonDeg = degrees(atan2(q.x, q.z)); // ローカル時刻 float localtime = MJD_time + lonDeg / 360; localtime = frac(localtime); // テクスチャサンプリング float2 t; t.x = (180 + lonDeg) / 360; t.y = (90 - degrees(latRad)) / 180; float4 output = tex2D(TextureSampler, t); // 天球上の太陽軌道と地平面の交点=日出・日没 float ra = sin(latRad) * revision; float rx = cos(latRad) * revision; float cosx = ((solarAlt + ra) * -tan(latRad) - rx) / solarRad; if (cosx = -1) // 白夜 { return output; } if (1 = cosx) // 極夜 { output.rgb *= 0.5; return output; } float halfDaytime = degrees(acos(cosx)) / 360; // 日出・日没時刻(南中時-半分の昼の長さ) float rising = transit - halfDaytime; float setting = transit + halfDaytime; if (localtime = rising || setting = localtime) { output.rgb *= 0.5; } return output; } technique Technique1 { pass Pass1 { VertexShader = compile vs_3_0 VertexShaderFunction(); PixelShader = compile ps_3_0 PixelShaderFunction(); } }
https://w.atwiki.jp/sampleisbest/pages/546.html
vsync.asm comment * MASM32 SDK ml /c /AT /Fl vsync.asm link16 /t vsync; * .modeltiny VRAMSEGequ0a000h CLSequ1ah .code .186 org0100h mainproc movah, 02h movdl, CLS int21h pushes movax, 350ah; ベクタ取得 int21h movold0a_off, bx movold0a_seg, es popes movdx, offset myint0a movax, 250ah; ベクタ設定 int21h inal, 02h andal, 0fbh; VSYNC割り込みマスク on out02h, al sti out64h, al; VSYNCリセット @@loop movah, 01h int21h cmpal, 1bh jne@@loop pushds ldsdx, old0a movax, 250ah; ベクタ復帰 int21h popds movax, 4c00h int21h mainendp myint0aprocfar cmpcs in0a, 0 jne@@exit inccs in0a pushds pushes pusha pushcs popds inccount movax, count movdi, offset buf calltodec5 movax, VRAMSEG moves, ax movsi, offset buf movdi, 0 cld movah, 0 movcx, 5 @@loop lodsb stosw loop@@loop popa popes popds deccs in0a @@exit out64h, al; VSYNCリセット jmpcs [old0a] myint0aendp ; ax=数値 di=バッファ todec5proc adddi, 5 movbx, 10 movcx, 5 @@loop movdx, 0 divbx adddl, 0 decdi mov[di], dl loop@@loop ret todec5endp old0alabeldword old0a_offdw? old0a_segdw? in0adw0 countdw0 bufdb5 dup (?) endmain
https://w.atwiki.jp/sampleisbest/pages/526.html
開発環境 Microsoft Visual Studio Community 2017 実行環境 Microsoft Windows 10 Home (64bit) プロジェクトの種類 Visual C++ / 空のプロジェクト 参考 サウンド デバイスの列挙 コンソール版(dsenum_c) dsenum_c.cpp // マルチバイト文字セット // https //msdn.microsoft.com/ja-jp/library/cc354468.aspx #pragma comment(lib, "dsound") #include dsound.h #include stdio.h BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { printf("[%s][%s]\n", lpszDesc, lpszDrvName); return TRUE; } int main() { HRESULT hr = DirectSoundEnumerate(DSEnumProc, NULL); return 0; } 出力 [プライマリ サウンド ドライバー][] [EX-LD2071T (Intel SST Audio Device (WDM))][{0.0.0.00000000}.{0226a988-680d-43c9-b4e4-f71db4992a9c}] [スピーカー (Intel SST Audio Device (WDM))][{0.0.0.00000000}.{1dbfc4da-902e-4808-b91b-5381f6f64943}] ウィンドウ版(dsenum_w) dsenum_w.cpp // Unicode文字セット // https //msdn.microsoft.com/ja-jp/library/cc354468.aspx #pragma comment(lib, "dsound") #include windowsx.h #include dsound.h #include "Resource.h" INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); void Init(HWND hDlg); BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext); //// int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINDLG), NULL, MainDlg); return 0; } INT_PTR CALLBACK MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND switch (LOWORD(wParam)) { case IDCANCEL EndDialog(hDlg, IDCANCEL); break; } break; case WM_INITDIALOG Init(hDlg); break; default return FALSE; } return TRUE; } void Init(HWND hDlg) { HWND hCombo1 = GetDlgItem(hDlg, IDC_COMBO1); DirectSoundEnumerate(DSEnumProc, hCombo1); } BOOL CALLBACK DSEnumProc(LPGUID lpGUID, LPCTSTR lpszDesc, LPCTSTR lpszDrvName, LPVOID lpContext) { HWND hCombo = (HWND)lpContext; ComboBox_AddString(hCombo, lpszDesc); return TRUE; } Resource.h #define IDD_MAINDLG100 #define IDC_STATIC-1 #define IDC_COMBO11000 dsenum_w.rs // resource script #include windows.h #include "resource.h" IDD_MAINDLG DIALOGEX 100, 100, 320, 200 STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "dsenum_w" FONT 9, "MS UI Gothic" BEGIN COMBOBOXIDC_COMBO1, 10, 10, 200, 100, CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP END