Jump to content

  • Log In with Google      Sign In   
  • Create Account


granberg

Member Since 28 Apr 2011
Offline Last Active Sep 23 2011 10:59 AM

#4814804 Role playing code

Posted by granberg on 23 May 2011 - 05:22 PM

There is some code experts from jim adams's book Programming Role playing games
if(Size > m_MaxSize && Num > m_MaxPolygons) {
for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) {
XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f);
ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f);
YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f);

// See if any polygons in new node bounding box
if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) {

Node->Nodes[i] = new sNode(); // Create new child node

// Sort the polygons with the new child node
SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f);
}
}
does someone undertstand why we caculate the Xoff and Yoff and ZOff as this way,try to explain that code very detail don't use the depth math than I can undertstand !


#4814690 Developing a advanced 3D game engine

Posted by granberg on 23 May 2011 - 12:22 PM

Your guys don't know the expalin of thease code is so rude for me,I read that section again again,but no words can give me a way to slove it understand it!so don,t delay my time,just to explain it that is all!


#4814657 Developing a advanced 3D game engine

Posted by granberg on 23 May 2011 - 11:26 AM

if you read the book programming role playing games,you must remember the function as below:
if(Size > m_MaxSize && Num > m_MaxPolygons) {
for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) {
if(Size > m_MaxSize && Num > m_MaxPolygons) {
for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) {
XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f);
ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f);
YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f);

// See if any polygons in new node bounding box
if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) {

Node->Nodes[i] = new sNode(); // Create new child node

// Sort the polygons with the new child node
SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f);
}
}

