その癖というのが
まあ例えば、
if(i==n)
っていう文があるとするじゃないですか
それを
if(i=n)
って書いちゃうんですよ
==が比較演算子で
=が代入演算子なのにね
いい加減この癖直さないとなぁ
if(i==n)
if(i=n)
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"winmm.lib")
#include<TCHAR.h>
#include<d3dx9.h>
#include<math.h>
#include<strsafe.h>
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
#define WS_GAMEWINDOW (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU)
void Render();
void Cleanup();
void SetupLights();
void SetupMatrices();
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
LRESULT CALLBACK MsgProc( HWND, UINT, WPARAM, LPARAM );
HRESULT InitD3D( HWND );
HRESULT InitGeometry();
HRESULT SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride );
HRESULT DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount );
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The surface normal for the vertex
};
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wcex = {};
//①ウィンドウクラスの定義・登録
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_CLASSDC; //スタイル
wcex.lpfnWndProc = MsgProc; //メッセージ処理関数
wcex.cbClsExtra = 0L;
wcex.cbWndExtra = 0L;
wcex.hInstance = GetModuleHandle(NULL); //プログラムのハンドル
wcex.hIcon = NULL; //アイコン
wcex.hCursor = NULL; //カーソル
wcex.hbrBackground = NULL; //背景色
wcex.lpszMenuName = NULL; //メニュー
wcex.lpszClassName = _T("D3D Tutorial"); //クラス名
if( !RegisterClassEx( &wcex ) )
{
MessageBox(hWnd, _T("_TWinMain Error!"), _T("Failed to RegisterClassEx( &wcex )."), MB_OK|MB_ICONSTOP );
return 0;
}
//②ウィンドウの作成
if( !(hWnd = CreateWindow
(
_T("D3D Tutorial"), // 登録されているクラス名
_T("Test by aoisensi."), // ウィンドウ名
WS_GAMEWINDOW, // ウィンドウスタイル
CW_USEDEFAULT, // ウィンドウの横方向の位置
CW_USEDEFAULT, // ウィンドウの縦方向の位置
640, // ウィンドウの幅
480, // ウィンドウの高さ
NULL, // 親ウィンドウまたはオーナーウィンドウのハンドル
NULL, // メニューハンドルまたは子ウィンドウ ID
wcex.hInstance, // アプリケーションインスタンスのハンドル
NULL // ウィンドウ作成データ
) ) )
{
MessageBox(hWnd, _T("_TWinMain Error!"), _T("Failed to CreateWindow."), MB_OK|MB_ICONSTOP );
return 0;
}
//③ウィンドウを表示
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
if( SUCCEEDED( InitGeometry() ) )
{
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
ZeroMemory( &msg, sizeof(msg) );
//④メインループ
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
Render();
}
}
}
else
{
MessageBox(hWnd, _T("_tWinMain Error!"), _T("Failed to InitGeometry."), MB_OK|MB_ICONSTOP );
}
}
UnregisterClass( _T("D3D Tutorial"), wcex.hInstance );
return 0;
}
void Render()
{
if( NULL == g_pd3dDevice )
{
return;
}
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0x00, 0x00, 0xFF), 1.0f, 0 );
if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupLights();
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 ); //一つ目のトイレットペーパーの芯
D3DXMATRIXA16 matWorld, curWorld;
g_pd3dDevice->GetTransform( D3DTS_WORLD, &curWorld);
D3DXMatrixTranslation( &matWorld, -3,0,2 );
curWorld = curWorld * matWorld;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &curWorld );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 ); //二つ目のトイレットペーパーの芯
D3DXMatrixTranslation( &matWorld, 3,0,2 );
curWorld = curWorld * matWorld;
g_pd3dDevice->SetTransform( D3DTS_WORLD, &curWorld );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 ); //三つ目のトイレットペーパーの芯
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void Cleanup()
{
if( g_pd3dDevice != NULL)
{
g_pd3dDevice->Release();
}
if ( g_pD3D != NULL)
{
g_pD3D->Release();
}
}
void SetupLights()
{
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
g_pd3dDevice->SetMaterial( &mtrl );
D3DXVECTOR3 vecDir;
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
vecDir = D3DXVECTOR3(cosf(timeGetTime()/350.0f),
1.0f,
sinf(timeGetTime()/350.0f) );
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
light.Range = 1000.0f;
g_pd3dDevice->SetLight( 0, &light );
g_pd3dDevice->LightEnable( 0, true );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, true );
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
}
void SetupMatrices()
{
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixRotationX( &matWorld, timeGetTime()/500.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
D3DXVECTOR3 vEyePt( 0.0f, 3.0f, -5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam) );
}
}
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
MessageBox(hWnd, _T("InitD3D Error!"), _T("Null to Direct3DCreate9."), MB_OK|MB_ICONSTOP );
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) )
{
MessageBox(hWnd, _T("InitD3D Error!"), _T("Failed to CreateDevice."), MB_OK|MB_ICONSTOP );
return E_FAIL;
}
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, true );
return S_OK;
}
HRESULT InitGeometry()
{
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
CUSTOMVERTEX* pVertices;
if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
{
return E_FAIL;
}
for( DWORD i=0; i<50; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);
pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
}
g_pVB->Unlock();
return S_OK;
}
#include <windows.h>
#pragma comment(lib,"d3dx9.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"winmm.lib")
#include<TCHAR.h>
#include<d3dx9.h>
#include<math.h>
#include<strsafe.h>
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
void Render();
void Cleanup();
void SetupLights();
void SetupMatrices();
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
HRESULT InitD3D( HWND );
HRESULT InitGeometry();
HRESULT SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride );
HRESULT DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount );
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The surface normal for the vertex
};
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
//①ウィンドウクラスの定義・登録
wc.style = CS_HREDRAW | CS_VREDRAW; //スタイル
wc.lpfnWndProc = WndProc; //メッセージ処理関数
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst; //プログラムのハンドル
wc.hIcon = NULL; //アイコン
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //カーソル
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); //背景色
wc.lpszMenuName = NULL; //メニュー
wc.lpszClassName = _T("test"); //クラス名
if( !RegisterClass( &wc ) )
{
return 0;
}
//②ウィンドウの作成
hWnd = CreateWindow
(
_T("test"), // 登録されているクラス名
_T("Test by aoisensi."), // ウィンドウ名
WS_OVERLAPPEDWINDOW, // ウィンドウスタイル
CW_USEDEFAULT, // ウィンドウの横方向の位置
CW_USEDEFAULT, // ウィンドウの縦方向の位置
640, // ウィンドウの幅
480, // ウィンドウの高さ
NULL, // 親ウィンドウまたはオーナーウィンドウのハンドル
NULL, // メニューハンドルまたは子ウィンドウ ID
hInst, // アプリケーションインスタンスのハンドル
NULL // ウィンドウ作成データ
);
//③ウィンドウを表示
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
if( SUCCEEDED( InitGeometry() ) )
{
ShowWindow( hWnd, nShowCmd );
UpdateWindow( hWnd );
//④メインループ
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
Render();
}
}
UnregisterClass( _T("D3D Tutorial"), wc.hInstance );
return 0;
}
void Render()
{
if( NULL == g_pd3dDevice )
{
return;
}
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0x00, 0x00, 0xFF), 1.0f, 0 );
if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupLights();
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void Cleanup()
{
if( g_pd3dDevice != NULL)
{
g_pd3dDevice->Release();
}
if ( g_pD3D != NULL)
{
g_pD3D->Release();
}
}
void SetupLights()
{
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
g_pd3dDevice->SetMaterial( &mtrl );
D3DXVECTOR3 vecDir;
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
vecDir = D3DXVECTOR3(cosf(timeGetTime()/350.0f),1.0f,sinf(timeGetTime()/350.0f) );
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
light.Range = 1000.0f;
g_pd3dDevice->SetLight( 0, &light );
g_pd3dDevice->LightEnable( 0, true );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, true );
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
}
void SetupMatrices()
{
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixRotationX( &matWorld, timeGetTime()/500.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
D3DXVECTOR3 vEyePt( 0.0f, 3.0f, -5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam) );
}
}
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, true );
return S_OK;
}
HRESULT InitGeometry()
{
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
CUSTOMVERTEX* pVertices;
if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
{
return E_FAIL;
}
for( DWORD i=0; i<50; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);
pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
}
g_pVB->Unlock();
return S_OK;
}
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "wininet.lib")
#include<TCHAR.h>
#include<d3dx9.h>
#include<math.h>
#include<strsafe.h>
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
void Render();
void Cleanup();
void SetupLights();
void SetupMatrices();
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
HRESULT InitD3D( HWND );
HRESULT InitGeometry();
HRESULT SetStreamSource(UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride );
HRESULT DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount );
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The 3D position for the vertex
D3DXVECTOR3 normal; // The surface normal for the vertex
};
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
//①ウィンドウクラスの定義・登録
wc.style = CS_HREDRAW | CS_VREDRAW; //スタイル
wc.lpfnWndProc = WndProc; //メッセージ処理関数
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst; //プログラムのハンドル
wc.hIcon = NULL; //アイコン
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //カーソル
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); //背景色
wc.lpszMenuName = NULL; //メニュー
wc.lpszClassName = _T("test"); //クラス名
if( !RegisterClass( &wc ) )
{
return 0;
}
//②ウィンドウの作成
hWnd = CreateWindow
(
_T("test"), // 登録されているクラス名
_T("Test"), // ウィンドウ名
WS_OVERLAPPEDWINDOW, // ウィンドウスタイル
CW_USEDEFAULT, // ウィンドウの横方向の位置
CW_USEDEFAULT, // ウィンドウの縦方向の位置
640, // ウィンドウの幅
480, // ウィンドウの高さ
NULL, // 親ウィンドウまたはオーナーウィンドウのハンドル
NULL, // メニューハンドルまたは子ウィンドウ ID
hInst, // アプリケーションインスタンスのハンドル
NULL // ウィンドウ作成データ
);
//③ウィンドウを表示
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
if( SUCCEEDED( InitGeometry() ) )
{
ShowWindow( hWnd, nShowCmd );
UpdateWindow( hWnd );
//④メインループ
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else
{
Render();
}
}
UnregisterClass( _T("D3D Tutorial"), wc.hInstance );
return 0;
}
void Render()
{
if( NULL == g_pd3dDevice )
{
return;
}
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0x00, 0x00, 0xFF), 1.0f, 0 );
if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetupLights();
SetupMatrices();
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void Cleanup()
{
if( g_pd3dDevice != NULL)
{
g_pd3dDevice->Release();
}
if ( g_pD3D != NULL)
{
g_pD3D->Release();
}
}
void SetupLights()
{
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;
mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;
g_pd3dDevice->SetMaterial( &mtrl );
D3DXVECTOR3 vecDir;
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
vecDir = D3DXVECTOR3(cosf(timeGetTime()/350.0f),1.0f,sinf(timeGetTime()/350.0f) );
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );
light.Range = 1000.0f;
g_pd3dDevice->SetLight( 0, &light );
g_pd3dDevice->LightEnable( 0, true );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, true );
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
}
void SetupMatrices()
{
D3DXMATRIXA16 matWorld;
D3DXMatrixIdentity( &matWorld );
D3DXMatrixRotationX( &matWorld, timeGetTime()/500.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
D3DXVECTOR3 vEyePt( 0.0f, 3.0f, -5.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam) );
}
}
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, true );
return S_OK;
}
HRESULT InitGeometry()
{
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
CUSTOMVERTEX* pVertices;
if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
{
return E_FAIL;
}
for( DWORD i=0; i<50; i++ )
{
FLOAT theta = (2*D3DX_PI*i)/(50-1);
pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
pVertices[2*i+0].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
pVertices[2*i+1].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
}
g_pVB->Unlock();
return S_OK;
}
エラー内容わかる方いればよろしくお願いします
1>------ ビルド開始: プロジェクト: p1, 構成: Debug Win32 ------
1>main.obj : error LNK2019: 未解決の外部シンボル _D3DXVec3Normalize@8 が関数 "void __cdecl SetupLights(void)" (?SetupLights@@YAXXZ) で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル __imp__timeGetTime@0 が関数 "void __cdecl SetupLights(void)" (?SetupLights@@YAXXZ) で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル _D3DXMatrixPerspectiveFovLH@20 が関数 "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ) で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル _D3DXMatrixLookAtLH@16 が関数 "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ) で参照されました。
1>main.obj : error LNK2019: 未解決の外部シンボル _D3DXMatrixRotationX@8 が関数 "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ) で参照されました。
1>C:\Users\aoisensi\Documents\Visual Studio 2010\DirectX\p1\Debug\p1.exe : fatal error LNK1120: 外部参照 5 が未解決です。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========
#pragma comment(lib, "d3d9.lib")
#include<windows.h>
#include<TCHAR.h>
#include<d3d9.h>
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
void Render();
void Cleanup();
HRESULT InitD3D( HWND );
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
//①ウィンドウクラスの定義・登録
wc.style = CS_HREDRAW | CS_VREDRAW; //スタイル
wc.lpfnWndProc = WndProc; //メッセージ処理関数
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst; //プログラムのハンドル
wc.hIcon = NULL; //アイコン
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); //カーソル
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); //背景色
wc.lpszMenuName = NULL; //メニュー
wc.lpszClassName = _T("test"); //クラス名
if( !RegisterClass( &wc ) )
{
return 0;
}
//②ウィンドウの作成
hWnd = CreateWindow( _T("test"), _T("Test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
//③ウィンドウを表示
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
ShowWindow( hWnd, nShowCmd );
UpdateWindow( hWnd );
//④メインループ
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
UnregisterClass( _T("D3D Tutorial"), wc.hInstance );
return 0;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam) );
}
}
void Render()
{
if( NULL == g_pd3dDevice )
{
return;
}
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0x00, 0x00, 0xFF), 1.0f, 0 );
if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
g_pd3dDevice->EndScene();
}
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void Cleanup()
{
if( g_pd3dDevice != NULL)
{
g_pd3dDevice->Release();
}
if ( g_pD3D != NULL)
{
g_pD3D->Release();
}
}
HRESULT InitD3D( HWND hWnd )
{
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return E_FAIL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
return S_OK;
}
#include<windows.h>
#include<TCHAR.h>
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpszCmdLine, int nShowCmd)
{
HWND hWnd;
MSG msg;
WNDCLASS wc;
//①ウィンドウクラスの定義・登録
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = _T("test");
if( !RegisterClass( &wc ) )
{
return 0;
}
//②ウィンドウの作成
hWnd = CreateWindow( _T("test"), _T("Test"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL );
//③ウィンドウを表示
ShowWindow( hWnd, nShowCmd );
UpdateWindow( hWnd );
//④メインループ
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return 0;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return( DefWindowProc( hWnd, msg, wParam, lParam) );
}
}
おはよ!きんかんにっしょくでおこされた
— aoisensi@プロフ読めさん (@aoisensi) 5月 20, 2012
— aoisensi@プロフ読めさん (@aoisensi) 5月 20, 2012
金環日食×太陽ください。金「こういうのが良いんだろ…?」太陽「ちょ…やめ…!」金「久しぶりだからってそんなに興奮するなよ」太陽「そ、そんなにしたら暗くなっちゃ…!」金「そんなこと言って、本当は嬉しいんだろ?」太陽「ん、んなわけ…」金「俺だけしか見えないようにしてやるよ」 ください
— おおかまたよ、死んでしまうとはなさけないさん (@kmtor2) 5月 20, 2012
目覚ましテレビ。 RT @kani_hiko: @yoshida_justice グラス無しで見る方法教えてよ!
— 鷹の爪団 吉田さん (@yoshida_justice) 5月 20, 2012
バルス!
— ゆるにゃんさん (@YuruRokko) 5月 20, 2012
日食グラスAmazonで注文したら明日届くってさ
— kaomojiさん (@kaomoji_0908) 5月 20, 2012
金環日食見れてるやつは金柑食って爆発しろ
_人人人人人人_
>渾身のギャグ<
 ̄YYYYYY ̄
