Exemple #1
0
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());
}
Exemple #2
0
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());
}
Exemple #3
0
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());
}
Exemple #4
0
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;
}
Exemple #6
0
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());
}
Exemple #7
0
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());
}
Exemple #8
0
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;
}
Exemple #9
0
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;
		}
	}
}
Exemple #10
0
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());
}
Exemple #11
0
///////////////// 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;
		}
	}
}
Exemple #12
0
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);
		}
	}
}
Exemple #13
0
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);
}
Exemple #14
0
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());
}
Exemple #15
0
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;
		}
	}
}
Exemple #16
0
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());
}
Exemple #17
0
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);
}
Exemple #18
0
// 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);
}
Exemple #19
0
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);
}
Exemple #21
0
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;
		}
	}
}
Exemple #22
0
void TranTied::forward(Transformable &data)
{
	for (map<string, pair_string_double>::iterator ii = items.begin(); ii != items.end(); ++ii)
	{
		data.erase(ii->first);
	}
}
Exemple #23
0
///////////////// 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);
	}
}
Exemple #24
0
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);
}
Exemple #25
0
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);
	}
}
Exemple #26
0
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));
		}
	}
}
Exemple #27
0
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());
}
Exemple #28
0
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);
	}
}
Exemple #30
0
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());
}