-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
114 lines (94 loc) · 3.87 KB
/
main.cpp
File metadata and controls
114 lines (94 loc) · 3.87 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <SFML/Graphics.hpp>
#include "Skeleton2D.h"
#include "JSONSkeletonReader.h"
int main()
{
sf::RenderWindow window;
sf::VideoMode mode(800, 800);
window.create(mode, "test");
sf::View currView;
currView.setCenter(0.0f, 0.0f);
window.setView(currView);
Skeleton2D skeletonJ = JSONSkeletonReader::readFromFile("example3.json");
int selector = 2;
std::string sstring = "root";
std::string animationString = "walk";
sf::Clock clock;
clock.restart();
float time = 0.01f;
bool paused = false;
skeletonJ.setAnimation(animationString, AnimationSet::TransitionType::Immediate);
//skeletonJ.setScale({-1.0f, 1.0f});
skeletonJ.getBoneData("ofidsoifj");
while(window.isOpen())
{
sf::Event currEvent;
while(window.pollEvent(currEvent))
{
switch(currEvent.type)
{
case(sf::Event::Closed):
window.close();
break;
case(sf::Event::KeyPressed) :
{
if(currEvent.key.code == sf::Keyboard::L)
{
//time += 0.001f;
skeletonJ.animate(time);
std::cout << "time: " << time << "\n\n";
}
else if(currEvent.key.code == sf::Keyboard::K)
{
//time -= 0.001f;
skeletonJ.animate(time);
std::cout << "time: " << time << "\n\n";
}
else if(currEvent.key.code == sf::Keyboard::Space)
{
paused = !paused;
}
else if(currEvent.key.code == sf::Keyboard::R)
{
if(animationString == "walk") animationString = "jump";
else if(animationString == "jump") animationString = "walk";
skeletonJ.setAnimation(animationString, AnimationSet::TransitionType::Immediate);
}
}
default:
break;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num0)) selector = 0;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)) selector = 1;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num2)) selector = 2;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num3)) selector = 3;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Num9)) selector = -1;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::F)) sstring = "root";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) sstring = "left limb";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::U)) sstring = "right limb";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::T)) sstring = "torso";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::H)) sstring = "hip";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::N)) sstring = "board-ik";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::G)) sstring = "neck";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::T)) sstring = "torso";
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Comma))
{
skeletonJ.setRotation(1.0f, sstring, Skeleton2DBone::RelativeTo::Current);
}
sf::sleep(sf::milliseconds(16));
if(!paused)
{
//skeletonJ.animate(time);
//skeletonJ.setTarget({-200.0f + fmod(150.0f*time, 400.0f), 0.0f}, "root", 0);
}
if(sf::Mouse::isButtonPressed(sf::Mouse::Middle))
{
skeletonJ.externalSetTarget(window.mapPixelToCoords(sf::Mouse::getPosition(window)),
sstring, selector,false, true, Skeleton2DBone::RelativeTo::Orthogonal);
}
window.clear(sf::Color::Black);
skeletonJ.draw(window);
window.display();
}
}