Jump to content

  • Log In with Google      Sign In   
  • Create Account


OCN.FiX

Member Since 14 Sep 2011
Offline Last Active Mar 31 2012 03:43 PM
-----

Topics I've Started

Tracing a ray to a certain X value

01 March 2012 - 01:34 AM

Hi all,

I'm trying to work on an editor for my game, and I'm having issues tracing a ray to a certain point.
On click, the Editor needs to trace the mouse ray to the Z point of 3, and add a 'plane' (rectangle) at that point.
It seems to be getting in the right sort of area on click, but its always off.
Posted Image
The red dot illustrates where I've clicked.
I've uploaded the files for you to play with (easier than me trying to explain)
http://jameswarner.c...ther/Editor.rar

And heres the code that handles the tracing of the ray and adding plane:
void Editor::addPlane(D3DXVECTOR3 oldMPos, D3DXVECTOR3 oldMDir, string texName, float* texScale, int whichForm)
{
D3DXMATRIX matView, matWorld;  

d3ddev->SetTransform(D3DTS_WORLD, &matStart);
matWorld = matStart;

if(whichForm == 0)
{
fpsCamera->calculateViewMatrix(&matView);
cameraPos[whichForm] = fpsCamera->getPosition();
cameraEyePos[whichForm] = fpsCamera->getEyePos();
}
else
{
D3DXMatrixLookAtLH(&matView,
&cameraPos[whichForm],  
&cameraEyePos[whichForm],  
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));  
}
d3ddev->SetTransform(D3DTS_VIEW, &matView);

D3DXMATRIX matProjection;	
D3DXMatrixPerspectiveFovLH(&matProjection,
D3DXToRadian(45),
(FLOAT)screenSize[whichForm].x / (FLOAT)screenSize[whichForm].y,
1.0f,  
100.0f);  
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);

POINT mousePos;
GetCursorPos(&mousePos);

D3DXVECTOR3 mouseOut, mouseOut2;
D3DVIEWPORT9 viewPort;

d3ddev->GetViewport(&viewPort);

ScreenToClient(hWnd[whichForm], &mousePos);

RECT temp;
GetClientRect(hWnd[whichForm], &temp);

D3DXVec3Unproject(&mouseOut, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MinZ), &viewPort, &matProjection, &matView, &matWorld);
D3DXVec3Unproject(&mouseOut2, &D3DXVECTOR3(mousePos.x, mousePos.y, viewPort.MaxZ), &viewPort, &matProjection, &matView, &matWorld);

float wz = 3.0f;
float wx = ((wz - mouseOut.z) * (mouseOut2.x - mouseOut.x)) / (mouseOut2.z - mouseOut.z) + mouseOut.x;
float wy = ((wz - mouseOut.z) * (mouseOut2.y - mouseOut.y)) / (mouseOut2.z - mouseOut.z) + mouseOut.y;
D3DXVECTOR3 mouseFinal = D3DXVECTOR3(wx, wy, wz);

addPlane(D3DXVECTOR2(mouseFinal.x, mouseFinal.y), D3DXVECTOR2(1.0f, 1.0f), 0.0f, PhysDefinition(NoPhysics, 0.0f, 0.0f, 0.0f), ForeGroundPlane, TextureDefinition(texName, D3DXVECTOR2(texScale[0], texScale[1]), 0.0f));
}

Any help appreciated

Thanks,
James

Rendering onto DepthStencilSurface causing black screen

15 February 2012 - 02:51 AM

Hi all,

Working on an editor for my game, with multiple swap chains (3 excluding implicit one to be exact) and I've run across a slight problem.
Since you cant have D3D9 create and manage the depth stencil with multiple swap chains, I've come across the need to make my own.
The swap chains initialize right, and are set to render to per frame. All the HRESULTs return S_OK and theres no errors in the log from DirectX (debug mode is on) - theres only warnings about redundant render states.
Any ideas? Please post if you want me to add some code from the editor.

Thanks,
James

[D3D9] 'Drawing' into window

12 February 2012 - 09:41 PM

Hi all,

Working on a level editor for my engine (still), and I'm at a loss as to how I should go about this next bit.
I want to have the user click, drag and release to make a box (which will be turned into a plane - 2D engine).
I can't seem to get the mouse coordinates to relate to the position in the 3d view.
Heres an image just so you guys can see what I've currently got:
Posted Image
Note, it has 3D views because I want this editor to be re-usable in the future.