— ゆずりは@らいん@俺は今から滾るぜ!さん (@yurain69) 5月 20, 2012
— aoisensi@プロフ読めさん (@aoisensi) 5月 20, 2012
リングができた瞬間にそこからリングだけ取り出してこいしちゃんに渡したら無視されたけど、10分後に気付いて嬉しそうな顔してて幸せ
— 古明地だるきさん (@daruki514) 5月 20, 2012
#金環日食見てる人RT #とかいうと思ったか死ね #金環日食
— aoisensi@プロフ読めさん (@aoisensi) 5月 20, 2012
ジュンク堂書店 三宮店にタッチ! tou.ch/CQI1Ta
— aoisensi@プロフ読めさん (@aoisensi) 5月 20, 2012
| 指定子 | 対応する型 | 説明 | 使用例 |
|---|---|---|---|
| %c | char | 1文字を出力する | "%c" |
| %s | char * | 文字列を出力する | "%8s", "%-10s" |
| %d | int, short | 整数を10進で出力する | "%-2d","%03d" |
| %u | unsigned int, unsigned short | 符号なし整数を10進で出力する | "%2u","%02u" |
| %o | int, short, unsigned int, unsigned short | 整数を8進で出力する | "%06o","%03o" |
| %x | int, short, unsigned int, unsigned short | 整数を16進で出力する | "%04x" |
| %f | float | 実数を出力する | "%5.2f" |
| %e | float | 実数を指数表示で出力する | "%5.3e" |
| %g | float | 実数を最適な形式で出力する | "%g" |
| %ld | long | 倍精度整数を10進で出力する | "%-10ld" |
| %lu | unsigned long | 符号なし倍精度整数を10進で出力する | "%10lu" |
| %lo | long, unsigned long | 倍精度整数を8進で出力する | "%12lo" |
| %lx | long, unsigned long | 倍精度整数を16進で出力する | "%08lx" |
| %lf | double | 倍精度実数を出力する | "%8.3lf" |
double a = 68920.5555555;
printf ("%4.2lf",a);
を実行すると
| データ型 | サイズ | 意味 | 範囲 |
| bool | 1Byte | 論理型 | true(0以外) / false(0) |
| char | 1Byte | 文字型 | -128 ~ 127 |
| unsigned char | 1Byte | 符号なし文字型 | 0 ~ 255 |
| wchar_t | 2Byte | ワイド文字型 | - |
| short (int) | 2Byte | 短長整数型 | -32768 ~ 32767 |
| unsigned short (int) | 2Byte | 符号なし短長整数型 | 0 ~ 65535 |
| int | 4Byte | 整数型 | -2147486948 ~ 2147483647 |
| unsigned (int) | 4Byte | 符号なし整数型 | 0 ~ 4294967295 |
| long (int) | 4Byte | 長整数型 | -2147486948 ~ 2147483647 |
| unsigned long (int) | 4Byte | 符号なし長整数型 | 0 ~ 4294967295 |
| float | 4Byte | 単精度浮動小数点型 | -3.4E+38 ~ 3.4E+38 |
| double | 8Byte | 倍精度実数 | -1.7E+308 ~ 1.7E+308 |
| long double | 8Byte | 拡張精度浮動小数点型 | -1.7E+308 ~ 1.7E+308 |
| __int8 | 1Byte | 拡張整数型 | -128 ~ 127 |
| __int16 | 2Byte | 拡張整数型 | -32768 ~ 32767 |
| __int32 | 4Byte | 拡張整数型 | -2147483648 ~ 2147483647 |
| __int64 | 8Byte | 拡張整数型 | -9223372036854775808 ~ 9223372036854775807 |
| void | 0Byte | 空のデータ型 | - |
char name[255];
printf("%s\n",name);
のように、1配列に半角一文字が入るようにする#include<iostream>
using namespace std;
int main()
{
for(int i=1;i<=9;++i)
{
for(int j=1;j<=9;++j)
{
printf("%dx%d=%d\n" , i , j , i*j);
}
}
return 0;
}
#include<iostream>
#define element 10
using namespace std;
int height[element];
int number;
int main()
{
for(int i=0;i<element;++i)
{
cin >> height[i];
}
for(int i=0;i<element;++i)
{
for(int j=i;j<element;++j)
{
if(height[i]<height[j])
{
number = height[i];
height[i] = height[j];
height[j] = number;
}
}
}
printf("%d\n%d\n%d\n",height[0],height[1],height[2]);
return 0;
}
#include<iostream>
int a, b, n, m;
int main()
{
while(std::cin>>a>>b)
{
n = a + b;
m = 1;
while(n>=10)
{
n=n/10;
++m;
}
printf ("%d\n",m);
}
return 0;
}
#include<iostream>
unsigned short a, b, c;
int m;
bool flag;
int main()
{
std::cin >> m;
for(int i = 0;i < m;++i)
{
std::cin >> a >> b >> c;
if (a==0||b==0||c==0)
{
continue;
}
flag = false;
if((a*a)+(b*b)==(c*c))
{
flag = true;
}
else if((a*a)+(c*c)==(b*b))
{
flag = true;
}
else if((b*b)+(c*c)==(a*a))
{
flag = true;
}
if(flag==false)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
return 0;
}
#include<iostream>
#include<math.h>
double a, b, c, d, e, f;
int main()
{
while(std::cin>>a>>b>>c>>d>>e>>f)
{
double x = (e*c-b*f)/(a*e-b*d);
double y = (-d*c+a*f)/(a*e-b*d);
printf("%.3lf %.3lf\n",x+(1e-10),y+(1e-10));
}
return 0;
}
#include<iostream>
using namespace std;
int a, b;
int change;
int GCD(int m, int n)
{
if((0==m)||(0==n))
{
return 0;
}
while(m!=n)
{
if(m>n)
{
m=m-n;
}
else
{
n=n-m;
}
}
return m;
}
int LCM(int m,int n)
{
if((0==m)||(0==n))
{
return 0;
}
return m/GCD(m,n)*n;
}
int main()
{
while(cin>>a>>b)
{
printf("%d %d\n",GCD(a,b),LCM(a,b));
}
}
#include<iostream>
using namespace std;
char str[20];
int main()
{
cin>>str;
for(int i=0;i<20;++i)
{
if(str[19-i]!=0)
{
printf("%c",str[19-i]);
}
}
printf("\n");
}
#include<iostream>
using namespace std;
double money = 100000;
int i;
int main()
{
cin>>i;
for(i;i>0;--i)
{
money *= 1.05;
money = (long)(money/1000+0.99)*1000;
}
printf("%.0lf\n",money);
}
#include<iostream>
using namespace std;
int n;
int count;
int main()
{
while(cin>>n)
{
for(int i=0;i<=9;++i)
{
for(int j=0;j<=9;++j)
{
for(int k=0;k<=9;++k)
{
for(int l=0;l<=9;++l)
{
if(i+j+k+l==n)
{
++count;
}
}
}
}
}
cout<<count<<endl;
count = 0;
}
}
#include<iostream>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int count = 0;
bool *flag = new bool[n+1]();
for(int i=2;i<=n;++i)
{
if (flag[i])
{
continue;
}
for(int j=i*2;j<=n;j+=i)
{
flag[j] = true;
}
}
flag[0]=true;
flag[1]=true;
for(int i=0;i<=n;++i)
{
if(!flag[i])
{
++count;
}
}
cout<<count<<endl;
}
}
using System;
namespace primeget
{
class Program
{
static void Main()
{
Console.WriteLine("Please enter the maximum value to calculate the prime number.");
Console.WriteLine("Creat by aoisensi.");
int MaxValue = int.Parse(Console.ReadLine());
bool[] flag = new bool[MaxValue];
for(int i = 2; i < MaxValue; i++)
{
if (flag[i] == true)
{
continue;
}
for(int j = i*2; j < MaxValue; j += i)
{
flag[j] = true;
}
}
for (int i = 2; i < MaxValue; i++)
{
if (flag[i] == false)
{
Console.WriteLine(i);
}
}
Console.WriteLine("End");
Console.WriteLine("続行するには何かキーを押してください…");
Console.ReadKey();
}
}
}