Skip to main content
gamedev.net
🔒 Locked

Problem with d3d rotation.

Started by SSJCORY Jan 2, 2004 at 10:55 PM 3 replies 400+ views
Original Post
SSJCORY
SSJCORY
Ok when I compile the sdk tutorial source code for matrices. It worked using the function timeGetTime(). It used this in rotating the around the y axis. When I used it it gave me an error. Also I would like someone to look over my code and see if it is correct.
#define WIN32_LEAN_AND_MEAN
#include<windows.h>
#include<d3d8.h>
#include<d3dx8.h>
#include<mmsystem.h>
#pragma comment(lib,"d3d8.lib")
#pragma comment(lib,"d3dx8.lib")

struct CUSTOMVERTEX{
	FLOAT x,y,z;
	DWORD color;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
LPDIRECT3D8 pd3d;
IDirect3DDevice8 *pd3dd;
IDirect3DVertexBuffer8 *pvb;

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
void AskFullScreen();
void InitWindow();
void InitD3D();
void InitMatrices();
void InitGeometry();
void InitGame();
void MessageHandler();
void Render();
void KillGame();
void KillD3D();
void KillWindow();

const int gwidth = 640;
const int gheight = 480;
const char gamename[] = "D3D Matrix Usage";
const char winclass[] = "Class";

HWND ghwnd;
HINSTANCE gInstance;

bool fullscreen = true;
bool gameover = false;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR CmdLine,int iCmd){
	gInstance = hInstance;
	AskFullScreen();
	InitWindow();
	InitD3D();
	InitMatrices();
	InitGeometry();
	InitGame();
	while(!gameover){
		MessageHandler();
		Render();
	}
	KillGame();
	KillD3D();
	KillWindow();
	return 0;
}
void AskFullScreen(){
	int full;
	full = MessageBox(NULL,"Fullscreen?","Fullscreen",MB_YESNOCANCEL);
	switch(full){
	case IDYES:
		fullscreen = true;
		break;
	case IDNO:
		fullscreen = false;
		break;
	case IDCANCEL:
		exit(5);
		break;
	}
}
void InitWindow(){
	DWORD style;
	ULONG width,height;
	WNDCLASS wc;
	
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.hInstance = gInstance;
	wc.lpfnWndProc = WndProc;
	wc.lpszClassName = winclass;
	wc.lpszMenuName = NULL;
	wc.style = CS_OWNDC;
	RegisterClass(&wc);
	if(fullscreen){
		style = WS_POPUP;
		width = GetSystemMetrics(SM_CXSCREEN);
		height = GetSystemMetrics(SM_CYSCREEN);
	}
	else{
		style = WS_OVERLAPPED|WS_SYSMENU;
		width = gwidth;
		height = gheight;
	}
	ghwnd = CreateWindow(winclass,gamename,style,0,0,width,height,NULL,NULL,gInstance,NULL);
	ShowWindow(ghwnd,SW_SHOW);
	UpdateWindow(ghwnd);
	SetFocus(ghwnd);
}
void InitD3D(){
	D3DPRESENT_PARAMETERS d3dpp;
	D3DDISPLAYMODE d3ddm;
	pd3d = Direct3DCreate8(D3D_SDK_VERSION);
	pd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);
	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferCount = 1;
	d3dpp.hDeviceWindow = ghwnd;
	if(fullscreen){
		d3dpp.BackBufferWidth = gwidth;
		d3dpp.BackBufferHeight = gheight;
		d3dpp.Windowed = FALSE;
		d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
	}
	else{
		d3dpp.Windowed = TRUE;
		d3dpp.BackBufferFormat = d3ddm.Format;
	}
	pd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,ghwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dd);
	pd3dd->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
	pd3dd->SetRenderState(D3DRS_LIGHTING,FALSE);
}
void InitMatrices(){
	D3DXMATRIX worldMat;
	D3DXMatrixRotationY(&worldMat,timeGetTime()/150.0f);
	pd3dd->SetTransform(D3DTS_WORLD,&worldMat);

	D3DXMATRIX viewMat;
	D3DXMatrixLookAtLH(&viewMat,&D3DXVECTOR3(0.0f,0.0f,-5.0f),&D3DXVECTOR3(0.0f,0.0f,0.0f),&D3DXVECTOR3(0.0,1.0,0.0));
	pd3dd->SetTransform(D3DTS_VIEW,&viewMat);

	D3DXMATRIX projMat;
	D3DXMatrixPerspectiveFovLH(&projMat,D3DX_PI/4,1.0f,1.0f,100.0f);
	pd3dd->SetTransform(D3DTS_PROJECTION,&projMat);
}
void InitGeometry(){
	CUSTOMVERTEX Triangle[] = {
		{-1.0f,-1.0f,0.0f,0xffff0000},
		{1.0f,-1.0f,0.0f,0xffff0000},
		{0.0f,1.0f,0.0f,0xffff0000}
	};
	pd3dd->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&pvb);
	VOID* pvertices;
	pvb->Lock(0,sizeof(Triangle),(BYTE**)&pvertices,0);
	memcpy(pvertices,Triangle,sizeof(Triangle));
	pvb->Unlock();
}
void InitGame(){
}
void MessageHandler(){
	MSG msg;
	if(PeekMessage(&msg,ghwnd,0,0,PM_REMOVE)){
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
}
void Render(){
	pd3dd->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
	
	pd3dd->BeginScene();
	pd3dd->SetStreamSource(0,pvb,sizeof(CUSTOMVERTEX));
	pd3dd->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	pd3dd->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,1);
	pd3dd->EndScene();
	pd3dd->Present(NULL,NULL,NULL,NULL);

}
void KillGame(){
}
void KillD3D(){
	if(pd3d != NULL){
		pd3d->Release();
	}
	if(pd3dd != NULL){
		pd3dd->Release();
	}
}
void KillWindow(){
	ghwnd = NULL;
	gInstance = NULL;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
	switch(msg){
	case WM_DESTROY:
		gameover = true;
		break;
	case WM_KEYDOWN:
		gameover = true;
		break;
	case WM_LBUTTONDOWN:
		gameover = true;
		break;
	}
	return DefWindowProc(hwnd,msg,wParam,lParam);
}
Your help is greatly appreciated. I'm a noob to directx so thats why i'm posting so much, but i'm learning a lot. Thanks again, Cory EDIT: here is the error message: linking... main.obj : error LNK2001: unresolved external symbol __imp__timeGetTime@0 Debug/usingmats.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
[edited by - ssjcory on January 3, 2004 2:04:42 AM] [edited by - ssjcory on January 3, 2004 2:05:53 AM] [edited by - ssjcory on January 3, 2004 2:06:51 AM]
Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
SSJCORY
SSJCORY
Thanks again dh and i looked at your dx9 tutorials i like them a lot better than the dx8 ones. You are the directx master!I BOW TO YOUR SKILLS.



Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Favorite Quotes:Gandalf: You cannot pass!|Smeagol: We don't need you!|Sloth: Hey you guys!|
Fireface
Fireface
I just can agree with that.
DrunkenHyena tought me a lot about DX...
Every time you download warez, god kills a programmer. So please, think of the programmers!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.