Any help appreciated,

Thanks,
James Warner

Creating a grid (DX9)

24 January 2012 - 08:42 PM

Hi all,

Looking into creating a grid like in the Valve Hammer editor for use in my map editor.
I'll attach what I've got so far and a snippet of the valve hammer editors grid for reference.
What I have at the moment:
Posted Image
What I want it to look like:
Posted Image
The code Im using is:
void EditorDXHandler::renderGrid()
{
static int GridSize = 10;
static D3DXMATRIX matIdentity;

d3ddev->SetFVF(GRIDFVF);

if(!gridInit)
{
d3ddev->CreateVertexBuffer(sizeof(GRIDVERTEX) * GridSize * 9,
  0,
  GRIDFVF,
  D3DPOOL_MANAGED,
  &g_buffer,
  0);

GRIDVERTEX* pGridData = 0;
g_buffer->Lock(0, 0, (void**)&pGridData, 0);

int index = 0;
for(; index <= GridSize * 4 + 1; index++)
{
float x = (index % 2) ? GridSize : -GridSize;
float y = index / 2 - GridSize;
float z = 0.0f;

pGridData[index].position = D3DXVECTOR3(x, y, z);
pGridData[index].color = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
}

for(; index <= GridSize * 8 + 4; index++)
{
static int half = index;
float x = (index - half) / 2 - GridSize;
float y = (index % 2) ? -GridSize : GridSize;
float z = 0.0f;

pGridData[index].position = D3DXVECTOR3(x, y, z);
pGridData[index].color = D3DXCOLOR(0.4f, 0.4f, 0.4f, 1.0f);
}

g_buffer->Unlock();

D3DXMatrixIdentity(&matIdentity);
gridInit = true;
}

d3ddev->SetTransform(D3DTS_WORLD, &matIdentity);
d3ddev->SetStreamSource(0, g_buffer, 0, sizeof(GRIDVERTEX));
d3ddev->SetTexture(0, NULL);
d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, GridSize * 4 + 2);
}

Thanks,
James Warner

Issues resizing swap chain (DX9)

22 January 2012 - 08:32 PM

Hi all,

Im working on an editor, but I'm having issues resizing the swap chains (theres 4 (including the main device)). The main devices swap chain resizes correctly, but the 3 subsequent ones dont. Il post an image of the editor and then post some more code (easier than trying to explain Posted Image).
Posted Image
And the code:
On resize, this is called:
void DXHandler::updateBackBuffer(int width, int height, short which)
{
screenSize[which].x = width;
screenSize[which].y = height;
d3dpp.BackBufferHeight = screenSize[which].x;
d3dpp.BackBufferWidth = screenSize[which].y;
d3dpp.hDeviceWindow = hWnd[which];

invalidateDeviceObjects();

HRESULT hr = d3ddev->Reset(&d3dpp);

if(hr != D3D_OK)
{
MessageBox(NULL, "Call to Reset() failed!", "ERROR", MB_OK | MB_ICONEXCLAMATION);
}

restoreDeviceObjects();
}
Restore device objects is:
void DXHandler::restoreDeviceObjects()
{
d3ddev->GetSwapChain(0, &swapchains[0]);
d3ddev->GetDepthStencilSurface(&depthStencils[0]);

for(int i = 1; i < 4; i++)
{
d3dpp.BackBufferHeight = screenSize[i].x;
d3dpp.BackBufferWidth = screenSize[i].y;
d3dpp.hDeviceWindow = hWnd[i];

d3ddev->CreateDepthStencilSurface(d3dpp.BackBufferHeight, d3dpp.BackBufferWidth, d3dpp.BackBufferFormat, d3dpp.MultiSampleType, d3dpp.MultiSampleQuality, true, &depthStencils[i], NULL);

d3ddev->CreateAdditionalSwapChain(&d3dpp, &swapchains[i]);
}

init_light();

d3ddev->SetRenderState(D3DRS_LIGHTING, TRUE);  
	d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);  
	d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));  

D3DXCreateTeapot(d3ddev, &meshTeapot, NULL);
}

Any ideas?

Thanks,
James

PARTNERS