Wie ktoś jak obsługuje się DirectInput co do myszki prosił bym o prosty przykład.jeśli można Jesli chodzi o wartości to nie ekranowe tylko coś w rodzaju arriva czyli warotści np -1 0 +1 oś x albo oś y
Pokaż co już sam próbowałeś zrobić.
Riddle napisał(a):
Pokaż co już sam próbowałeś zrobić.
tuta jest fajny pzryjkład: https://stackoverflow.com/questions/18830051/management-inputs-mouse-with-directx-directinput
sprawa sie ma do tego że tam są współrzędne ekranowe a nie odczyt skalarny wartości po osiach X i Y
wilkwielki napisał(a):
Riddle napisał(a):
Pokaż co już sam próbowałeś zrobić.
tuta jest fajny pzryjkład: https://stackoverflow.com/questions/18830051/management-inputs-mouse-with-directx-directinput
No to przecież tam jest też odpowiedź.
Riddle napisał(a):
wilkwielki napisał(a):
Riddle napisał(a):
Pokaż co już sam próbowałeś zrobić.
tuta jest fajny pzryjkład: https://stackoverflow.com/questions/18830051/management-inputs-mouse-with-directx-directinput
No to przecież tam jest też odpowiedź.
kombinowałem z tym przykładem ten kod jest spalony nie działa jak trzeba pomimo że dodałem dinput.lib
oraz dinput.h
Pokaż kod!
Pokaż jak kombinowałeś!
co to znacz ten kod jest spalony nie działa jak trzeba
?
Marius.Maximus napisał(a):
Pokaż kod!
Pokaż jak kombinowałeś!co to znacz
ten kod jest spalony nie działa jak trzeba
?
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
bool System::frame()
{
bool result;
if (input->isButtonDown(BUTTON_L)) //if left button is down
{
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
}
bool System::ReadMouse()
{
HRESULT result;
//this->mouseState is a DIMOUSESTATE ; this->mouse is a LDIRECTINPUTDEVICE8
result = this->mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&this->mouseState);
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
this->mouse->Acquire();
else
return false;
}
return true;
}
void System::ProcessInput()
{
this->mouseX = this->mouseState.lX;
this->mouseY = this->mouseState.lY;
if(this->mouseX < 0)
this->mouseX = 0;
if(this->mouseY < 0)
this->mouseY = 0;
if(this->mouseX > this->ScreenWidth)
this->mouseX = this->ScreenWidth;
if(this->mouseY > this->ScreenHeight)
this->mouseY = this->ScreenHeight;
return;
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
return 0;
}
--------------------Configuration: dinut - Win32 Debug--------------------
Compiling...
dinut.cpp
C:\projekty\dinut\dinut.cpp(8) : error C2653: 'System' : is not a class or namespace name
C:\projekty\dinut\dinut.cpp(11) : error C2065: 'input' : undeclared identifier
C:\projekty\dinut\dinut.cpp(11) : error C2227: left of '->isButtonDown' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(11) : error C2065: 'BUTTON_L' : undeclared identifier
C:\projekty\dinut\dinut.cpp(13) : error C2065: 'ReadMouse' : undeclared identifier
C:\projekty\dinut\dinut.cpp(13) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\projekty\dinut\dinut.cpp(16) : error C2065: 'ProcessInput' : undeclared identifier
C:\projekty\dinut\dinut.cpp(20) : error C2653: 'System' : is not a class or namespace name
C:\projekty\dinut\dinut.cpp(21) : error C2373: 'ReadMouse' : redefinition; different type modifiers
C:\projekty\dinut\dinut.cpp(25) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(25) : error C2227: left of '->mouse' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(25) : error C2227: left of '->GetDeviceState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(25) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(25) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(29) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(29) : error C2227: left of '->mouse' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(29) : error C2227: left of '->Acquire' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(36) : error C2653: 'System' : is not a class or namespace name
C:\projekty\dinut\dinut.cpp(37) : error C2373: 'ProcessInput' : redefinition; different type modifiers
C:\projekty\dinut\dinut.cpp(38) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(38) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(38) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(38) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(38) : error C2228: left of '.lX' must have class/struct/union type
C:\projekty\dinut\dinut.cpp(39) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(39) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(39) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(39) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(39) : error C2228: left of '.lY' must have class/struct/union type
C:\projekty\dinut\dinut.cpp(41) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(41) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(42) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(42) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(43) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(43) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(44) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(44) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(46) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(46) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(46) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(46) : error C2227: left of '->ScreenWidth' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(47) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(47) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(47) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(47) : error C2227: left of '->ScreenWidth' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(48) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(48) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(48) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(48) : error C2227: left of '->ScreenHeight' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(49) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(49) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(49) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(49) : error C2227: left of '->ScreenHeight' must point to class/struct/union
Error executing cl.exe.
dinut.exe - 52 error(s), 1 warning(s)
jest problem z tymi wskaźnikami this i nie dzniała
wilkwielki napisał(a):
i nie dzniała
Nie "nie działa" tylko masz elementarne problemy kompilacji
To jakiś zlepek nie wiadomo skąd zbieranych fragmentów. Sklejane bez rozumienia i znajomosci jezyka
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
bool ReadMouse()
{
HRESULT result;
//this->mouseState is a DIMOUSESTATE ; this->mouse is a LDIRECTINPUTDEVICE8
result = this->mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&this->mouseState);
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
this->mouse->Acquire();
else
return false;
}
return true;
}
bool frame()
{
bool result;
if (input->isButtonDown(BUTTON_L)) //if left button is down
{
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
}
void ProcessInput()
{
this->mouseX = this->mouseState.lX;
this->mouseY = this->mouseState.lY;
if(this->mouseX < 0)
this->mouseX = 0;
if(this->mouseY < 0)
this->mouseY = 0;
return;
}
--------------------Configuration: dinut - Win32 Debug--------------------
Compiling...
dinut.cpp
C:\projekty\dinut\dinut.cpp(13) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(13) : error C2227: left of '->mouse' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(13) : error C2227: left of '->GetDeviceState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(13) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(13) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(17) : error C2673: 'ReadMouse' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(17) : error C2227: left of '->mouse' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(17) : error C2227: left of '->Acquire' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(26) : error C2065: 'input' : undeclared identifier
C:\projekty\dinut\dinut.cpp(26) : error C2227: left of '->isButtonDown' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(26) : error C2065: 'BUTTON_L' : undeclared identifier
C:\projekty\dinut\dinut.cpp(31) : error C2065: 'ProcessInput' : undeclared identifier
C:\projekty\dinut\dinut.cpp(38) : error C2373: 'ProcessInput' : redefinition; different type modifiers
C:\projekty\dinut\dinut.cpp(39) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(39) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(39) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(39) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(39) : error C2228: left of '.lX' must have class/struct/union type
C:\projekty\dinut\dinut.cpp(40) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(40) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(40) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(40) : error C2227: left of '->mouseState' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(40) : error C2228: left of '.lY' must have class/struct/union type
C:\projekty\dinut\dinut.cpp(42) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(42) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(43) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(43) : error C2227: left of '->mouseX' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(44) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(44) : error C2227: left of '->mouseY' must point to class/struct/union
C:\projekty\dinut\dinut.cpp(45) : error C2673: 'ProcessInput' : global functions do not have 'this' pointers
C:\projekty\dinut\dinut.cpp(45) : error C2227: left of '->mouseY' must point to class/struct/union
Error executing cl.exe.
dinut.exe - 31 error(s), 0 warning(s)
@wilkwielki: Skąd ty ten kod wytrzasnąłeś?
Keyword this
odwołuje się do pointera na instancję danej klasy wewnątrz tej instancji,
twoje funkcje nie są memberami żadnej z klas więc this
nie ma tutaj żadnego sensu
o czym informuje cię kompilator.
Eldorad O. napisał(a):
@wilkwielki: Skąd ty ten kod wytrzasnąłeś?
Keywordthis
odwołuje się do pointera na instancję danej klasy wewnątrz tej instancji,
twoje funkcje nie są memberami żadnej z klas więcthis
nie ma tutaj żadnego sensu
o czym informuje cię kompilator.
szukałem w internecie nie mogę dojść do ładu i składu jak to pozbierać
dodałem również to
DIMOUSESTATE mouseState;
LDIRECTINPUTDEVICE8 mouse;
--------------------Configuration: dinut - Win32 Debug--------------------
Compiling...
dinut.cpp
C:\projekty\dinut\dinut.cpp(10) : error C2146: syntax error : missing ';' before identifier 'mouse'
C:\projekty\dinut\dinut.cpp(10) : error C2501: 'LDIRECTINPUTDEVICE8' : missing storage-class or type specifiers
C:\projekty\dinut\dinut.cpp(10) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
dinut.exe - 3 error(s), 0 warning(s)
@wilkwielki: Wklej cały przykład z którego wklejasz kod,
bo z takich losowych zlepków to nic nie wyczarujemy.
Eldorad O. napisał(a):
@wilkwielki: Wklej cały przykład z którego wklejasz kod,
bo z takich losowych zlepków to nic nie wyczarujemy.
PROSZE CAŁY KOD W ORGINALE
bool System::frame()
{
bool result;
if (input->isButtonDown(BUTTON_L)) //if left button is down
{
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
}
bool System::ReadMouse()
{
HRESULT result;
//this->mouseState is a DIMOUSESTATE ; this->mouse is a LDIRECTINPUTDEVICE8
result = this->mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&this->mouseState);
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
this->mouse->Acquire();
else
return false;
}
return true;
}
void System::ProcessInput()
{
this->mouseX = this->mouseState.lX;
this->mouseY = this->mouseState.lY;
if(this->mouseX < 0)
this->mouseX = 0;
if(this->mouseY < 0)
this->mouseY = 0;
if(this->mouseX > this->ScreenWidth)
this->mouseX = this->ScreenWidth;
if(this->mouseY > this->ScreenHeight)
this->mouseY = this->ScreenHeight;
return;
}
https://stackoverflow.com/questions/18830051/management-inputs-mouse-with-directx-directinput
@wilkwielki: Nie ma header'a ale coś można pokombinować - nie mam za bardzo jak tym kodem
się teraz pobawić, więc mogę najwyżej cię nakierować na rozwiązanie.
Member mouse
to raczej na pewno typ LPDIRECTINPUTDEVICE8
, zgodnie z tym:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416845(v=vs.85)
Tworzy się go tak:
LPDIRECTINPUTDEVICE8 lpdiKeyboard;
lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL);
lpdi
to pointer na interfejs IDirectInput8
:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417799(v=vs.85)
Tworzysz go za pomocą tej funkcji:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416756(v=vs.85)
Czyli powiedzmy ten twój kod by wyglądał mniej więcej tak:
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
LPDIRECTINPUT8 lpdi;
DirectInput8Create(...); // Jednym z parametrów tutaj jest adres do zmiennej lpdi
LPDIRECTINPUTDEVICE8 mouse;
lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL);
DIMOUSESTATE mouseState;
lpdi->SetDataFormat(&c_dfDIMouse); // https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417925(v=vs.85)
LONG mouseX;
LONG mouseY;
bool ReadMouse()
{
HRESULT result;
result = mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState);
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417897(v=vs.85)
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
mouse->Acquire();
else
return false;
}
return true;
}
bool frame()
{
bool result;
if (input->isButtonDown(BUTTON_L)) // Nie mam pojęcia jakim typem jest input
{
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
}
void ProcessInput()
{
mouseX = mouseState.lX;
mouseY = mouseState.lY;
if(mouseX < 0)
mouseX = 0;
if(mouseY < 0)
mouseY = 0;
return;
}
Nigdy nie używałem WinApi więc nie mam pojęcia czy to zadziała, musisz sam pokombinować i poczytać dokumentację dokładniej - linki wstawiłem też w komentarzach.
Eldorad O. napisał(a):
@wilkwielki: Nie ma header'a ale coś można pokombinować - nie mam za bardzo jak tym kodem
się teraz pobawić, więc mogę najwyżej cię nakierować na rozwiązanie.Member
mouse
to raczej na pewno typLPDIRECTINPUTDEVICE8
, zgodnie z tym:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416845(v=vs.85)Tworzy się go tak:
LPDIRECTINPUTDEVICE8 lpdiKeyboard; lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL);
lpdi
to pointer na interfejsIDirectInput8
:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417799(v=vs.85)Tworzysz go za pomocą tej funkcji:
https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416756(v=vs.85)Czyli powiedzmy ten twój kod by wyglądał mniej więcej tak:
#include "stdafx.h" #include <iostream.h> #include <windows.h> #include <dinput.h> LPDIRECTINPUT8 lpdi; DirectInput8Create(...); // Jednym z parametrów tutaj jest adres do zmiennej lpdi LPDIRECTINPUTDEVICE8 mouse; lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL); DIMOUSESTATE mouseState; lpdi->SetDataFormat(&c_dfDIMouse); // https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417925(v=vs.85) LONG mouseX; LONG mouseY; bool ReadMouse() { HRESULT result; result = mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState); // https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417897(v=vs.85) if(FAILED(result)) { if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED)) mouse->Acquire(); else return false; } return true; } bool frame() { bool result; if (input->isButtonDown(BUTTON_L)) // Nie mam pojęcia jakim typem jest input { result = ReadMouse(); if(!result) return false; ProcessInput(); } } void ProcessInput() { mouseX = mouseState.lX; mouseY = mouseState.lY; if(mouseX < 0) mouseX = 0; if(mouseY < 0) mouseY = 0; return; }
Nigdy nie używałem WinApi więc nie mam pojęcia czy to zadziała, musisz sam pokombinować i poczytać dokumentację dokładniej - linki wstawiłem też w komentarzach.
co ja mam wpisać w funkcji DirectInput8Create
@wilkwielki: Wstawiłem link do dokumentacji, tam masz napisane.
Eldorad O. napisał(a):
@wilkwielki: Wstawiłem link do dokumentacji, tam masz napisane.
znalazłem takie coś DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
i jak to przerobić na ten przykład u góry?
@wilkwielki: Nie wiem, tu masz napisane: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416756(v=vs.85)
Nie korzystałem nigdy z WinAPI, wczytaj się w dokumentację.
Chyba coś takiego, poczytaj czym jest ten pierwszy parametr:
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
Eldorad O. napisał(a):
@wilkwielki: Nie wiem, tu masz napisane: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee416756(v=vs.85)
Nie korzystałem nigdy z WinAPI, wczytaj się w dokumentację.
Chyba coś takiego, poczytaj czym jest ten pierwszy parametr:DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
dzięki za pomoc teraz się połapie :)
@wilkwielki: poszukaj jakiegoś gotowego przykładu na start który działa ( Windows-SDK , DirectX-SDK ? )
Marius.Maximus napisał(a):
@wilkwielki: poszukaj jakiegoś gotowego przykładu na start który działa ( Windows-SDK , DirectX-SDK ? )
mam pytanie skąd można pobrać pakiet bibliotek LIBS i plików nagłówkowych INCLUDE najnowszą wersje ponieważ pisze że obsługa jest tylko wersja directx 5.0 u mnie w visualu c++ 6.0 profesional. znalazłem directx sdk z 8.0 ale ciągle są błędy proszę to kod
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
LPDIRECTINPUT8 lpdi;
HINSTANCE hinstance;
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
LPDIRECTINPUTDEVICE8 mouse;
lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL);
DIMOUSESTATE mouseState;
lpdi->SetDataFormat(&c_dfDIMouse); // https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417925(v=vs.85)
LONG mouseX;
LONG mouseY;
bool ReadMouse()
{
HRESULT result;
result = mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState);
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417897(v=vs.85)
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
mouse->Acquire();
else
return false;
}
return true;
}
void ProcessInput()
{
mouseX = mouseState.lX;
mouseY = mouseState.lY;
if(mouseX < 0)
mouseX = 0;
if(mouseY < 0)
mouseY = 0;
return;
}
bool frame()
{
bool result;
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
@wilkwielki: strasznie sobie utrudniasz
- stary kompilator (z poprzedniego wieku 1999)
- directX 8/9
- bierzesz się za temat o którym niewiele wiesz: (DirectInput)
- uzywas kompilatora/IDE którego zupełnie nie znasz
Jeden temat można przeskoczyć (i to jest normalne podejscie) , ale jak WSZYTKO JEST PRZECIW TOBIE
to będzie twarda ściana, oby Twoje samozaparcie bylo wystarczajaco mocne
@wilkwielki: Dlaczego używasz takich staroci?
Eldorad O. napisał(a):
@wilkwielki: Dlaczego używasz takich staroci?
lubię tą wersje ja sprawdzałem też nowsze i nic nadzwyczajnego nie znalazłem a sprawdzałem pod różnymi możliwościami lepszych wersji ja wiem to 1999. juz znalazlemm w dx sdk wersje 8.0 i wkopiowałem do katalogów co się należy to tyle co dalej z tym kodem moze ktos to sprawdzic i pomóc?
@wilkwielki: Skoro znalazłeś odpowiednie pliki to skompiluj i odpal.
Eldorad O. napisał(a):
@wilkwielki: Skoro znalazłeś odpowiednie pliki to skompiluj i odpal.
Eldorad O. napisał(a):
@wilkwielki: Skoro znalazłeś odpowiednie pliki to skompiluj i odpal.
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
LPDIRECTINPUT8 lpdi;
HINSTANCE hinstance;
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
LPDIRECTINPUTDEVICE8 mouse;
lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL);
DIMOUSESTATE mouseState;
lpdi->SetDataFormat(&c_dfDIMouse); // https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417925(v=vs.85)
LONG mouseX;
LONG mouseY;
bool ReadMouse()
{
HRESULT result;
result = mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState);
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417897(v=vs.85)
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
mouse->Acquire();
else
return false;
}
return true;
}
void ProcessInput()
{
mouseX = mouseState.lX;
mouseY = mouseState.lY;
if(mouseX < 0)
mouseX = 0;
if(mouseY < 0)
mouseY = 0;
return;
}
bool frame()
{
bool result;
result = ReadMouse();
if(!result)
return false;
ProcessInput();
}
Compiling...
myszka.cpp
c:\programy\microsoft visual studio\vc98\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
C:\projekty\myszka\myszka.cpp(9) : error C2501: 'DirectInput8Create' : missing storage-class or type specifiers
C:\projekty\myszka\myszka.cpp(9) : error C2373: 'DirectInput8Create' : redefinition; different type modifiers
c:\programy\microsoft visual studio\vc98\include\dinput.h(2685) : see declaration of 'DirectInput8Create'
C:\projekty\myszka\myszka.cpp(9) : error C2078: too many initializers
C:\projekty\myszka\myszka.cpp(12) : error C2143: syntax error : missing ';' before '->'
C:\projekty\myszka\myszka.cpp(12) : error C2501: 'lpdi' : missing storage-class or type specifiers
C:\projekty\myszka\myszka.cpp(12) : error C2040: 'lpdi' : 'int' differs in levels of indirection from 'struct IDirectInput8A *'
C:\projekty\myszka\myszka.cpp(12) : error C2143: syntax error : missing ';' before '->'
C:\projekty\myszka\myszka.cpp(16) : error C2143: syntax error : missing ';' before '->'
C:\projekty\myszka\myszka.cpp(16) : error C2501: 'lpdi' : missing storage-class or type specifiers
C:\projekty\myszka\myszka.cpp(16) : error C2040: 'lpdi' : 'int' differs in levels of indirection from 'struct IDirectInput8A *'
C:\projekty\myszka\myszka.cpp(16) : error C2143: syntax error : missing ';' before '->'
Error executing cl.exe.
myszka.exe - 11 error(s), 0 warning(s)
wilkwielki napisał(a):
Eldorad O. napisał(a):
@wilkwielki: Dlaczego używasz takich staroci?
lubię tą wersje ja sprawdzałem też nowsze i nic nadzwyczajnego nie znalazłem a sprawdzałem pod różnymi możliwościami lepszych wersji ja wiem to 1999. juz znalazlemm w dx sdk wersje 8.0 i wkopiowałem do katalogów co się należy to tyle co dalej z tym kodem moze ktos to sprawdzic i pomóc?
Jakoś tak na tym bożym świecie jest, że najbardziej wyrobione zdanie o kompilatorach mają łebki, które nie potrafią ze zrozumieniem przeczytać komunikatów o błędach w 15 liniowym projekcie
@wilkwielki: Przenieś te calle do maina:
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL);
lpdi->SetDataFormat(&c_dfDIMouse);
Eldorad O. napisał(a):
@wilkwielki: Przenieś te calle do maina:
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL); lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL); lpdi->SetDataFormat(&c_dfDIMouse);
a więc jest tak:
#include "stdafx.h"
#include <iostream.h>
#include <windows.h>
#include <dinput.h>
DIMOUSESTATE mouseState;
LPDIRECTINPUT8 lpdi;
LPDIRECTINPUTDEVICE8 mouse;
HINSTANCE hinstance;
LONG mouseX;
LONG mouseY;
bool ReadMouse()
{
HRESULT result;
result = mouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState);
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ee417897(v=vs.85)
if(FAILED(result))
{
if((result == DIERR_INPUTLOST) || (result == DIERR_NOTACQUIRED))
mouse->Acquire();
else
return false;
}
return true;
}
int main(int argc, char* argv[])
{
DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&lpdi, NULL);
lpdi->CreateDevice(GUID_SysMouse, &mouse, NULL);
lpdi->SetDataFormat(&c_dfDIMouse);
bool done=false;
do
{
ReadMouse();
cout << mouseState.lX << " " << mouseState.lY << endl;
}while(!done);
return 0;
}
a błędy są takie:
--------------------Configuration: myszka - Win32 Debug--------------------
Compiling...
myszka.cpp
c:\programy\microsoft visual studio\vc98\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800
C:\projekty\myszka\myszka.cpp(41) : error C2039: 'SetDataFormat' : is not a member of 'IDirectInput8A'
c:\programy\microsoft visual studio\vc98\include\dinput.h(2625) : see declaration of 'IDirectInput8A'
Error executing cl.exe.
myszka.exe - 1 error(s), 0 warning(s)
a zainstalowałem directx->sdk z LIBS i INCLUDE