本文整理汇总了C++中Transformable::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Transformable::getPosition方法的具体用法?C++ Transformable::getPosition怎么用?C++ Transformable::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transformable
的用法示例。
在下文中一共展示了Transformable::getPosition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cast
CollisionEvent CollisionGrid::cast(const ray& r, CollisionObject* ignore) {
CollisionEvent e;
e.intersected = false;
std::list<vec2> grid_list;
rayGridIntersections(r, grid_list);
for(std::list<vec2>::iterator g = grid_list.begin(); g != grid_list.end(); g++) {
int len = grid_list.size();
int x = (*g)[0];
int y = (*g)[1];
if(x < 0) continue;
if(x >= size_x) continue;
if(y < 0) continue;
if(y >= size_y) continue;
std::list<CollisionObject*>& lst = grid[x+y*size_x];
for(std::list<CollisionObject*>::iterator obj = lst.begin(); obj != lst.end(); obj++) {
if(ignore == (*obj)) continue;
Transformable* t = (Transformable*)((*obj)->script)->getLink(LINK_TRANSFORMABLE);
vec3 p = t->getPosition();
float radius = (*obj)->radius;
vec2 closestP;
float distance;
if(!rayCircleIntersection(r, vec2(p[0], p[2]), radius, closestP, distance)) {
continue;
} else {
e.distance = distance;
e.intersected = true;
e.obj_script = (*obj)->script;
e.obj_type = (*obj)->type;
return e;
}
}
}
return e;
}
示例2: range_closest
CollisionEvent CollisionGrid::range_closest(const vec2& i, const float& range) {
CollisionEvent e;
e.intersected = false;
float closest_dist_sq = 999999999.f;
CollisionObject* closest_object = 0;
int start_x = i[0]-range;
if(start_x < 0) start_x = 0;
int start_y = i[1]-range;
if(start_y < 0) start_y = 0;
int end_x = i[0]+range;
if(end_x >= size_x) end_x = size_x-1;
int end_y = i[0]+range;
if(end_y >= size_y) end_y = size_y-1;
float range_sq = range*range;
for(int x=start_x; x<end_x; x++) {
for(int y=start_y; y<end_y; y++) {
std::list<CollisionObject*>& lst = grid[x+y*size_x];
for(std::list<CollisionObject*>::iterator obj = lst.begin(); obj != lst.end(); obj++) {
Transformable* t = (Transformable*)((*obj)->script->getLink(LINK_TRANSFORMABLE));
vec2 p(t->getPosition()[0], t->getPosition()[2]);
float radius = (*obj)->radius;
float distance_sq = (p - i).length2();
if(distance_sq <= range_sq && distance_sq < closest_dist_sq && !((*obj)->script->destroyOnNextFrame)) {
closest_dist_sq = distance_sq;
closest_object = (*obj);
}
}
}
}
if(closest_object != 0) {
e.intersected = true;
e.distance = sqrt(closest_dist_sq);
e.obj_script = closest_object->script;
e.obj_type = closest_object->type;
}
return e;
}
示例3: add
void CollisionGrid::add(Script* script, int type, float radius) {
Transformable* t = (Transformable*)script->getLink(LINK_TRANSFORMABLE);
if(!t) return;
vec3 pos = t->getPosition();
int x = pos[0], y = pos[2];
CollisionObject* obj = new CollisionObject;
obj->script = script;
obj->type = type;
obj->radius = radius;
objects.push_back(obj);
script->setCollisionObject(obj);
update(0.f);
}
示例4: sqrt
std::list<CollisionEvent> CollisionGrid::range_all(const vec2& i, const float& range) {
std::list<CollisionEvent> events;
int start_x = i[0]-(range);
if(start_x < 0) start_x = 0;
int start_y = i[1]-(range);
if(start_y < 0) start_y = 0;
int end_x = i[0]+(range);
if(end_x >= size_x) end_x = size_x-1;
int end_y = i[0]+(range);
if(end_y >= size_y) end_y = size_y-1;
float range_sq = range*range;
for(int x=start_x; x<end_x; x++) {
for(int y=start_y; y<end_y; y++) {
std::list<CollisionObject*>& lst = grid[x+y*size_x];
for(std::list<CollisionObject*>::iterator obj = lst.begin(); obj != lst.end(); obj++) {
Transformable* t = (Transformable*)((*obj)->script->getLink(LINK_TRANSFORMABLE));
vec2 p = vec2(t->getPosition()[0], t->getPosition()[2]);
float radius = (*obj)->radius;
float distance_sq = (p - i).length2();
if(distance_sq <= range_sq && !((*obj)->script->destroyOnNextFrame)) {
CollisionEvent e;
e.intersected = true;
e.distance = sqrt(distance_sq);
e.obj_script = (*obj)->script;
e.obj_type = (*obj)->type;
events.push_back(e);
}
}
}
}
return events;
}
示例5: update
void CollisionGrid::update(float frameDelta) {
//if(!grid) return;
for(boost::unordered_map<int, std::list<CollisionObject*> >::iterator lst = grid.begin(); lst != grid.end(); lst++) {
lst->second.clear();
}
// memset(walk_grid, 0, sizeof(bool)*size_x*size_y);
for(std::list<CollisionObject*>::iterator obj = objects.begin(); obj != objects.end(); obj++) {
Transformable* t = (Transformable*)((*obj)->script->getLink(LINK_TRANSFORMABLE));
vec3 p = t->getPosition();
float r = (*obj)->radius;
int x = p[0], y = p[2];
walk_grid[x+y*size_x] = 1;
grid[x+y*size_x].push_back(*obj);
}
}
示例6: setPosition
Transformable::Transformable(const Transformable& other)
{
// We can only copy the layouts when they are strings
Layout2d position = {other.getPosition()};
Layout2d size = {other.getSize()};
if (other.m_position.x.getImpl()->operation == LayoutImpl::Operation::String)
position.x = other.m_position.x.getImpl()->stringExpression;
if (other.m_position.y.getImpl()->operation == LayoutImpl::Operation::String)
position.y = other.m_position.y.getImpl()->stringExpression;
if (other.m_size.x.getImpl()->operation == LayoutImpl::Operation::String)
size.x = other.m_size.x.getImpl()->stringExpression;
if (other.m_size.y.getImpl()->operation == LayoutImpl::Operation::String)
size.y = other.m_size.y.getImpl()->stringExpression;
setPosition(position);
setSize(size);
}