Jump to content

  • Log In with Google      Sign In   
  • Create Account


Sh@dow

Member Since 02 Sep 2009
Offline Last Active Aug 04 2011 09:38 AM

Topics I've Started

[DX8] GetDeviceState for joystick

02 August 2011 - 04:12 PM

Hi everyone,
I'm using DirectInput to read joystick state. Especially i need button states. Here is the code.

BOOL CALLBACK
enumCallback(const DIDEVICEINSTANCE* instance, VOID* context)
{
    HRESULT result;
    result = di->CreateDevice(instance->guidInstance, &joystick, NULL);
    if (FAILED(result)) { 
        return DIENUM_STOP;
    }
    return DIENUM_CONTINUE;
}

bool EnumerateDevices()
{
if (FAILED(result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
                               	IID_IDirectInput8, (VOID**)&di, NULL))) 
	{
		return false;
	}
	if (FAILED(result = di->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback,
                                NULL, DIEDFL_ATTACHEDONLY))) {
    return false;
	}
}

//////////////////MAIN CODE////////////////////
if (joystick == NULL) {
    OutputDebugString(L"JOYSTIC NOT FOUND\n");
    return false;
}

DIDEVCAPS capabilities;

if (FAILED(result = joystick->SetDataFormat(&c_dfDIJoystick))) 
{
	OutputDebugString(L"ERROR\n");
    return;
}

if (FAILED(result = joystick->SetCooperativeLevel(dlg_handle, DISCL_NONEXCLUSIVE |
                                              DISCL_BACKGROUND))) 
{
	OutputDebugString(L"ERROR\n");
    return;
}
capabilities.dwSize = sizeof(DIDEVCAPS);
if (FAILED(result = joystick->GetCapabilities(&capabilities))) 
{
	OutputDebugString(L"ERROR\n");
    return;
}
// this structure holds the data for the property changes
DIPROPRANGE joy_axis_range;
// first set x axis tp -1024 to 1024
joy_axis_range.lMin = -1024;
joy_axis_range.lMax = 1024;

joy_axis_range.diph.dwSize   	= sizeof(DIPROPRANGE);
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
joy_axis_range.diph.dwObj  = DIJOFS_X;
joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
joystick->SetProperty(DIPROP_RANGE,&joy_axis_range.diph);

// now y-axis
joy_axis_range.lMin = -1024;
joy_axis_range.lMax = 1024;
joy_axis_range.diph.dwSize   	= sizeof(DIPROPRANGE);
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
joy_axis_range.diph.dwObj        = DIJOFS_Y;
joy_axis_range.diph.dwHow        = DIPH_BYOFFSET;
joystick->SetProperty(DIPROP_RANGE,&joy_axis_range.diph);
    
if (joystick == NULL) {
   	OutputDebugString(L"Joystic not found\n");
    }
	result = joystick->Acquire();
	if (FAILED(result = joystick->GetDeviceState(sizeof(DIJOYSTATE), &js))) {
        OutputDebugString(L"The device should have been acquired during the Poll()\n");
		return; 
    }

    joystick->Unacquire();
	joystick->Release();

In EnumDevice i see that the joystic is found. In GetCapabilities function i see the correct parameters of the joystick. When I say Poll the result is DI_NOEFFECT. Sho i removed Poll method. Acquire returns no errors. But after i say GetDeviceState the rgbButtons are zeros even if i press buttons.
The program is dialog based. In CooperativeLevel i pass the handle of the dialog. Where is the problem? Why buttons are not readed?
Thanks,

Create 2D model in 3ds max

12 July 2011 - 10:07 AM

Hi all,

I'm developing a simple game (2D) and i need to draw a model.
Is it possible to draw a model on a plane in 3ds max using primitives(circle,oval) and export vertex coordinates to a file? How could i do this?
I see that 3ds max works only in 3D.
Thanks,

Lesson 43: How texture is rendered

17 June 2011 - 05:27 AM

In Lesson 43 to render a texture from free type font we are saying:

glBegin(GL_QUADS);
	glTexCoord2d(0,0); glVertex2d(0,bitmap.rows);
	glTexCoord2d(0,y); glVertex2d(0,0);

	glTexCoord2d(x,y); glVertex2d(bitmap.width,0);
	glTexCoord2d(x,0); glVertex2d(bitmap.width,bitmap.rows);

I can't understand what does this code do? We are drawing here two quads: first has all x = 0; What does this supposed to mean?
Thanks.

Several Graphics in single window

19 March 2011 - 02:34 PM

Hi, everyone
I need to plot different types of graphics in one window. I'm using C++ language on Win platform.
My problem is that i can't correctly imagine a whole program architecture.
I have several objects each one draws the specific types of graph(signal, 2d matrix). These objects expect device context as a parameter. But if i have only one window that means i have only one device context. As i understand the device context could not be divided into areas to draw separately into them. I can draw into the whole device context at one time. That's a problem to me because i can't redraw graphics independently.Imagine we have two graphics. When new data comes for graph1 i want to redraw it (not the entire window area and other graph2) so i can't do that.Or maybe i can?:D Is there any way to redraw only part of the window.Some kind of incremental drawing?

Projection distortion with gluPerspective

27 October 2010 - 08:46 AM

Hi everyone,
I'm reading "The Official Guide to Learning OpenGL Version 1.1" and found something i can't understand.
I'll let myself to cite a paragraph from it:
Quote:

With gluPerspective() you need to pick appropriate values for the field of view, or the image may look distorted. For example,suppose you're drawing to the entire screen, which happens to be 11 inches high. If you choose a filed of view of 90 degrees, your eye has to be about 7.8 inches from the screen for the image to appear undistorted.(This is the distance that makes the screen subtend 90 degrees.) If your eye is farther from the screen, as it usually is, the perspective doesn't look right.

I can't understand why the distance is 7.8. As i understood the distance must be 5.5.

PARTNERS