-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnbqgeditrigidbody.cpp
62 lines (57 loc) · 1.57 KB
/
nbqgeditrigidbody.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
57
58
59
60
61
62
#include "nbqgeditrigidbody.h"
#include "obj/nbbody.h"
NBQGEditRigidBody::NBQGEditRigidBody()
{
selArr.push_back(false);
selRotArr.push_back(false);
}
void NBQGEditRigidBody::click(float x, float y)
{
b2BodyDef* def = &((NBBody*)(obj))->def;
float size = widget->getWorldPixelSize();
if(def){
if(widget->CheckPointSelect(QPointF(def->position.x,def->position.y),QPointF(x,y))){
selArr[0] = true;
return;
}
b2Vec2 v = B2Physx::angle2Vec(def->angle,size*5);
if(widget->CheckPointSelect(QPointF(def->position.x+v.x,def->position.y+v.y),QPointF(x,y))){
selRotArr[0] = true;
return;
}
}
}
void NBQGEditRigidBody::move(float x, float y)
{
b2BodyDef* def = &((NBBody*)(obj))->def;
if(def){
if(selArr[0]){
def->position.x = x;
def->position.y = y;
widget->update();
}
if(selRotArr[0]){
b2Vec2 v = b2Vec2(x,y) - def->position;
def->angle = B2Physx::vec2Angle(v);
widget->update();
}
}
}
void NBQGEditRigidBody::draw()
{
widget->glColor4f(1,1,0,1);
b2BodyDef* def = &((NBBody*)(obj))->def;
float x = def->position.x;
float y = def->position.y;
float size = widget->getWorldPixelSize();
widget->drawRect(x,y,size,size);
b2Vec2 v = B2Physx::angle2Vec(def->angle,size*5);
widget->drawCircle(x+v.x,y+v.y,size,GL_LINE_LOOP);
}
void NBQGEditRigidBody::rel()
{
NBQGEdit::rel();
for(int i = 0;i<selRotArr.size();i++){
selRotArr[i] = false;
}
}