// See if any polygons in new node bounding box
if(CountPolygons(XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f)) {

Node->Nodes[i] = new sNode(); // Create new child node

// Sort the polygons with the new child node
SortNode(Node->Nodes[i],XPos+XOff,YPos+YOff,ZPos+ZOff,Size/2.0f);
}
}
Ok so jog your mind what 's mean with thease code?:
if(Size > m_MaxSize && Num > m_MaxPolygons) {
for(i=0;i<(unsigned long)((m_TreeType==QUADTREE)?4:8);i++) {
XOff = (((i % 2) < 1) ? -1.0f : 1.0f) * (Size / 4.0f);
ZOff = (((i % 4) < 2) ? -1.0f : 1.0f) * (Size / 4.0f);
YOff = (((i % 8) < 4) ? -1.0f : 1.0f) * (Size / 4.0f);

please explain thease code to me special on how to caculate the xOff and ZOff and YOff value,tell me where they come?




#4811816 Did someone can share his learn methoods

Posted by granberg on 17 May 2011 - 01:26 AM

I learn game programming from some book,I find a question,I read through all the code of the book,but finally I can't write the code myself,some author suggession our reader copy the code again by again,
get the effect of learn ,but I feel that is no real effect for me,so does someone call answer my question,
how to learn it?


#4809967 Kenneth.C.Finney email

Posted by granberg on 12 May 2011 - 03:35 PM

Ok I'm a reader let me know kenneth.c.Finney email ok?


#4809937 Greg snock's email

Posted by granberg on 12 May 2011 - 02:35 PM

HI someone offer me Gerg snock's email who write the book game programming geamsand Terrain engine programming ,please send his email address at frankluna11@yahoo.com


#4808926 exported to x file

Posted by granberg on 10 May 2011 - 06:36 AM

I have use x file to my game,I buy a model ,they are created in 3ds max 2009,I use 3ds max 2012 ,I open it I find I have a lot of error,they say I have lost essential file,they say three jpg file that doesn't exists,Idon't
know why I got this problem,then I use panda exporter to export the max file to x file format,but I don't know
how to export,I was export the max file to x file format when I use 3ds max 8.0,but I always don't get the correct x file from exported,what do you think, help me!


#4806511 A Rts Game

Posted by granberg on 04 May 2011 - 12:08 PM

what are you doing superVGA send model to me




#4806507 A Rts Game

Posted by granberg on 04 May 2011 - 12:04 PM

please post your model to me




#4806502 A Rts Game

Posted by granberg on 04 May 2011 - 11:57 AM

if you happen send me at frankluna11@yahoo.com


#4806410 A Rts Game

Posted by granberg on 04 May 2011 - 08:20 AM

I want to got a model to make my Rts Game,like a world war 2 solidier and tank model so many thing I need it,and I need some tree ,some building,some terrain things like walter.swamp. if you can offer it,
I pay for you maney,then reach me at frankluna11@yahoo.com


#4806264 I want to got a 3d model

Posted by granberg on 03 May 2011 - 10:58 PM

Hi friend ,I want to got a 3d model ,a solidier model for the rts game and hero model ,the x file please give me


#4806065 Andrew lamothe's email

Posted by granberg on 03 May 2011 - 12:53 PM

did everybody know andrew lamothe's email address if you known tell me


#4805054 a arthur's name

Posted by granberg on 01 May 2011 - 08:41 AM

did you know jim adams's email who write the book programmimng rpg game pleae tell me at frankluna11@yahoo.com


#4803949 about role playing games

Posted by granberg on 28 April 2011 - 07:07 AM

HI body I read the book programming role playing games with directx the author say he is online in this message forum, I write the message I want to call the author jim adams. if you is jim or any other game programming auhtor,please answer my question : what is your email: and look the code as below:answer me!
/**************************************************
WinMain.cpp
Chapter 2 Billboard Demo

Programming Role-Playing Games with DirectX, 2nd Edition
by Jim Adams (Jan 2004)

Required libraries:
D3D9.LIB and D3DX9.LIB
**************************************************/

// Include files
#include <windows.h>
#include <stdio.h>
#include "d3d9.h"
#include "d3dx9.h"

// Window handles, class and caption text
HWND g_hWnd;
HINSTANCE g_hInst;
static char g_szClass[] = "BillboardClass";
static char g_szCaption[] = "Billboard Demo by Jim Adams";

// The Direct3D and Device object
IDirect3D9 *g_pD3D = NULL;
IDirect3DDevice9 *g_pD3DDevice = NULL;

// The 3D vertex format and descriptor
typedef struct {
FLOAT x, y, z; // 3D coordinates
FLOAT u, v; // Texture coordinates
} s3DVertex;
#define FVF3D (D3DFVF_XYZ | D3DFVF_TEX1)

// The billboard vertex buffer and texture
IDirect3DVertexBuffer9 *g_pBillboardVB = NULL;
IDirect3DTexture9 *g_pBillboardTexture = NULL;

// The floor vertex buffer and texture
IDirect3DVertexBuffer9 *g_pFloorVB = NULL;
IDirect3DTexture9 *g_pFloorTexture = NULL;

// Function prototypes
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow);
long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

BOOL DoInit();
BOOL DoShutdown();
BOOL DoFrame();
BOOL SetupMeshes();

int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
WNDCLASSEX wcex;
MSG Msg;

g_hInst = hInst;

// Create the window class here and register it
wcex.cbSize = sizeof(wcex);
wcex.style = CS_CLASSDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_szClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcex))
return FALSE;

// Create the Main Window
g_hWnd = CreateWindow(g_szClass, g_szCaption,
WS_CAPTION | WS_SYSMENU,
0, 0, 400, 400,
NULL, NULL,
hInst, NULL );
if(!g_hWnd)
return FALSE;
ShowWindow(g_hWnd, SW_NORMAL);
UpdateWindow(g_hWnd);

// Run init function and return on error
if(DoInit() == FALSE)
return FALSE;

// Start message pump, waiting for signal to quit
ZeroMemory(&Msg, sizeof(MSG));
while(Msg.message != WM_QUIT) {
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
if(DoFrame() == FALSE)
break;
}

// Run shutdown function
DoShutdown();

UnregisterClass(g_szClass, hInst);

return Msg.wParam;
}

long FAR PASCAL WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

BOOL DoInit()
{
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
D3DXMATRIX matView, matProj;

// Do a windowed mode initialization of Direct3D
if((g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
return FALSE;
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return FALSE;
ZeroMemory(&d3dpp, sizeof(d3dpp));

d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pD3DDevice)))
return FALSE;

// Set the render states
g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
g_pD3DDevice->SetRenderState(D3DRS_ALPHAREF, 0x01);
g_pD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);

// Create and set the projection transformation
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f);
g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);

// Create the meshes
SetupMeshes();

return TRUE;
}

