Input.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
 
class Input : public Singleton<Input>
{
    friend class Window;
 
private:
    ...
 
    Vector2       mouseScreenPos;  //추가
    Vector2       mouseWorldPos;   //추가
  
public:
    Input();
    ~Input();
 
    bool KeyDown(int KeyCode); //눌렀을때 최초1회
    bool KeyPress(int KeyCode);//누르고있을때
    bool KeyUp(int KeyCode); //눌렀다가 떼었을때 최초1회
    void Update();
 
    Vector2 GetScreenMousPos() { return mouseScreenPos; } //추가
    Vector2 GetWorldMousPos() { return mouseWorldPos; }   //추가
};
cs

Vector2       mouseScreenPos;  
Vector2       mouseWorldPos;   

 

Vector2 GetScreenMousPos() { return mouseScreenPos; }
Vector2 GetWorldMousPos() { return mouseWorldPos; } 

 

 

 

Input.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "framework.h"
 
Input::Input() { ... }
 
Input::~Input() { ... }
 
bool Input::KeyDown(int KeyCode) 
{
    return keyMap[KeyCode] == KEY_INPUT_STATUS_DOWN;
}
 
bool Input::KeyPress(int KeyCode)
{
    return keyMap[KeyCode] <= KEY_INPUT_STATUS_PRESS;
}
 
bool Input::KeyUp(int KeyCode)
{
    return keyMap[KeyCode] == KEY_INPUT_STATUS_UP;
}
 
void Input::Update()
{
    // Screen to World
    mouseWorldPos.x =- app.GetHalfWidth() + mouseScreenPos.x;  //추가
    mouseWorldPos.y = app.GetHalfHeight() - mouseScreenPos.y;  //추가
    //mouseWorldPos.y = app.GetHeight() - mouseScreenPos.y - app.GetHalfHeight();
 
    ...
}
cs

Screen to World 좌표 변화 공식
mouseWorldPos.x =- app.GetHalfWidth() + mouseScreenPos.x; 
mouseWorldPos.y = app.GetHeight() - mouseScreenPos.y - app.GetHalfHeight();

 

 

 

 

Main.h - 변화 없음

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#pragma once
#define MAX 25
 
class Main : public Scene
{
private:
    ObRect        player;
    ObCircle    pet;
 
    ObRect        playerGauge;
    Bullet        bullet[MAX];
    Vector2        lastPos;
 
    GameObject    firePos;
 
public:
    virtual void Init() override;
    virtual void Release() override; //해제
    virtual void Update() override;
    virtual void LateUpdate() override;//갱신
    virtual void Render() override;
    virtual void ResizeScreen() override;
};
 
cs

 

 

Main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "stdafx.h"
#include "Main.h"
 
void Main::Init() { ... }
 
void Main::Release() { }
 
void Main::Update()
{
    cout << "Mouse : " << INPUT->GetWorldMousPos().x << "," 
        << INPUT->GetWorldMousPos().y << endl;  // MouseWorld 좌표 확인용
 
    Vector2 dir = INPUT->GetWorldMousPos() - player.GetWorldPos(); //추가
    player.rotation = Utility::DirToRadian(dir);                   //추가
 
    ...
    
    if (INPUT->KeyDown(VK_LBUTTON))  //마우스 좌클릭으로 수정
    {
        playerGauge.scale.x = 0.0f;
    }
 
    if (INPUT->KeyPress(VK_LBUTTON)) //마우스 좌클릭으로 수정
    {
        playerGauge.scale.x += 100.0f * DELTA;
 
        if (playerGauge.scale.x > 150.0f)
        {
            playerGauge.scale.x = 0.0f;
        }
    }
 
    if (INPUT->KeyUp(VK_LBUTTON)) //마우스 좌클릭으로 수정
    {
        for (int i = 0; i < MAX; i++)
        {
            if (bullet[i].Shoot(player, playerGauge.scale.x, firePos.GetWorldPos()))
            {
                break;
            }
        }
    }
 
    ...
}
 
void Main::LateUpdate() { ... }
 
void Main::Render() { ... }
 
void Main::ResizeScreen() { }
 
int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR param, int command)
{
  ...
}
cs

Vector2 dir = INPUT->GetWorldMousPos() - player.GetWorldPos(); 
player.rotation = Utility::DirToRadian(dir);            

 

 

 

 

 

 

 


 

충돌 후 

벡터 y좌표가

+ -> -

- -> +

 

 

'⭐ DirectX > DirectX11 2D + WinAPI' 카테고리의 다른 글

[WinAPI] 포물선 충돌 및 마찰계수 설정  (0) 2022.08.11
[WinAPI] 충돌  (0) 2022.08.10
[WinAPI] 총알 발사  (0) 2022.08.08
[WinAPI] Bullet 속도를 Gauge Bar와 연동  (0) 2022.07.29
[winAPI] 시계 만들기  (0) 2022.07.22