Sign in to follow this  

Need some help with my Code here, I want to add functionalities to the buttons on the bottom.

This topic is 2085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my code so far....[url="http://pastebin.com/LxmSuMe8"]http://pastebin.com/LxmSuMe8[/url]

[img]http://a7.sphotos.ak.fbcdn.net/hphotos-ak-prn1/s720x720/534458_393227180701838_100000436774205_1280431_541445092_n.jpg[/img]






I have the mouse pointer working so far and all that jazz... Basically I want to click on the buttons and the balls up there to create the shapes. I already have an idea of how the algorithms work but I just want to know how to make the buttons work. :/ My code isn't commented yet but I"m going to do it soon and update it for your guys ease but it's pretty straight forward... I know it's ugly but sorry guys.... anyway tips would be wonderful

Share this post


Link to post
Share on other sites
How I do it, is I color pick the scene. What I mean by that is that you render an off screen surface of only your buttons, each one a different solid color(randomly generated). Then on mouse down event, check what color the pixel is that your mouse is hovering over, and that is the button that is "clicked".

Edit: Granted, this method I propose is fairly lengthy, but it allows for picking ANY object in the scene, no matter what you are drawing. It is image based, so this method supports any number of objects on screen. In your case, if your buttons are always going to be in the same location, it would be easier to
just check the RECT coordinates of the buttons and see if your mouse is over or not.

Edit Again: Sorry! Just noticed you are writing in C#, so this code isn't applicable, but the concept is still the same =)

This is my implementation minus the actual drawing.
[code]
//Create offscreen surface to read surface data
IDirect3DSurface9* offScreenBuffer;
if(_d3dDevice->CreateOffscreenPlainSurface(_appWidth, _appHeight, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &offScreenBuffer, 0) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to create off screen surface!", __FILE__, __LINE__);

IDirect3DSurface9* source;
_d3dDevice->GetRenderTarget(0, &source);

if(_d3dDevice->GetRenderTargetData(source, offScreenBuffer) != D3D_OK)
ErrorMessenger::ReportMessage("Failed to GetRenderTargetData!", __FILE__, __LINE__);

//Lock surface data
D3DLOCKED_RECT surfaceData;
offScreenBuffer->LockRect(&surfaceData, 0, D3DLOCK_READONLY);

//Sample for pixel color to determine what object the mouse is colliding with
BYTE* bytePointer = (BYTE*)surfaceData.pBits;

//Get the index where the mouse is located
DWORD index = (mouseX * 4 + (mouseY * (surfaceData.Pitch)));

//Get the color
//X8R8G8B8 surface format
BYTE green = bytePointer[index];
BYTE blue = bytePointer[index + 1];
BYTE red = bytePointer[index + 2];

offScreenBuffer->UnlockRect();

//Find the object that belongs to the color
D3DXVECTOR4 searchColor = D3DXVECTOR4(((float)red / 255.0f), ((float)blue / 255.0f), ((float)green / 255.0f), 1.0f);
for(int i = 0; i < _worlds[_views[view].world].Size(); i++)
{
//Check in a range, color output from PS is not perfect
if(searchColor.x <= colors[i].x + 0.01f && searchColor.x >= colors[i].x - 0.01f &&
searchColor.y <= colors[i].y + 0.01f && searchColor.y >= colors[i].y - 0.01f &&
searchColor.z <= colors[i].z + 0.01f && searchColor.z >= colors[i].z - 0.01f)
{
return i;//Object found
}
}

//Mouse was not colliding with an object.
return NO_INDEX;
[/code]

Share this post


Link to post
Share on other sites
Hidden
Oh Thanks, I managed to change my code and use this http://msdn.microsoft.com/en-us/library/bb197572%28v=xnagamestudio.30%29.aspx

So now I have a working position marker mouse thing. Basically now all I have to do is make it "on click" and find out how to compare an entire range of Pixels... Any idea how I would be able to do this? For example, Anything from x=150 to X=200 to Y=100 to Y=50. So the after that it would be like If oh NVM... it's basic .... I feel a tad stupid... XD Now I just need to make the function work for for "On Click" run the Position checker. Position checker will then evaluate the positions of the mouse and return the function that needs to be done... lets see about that.... shouldn't be too difficult.

Share this post


Link to post
http://pastebin.com/i4pG9N5b

Alright that's my new Code, I managed to learn some stuff and now whenever I click it it changes background, It's pretty awesome... Now I"m over the hurdle and no longer need help. Thanks man tough.

Share this post


Link to post
Share on other sites

This topic is 2085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this