BOOL DoShutdown()
{
// Release textures and vertex buffers
if(g_pBillboardTexture != NULL)
g_pBillboardTexture->Release();

if(g_pBillboardVB != NULL)
g_pBillboardVB->Release();

if(g_pFloorTexture != NULL)
g_pFloorTexture->Release();

if(g_pFloorVB != NULL)
g_pFloorVB->Release();

// Release device and 3D objects
if(g_pD3DDevice != NULL)
g_pD3DDevice->Release();

if(g_pD3D != NULL)
g_pD3D->Release();

return TRUE;
}

BOOL DoFrame()
{
D3DXMATRIX matView, matWorld;
float Angle;
short i, j;

// Clear device backbuffer
g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0);

// Update the view position
Angle = (float)timeGetTime() / 2000.0f;
D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3((float)cos(Angle) * 200.0f, 200.0f, (float)sin(Angle) * 200.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);

if(SUCCEEDED(g_pD3DDevice->BeginScene())) {
// Draw the floor
g_pD3DDevice->SetStreamSource(0, g_pFloorVB, 0, sizeof(s3DVertex));
g_pD3DDevice->SetFVF(FVF3D);
g_pD3DDevice->SetTexture(0, g_pFloorTexture);
D3DXMatrixIdentity(&matWorld);
g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

// Draw the billboards
g_pD3DDevice->SetStreamSource(0, g_pBillboardVB, 0, sizeof(s3DVertex));
g_pD3DDevice->SetTexture(0, g_pBillboardTexture);

g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
D3DXMatrixTranspose(&matWorld, &matView);
for(i=0;i<3;i++) {
for(j=0;j<3;j++) {
matWorld._41 = (float)i * 80.0f - 80.0f;
matWorld._42 = 0.0f;
matWorld._43 = (float)j * 80.0f - 80.0f;

g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
}
}
g_pD3DDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

// Clear the texture usage
g_pD3DDevice->SetTexture(0, NULL);

// End the scene
g_pD3DDevice->EndScene();
}

// Display the scene
g_pD3DDevice->Present(NULL, NULL, NULL, NULL);

return TRUE;
}

BOOL SetupMeshes()
{
BYTE *Ptr;
s3DVertex BillboardVerts[4] = {
{ -42.0f, 80.0f, 0.0f, 0.0f, 0.0f },
{ 40.0f, 80.0f, 0.0f, 1.0f, 0.0f },
{ -40.0f, 0.0f, 0.0f, 0.0f, 1.0f },
{ 40.0f, 0.0f, 0.0f, 1.0f, 1.0f }
};

s3DVertex FloorVerts[4] = {
{ -100.0f, 0.0f, 100.0f, 0.0f, 0.0f },
{ 100.0f, 0.0f, 100.0f, 1.0f, 0.0f },
{ -100.0f, 0.0f, -100.0f, 0.0f, 1.0f },
{ 100.0f, 0.0f, -100.0f, 1.0f, 1.0f }
};

// Create vertex buffers and stuff in data
// Billboard
if(FAILED(g_pD3DDevice->CreateVertexBuffer( \
sizeof(BillboardVerts), 0, FVF3D, \
D3DPOOL_DEFAULT, &g_pBillboardVB, NULL)))
return FALSE;
if(FAILED(g_pBillboardVB->Lock(0,0, (void**)&Ptr, 0)))
return FALSE;
memcpy(Ptr, BillboardVerts, sizeof(BillboardVerts));
g_pBillboardVB->Unlock();

// Floor
if(FAILED(g_pD3DDevice->CreateVertexBuffer( \
sizeof(FloorVerts), 0, FVF3D, \
D3DPOOL_DEFAULT, &g_pFloorVB, NULL)))
return FALSE;
if(FAILED(g_pFloorVB->Lock(0,0, (void**)&Ptr, 0)))
return FALSE;
memcpy(Ptr, FloorVerts, sizeof(FloorVerts));
g_pFloorVB->Unlock();

// Get textures
D3DXCreateTextureFromFile(g_pD3DDevice, "Floor.bmp", &g_pFloorTexture);
D3DXCreateTextureFromFileEx(g_pD3DDevice, "Billboard.bmp",
D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A1R5G5B5,
D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE,
D3DCOLOR_RGBA(0,0,0,255), NULL, NULL, &g_pBillboardTexture);

return TRUE;
}
did you see the code D3DXMatrixTranspose(&matWorld, &matView); why we need transpose the matrix, flip the values in the matrix diagonally,why?
wait you reply !




PARTNERS