TEST(Transformable_objects, have_a_left_and_right_direction_along_the_x_axis) { Transformable t; EXPECT_EQ( Transformable::X_AXIS, t.left()); EXPECT_EQ(-Transformable::X_AXIS, t.right()); }
TEST(Transformable_objects, have_a_up_and_down_direction_along_the_y_axis) { Transformable t; EXPECT_EQ( Transformable::Y_AXIS, t.up()); EXPECT_EQ(-Transformable::Y_AXIS, t.down()); }
TEST(Transformable_objects, have_a_forward_and_backward_direction_along_the_z_axis) { Transformable t; EXPECT_EQ( Transformable::Z_AXIS, t.forward()); EXPECT_EQ(-Transformable::Z_AXIS, t.backward()); }
unsigned long Serialization::unserialize(const std::vector<char> &buf, Transformable &tr_data, unsigned long start_loc) { // delete all existing items tr_data.clear(); unsigned long names_arg_sz; unsigned long n_rec; unsigned long bytes_read; size_t i_start = 0; // get size of names record i_start = start_loc; w_memcpy_s(&names_arg_sz, sizeof(names_arg_sz), buf.data()+i_start, sizeof(names_arg_sz)); i_start += sizeof(names_arg_sz); unique_ptr<char[]> names_buf(new char[names_arg_sz]); w_memcpy_s(names_buf.get(), sizeof(char)*names_arg_sz, buf.data()+i_start, sizeof(char)*names_arg_sz); i_start += sizeof(char)*names_arg_sz; w_memcpy_s(&n_rec, sizeof(n_rec), buf.data()+i_start, sizeof(n_rec)); i_start += sizeof(n_rec); // build transformable data set double *value_ptr = (double *) ( buf.data()+i_start); vector<string> names_vec; tokenize(strip_cp(string(names_buf.get(), names_arg_sz)), names_vec); assert(names_vec.size() == n_rec); for (unsigned long i=0; i< n_rec; ++i) { tr_data.insert(names_vec[i], *(value_ptr+i)); } bytes_read = i_start + n_rec * sizeof(double); return bytes_read; }
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; }
TEST(Transformable_objects, have_a_position_rotation_and_scaling) { Transformable t; EXPECT_EQ(vec3(0,0,0), t.position()); EXPECT_EQ(vec3(1,1,1), t.scaling()); EXPECT_EQ(quat(0,0,0,1), t.rotation()); }
TEST(Transformable_objects, have_a_translation_matrix_to_move_form_model_space_to_world_space) { Transformable model; vec3 pInModelSpace(1,1,1), pInWorldSpace(2,3,4); model.moveTo(1,2,3); EXPECT_EQ(pInWorldSpace, (model.translationMatrix() * vec4(pInModelSpace,1)).xyz()); }
Transformable ServerFont::EmbeddedTransformation() const { // TODO: cache this? Transformable transform; transform.ShearBy(B_ORIGIN, (90.0 - fShear) * M_PI / 180.0, 0.0); transform.RotateBy(B_ORIGIN, -fRotation * M_PI / 180.0); return transform; }
void TranScale::reverse(Transformable &data) { Transformable::iterator data_iter, data_end = data.end(); for (map<string,double>::const_iterator b=items.begin(), e=items.end(); b!=e; ++b) { data_iter = data.find(b->first); if (data_iter != data_end) { (*data_iter).second /= b->second; } } }
TEST(Transformable_objects, have_a_rotation_matrix_to_move_from_model_space_to_world_space__x_axis_only) { Transformable model; vec3 pInModelSpace(2,0,0), pInWorldSpace(2,0,0); vec3 qInModelSpace(0,2,0), qInWorldSpace(0,0,2); vec3 rInModelSpace(0,0,2), rInWorldSpace(0,-2,0); model.rotateTo(Transformable::X_AXIS, toRadian(90)); EXPECT_EQ(pInWorldSpace, (model.rotationMatrix() * vec4(pInModelSpace,1)).xyz()); EXPECT_EQ(qInWorldSpace, (model.rotationMatrix() * vec4(qInModelSpace,1)).xyz()); EXPECT_EQ(rInWorldSpace, (model.rotationMatrix() * vec4(rInModelSpace,1)).xyz()); }
///////////////// TranOffset Methods ///////////////// void TranOffset::forward(Transformable &data) { Transformable::iterator data_iter, data_end = data.end(); for (map<string,double>::const_iterator b=items.begin(), e=items.end(); b!=e; ++b) { data_iter = data.find(b->first); if (data_iter != data_end) { (*data_iter).second += (*b).second; } } }
void TranLog10::reverse(Transformable &data) { Transformable::iterator data_iter, data_end = data.end(); for (set<string>::const_iterator b=items.begin(), e=items.end(); b!=e; ++b) { data_iter = data.find(*b); if (data_iter != data_end) { (*data_iter).second = pow(10.0, (*data_iter).second); } } }
void TranNormalize::d2_to_d1(Transformable &del_data, Transformable &data) { Transformable::iterator del_data_iter, del_data_end = del_data.end(); for (map<string, NormData>::const_iterator b = items.begin(), e = items.end(); b != e; ++b) { del_data_iter = del_data.find(b->first); if (del_data_iter != del_data_end) { (*del_data_iter).second *= b->second.scale; } } reverse(data); }
TEST(Transformable_objects, have_a_scaling_matrix_to_move_from_model_space_to_world_space) { Transformable model; vec3 pInModelSpace(1,1,1), pInWorldSpace(1,2,3); vec3 qInModelSpace(0,0,0), qInWorldSpace(0,0,0); vec3 rInModelSpace(2,2,2), rInWorldSpace(2,4,6); model.scaleTo(1,2,3); EXPECT_EQ(pInWorldSpace, (model.scalingMatrix() * vec4(pInModelSpace,1)).xyz()); EXPECT_EQ(qInWorldSpace, (model.scalingMatrix() * vec4(qInModelSpace,1)).xyz()); EXPECT_EQ(rInWorldSpace, (model.scalingMatrix() * vec4(rInModelSpace,1)).xyz()); }
void TranNormalize::reverse(Transformable &data) { Transformable::iterator data_iter, data_end = data.end(); for (map<string,NormData>::const_iterator b=items.begin(), e=items.end(); b!=e; ++b) { data_iter = data.find(b->first); if (data_iter != data_end) { (*data_iter).second /= b->second.scale; (*data_iter).second -= b->second.offset; } } }
TEST(Transformable_objects, can_be_aligned_with_direction_using_alignWith) { Transformable t; t.moveTo(5,5,5); vec3 direction(1,0,-1); t.alignWith(direction); EXPECT_EQ(normalize(direction), t.forward()); EXPECT_EQ(vec3(5,5,5), t.position()); }
void TranScale::d1_to_d2(Transformable &del_data, Transformable &data) { Transformable::iterator del_data_iter, del_data_end = del_data.end(); for (map<string, double>::const_iterator b = items.begin(), e = items.end(); b != e; ++b) { del_data_iter = del_data.find(b->first); if (del_data_iter != del_data_end) { (*del_data_iter).second /= b->second; } } forward(data); }
// BoundingBox BRect Painter::BoundingBox(const char* utf8String, uint32 length, const BPoint& baseLine) const { Transformable transform; transform.TranslateBy(baseLine); BRect dummy; return fTextRenderer->RenderString(utf8String, length, fFontRendererSolid, fFontRendererBin, transform, dummy, true); }
void VectorPath::ApplyTransform(const Transformable& transform) { if (transform.IsIdentity()) return; for (int32 i = 0; i < fPointCount; i++) { transform.Transform(&(fPath[i].point)); transform.Transform(&(fPath[i].point_out)); transform.Transform(&(fPath[i].point_in)); } _NotifyPathChanged(); }
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); }
void TranLog10::d1_to_d2(Transformable &del_data, Transformable &data) { forward(data); Transformable::iterator del_data_iter, del_data_end = del_data.end(); for (set<string>::const_iterator b = items.begin(), e = items.end(); b != e; ++b) { del_data_iter = del_data.find(*b); if (del_data_iter != del_data_end) { double d1 = data.get_rec(*b); double factor = pow(10.0, d1) * log(10.0); (*del_data_iter).second *= factor; } } }
void TranTied::forward(Transformable &data) { for (map<string, pair_string_double>::iterator ii = items.begin(); ii != items.end(); ++ii) { data.erase(ii->first); } }
///////////////// TranFixed Methods ///////////////// void TranFixed::forward(Transformable &data) { for (map<string,double>::iterator b=items.begin(), e=items.end(); b!=e; ++b) { data.erase(b->first); } }
void TranLog10::d2_to_d1(Transformable &del_data, Transformable &data) { reverse(data); Transformable::iterator del_data_iter, del_data_end = del_data.end(); for (set<string>::const_iterator b = items.begin(), e = items.end(); b != e; ++b) { del_data_iter = del_data.find(*b); if (del_data_iter != del_data_end) { double d2 = data.get_rec(*b); double factor = 1.0 / (d2 * log(10.0)); (*del_data_iter).second *= factor; } } reverse(data); }
void TranFixed::reverse(Transformable &data) { for (map<string,double>::iterator b=items.begin(), e=items.end(); b!=e; ++b) { data.insert(b->first, b->second); } }
void TranTied::reverse(Transformable &data) { string const *base_name; double *factor; Transformable::iterator base_iter; for (map<string, pair_string_double>::iterator b=items.begin(), e=items.end(); b!=e; ++b) { base_name = &(b->second.first); factor = &(b->second.second); base_iter = data.find(*base_name); if (base_iter != data.end()) { data.insert(b->first, (*base_iter).second * (*factor)); } } }
TEST(Transformable_objects, can_be_rotated) { Transformable t; quat rotationX(Transformable::X_AXIS, toRadian(90)); quat rotationY(Transformable::Y_AXIS, toRadian(180)); EXPECT_EQ(quat(0,0,0,1), t.rotation()); t.rotateTo(rotationX); EXPECT_EQ(normalize(rotationX), t.rotation()); t.rotateTo(Transformable::Y_AXIS, toRadian(180)); EXPECT_EQ(normalize(rotationY), t.rotation()); t.rotate(quat(Transformable::X_AXIS, toRadian(90))); EXPECT_EQ(normalize(rotationX * rotationY), t.rotation()); t.rotate(Transformable::X_AXIS, toRadian(-90)); EXPECT_EQ(normalize(rotationY), t.rotation()); }
void TranFixed::d2_to_d1(Transformable &del_data, Transformable &data) { for (map<string, double>::iterator b = items.begin(), e = items.end(); b != e; ++b) { del_data.insert(b->first, 0.0); } reverse(data); }
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); } }
TEST(Transformable_objects, can_be_moved) { Transformable t; EXPECT_EQ(vec3(0,0,0), t.position()); t.moveTo(1,1,1); EXPECT_EQ(vec3(1,1,1), t.position()); t.moveTo(vec3(5,5,5)); EXPECT_EQ(vec3(5,5,5), t.position()); t.move(vec3(-1,-1,-1), 3); EXPECT_EQ(vec3(2,2,2), t.position()); }