本文整理汇总了C++中Mat4::TransformVec3方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat4::TransformVec3方法的具体用法?C++ Mat4::TransformVec3怎么用?C++ Mat4::TransformVec3使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat4
的用法示例。
在下文中一共展示了Mat4::TransformVec3方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetShot
bool GetShot(Shot* shot, Vec3 poi, Vec3 momentum)
{
if(blood_material != NULL)
for (int i = 0; i < 8; ++i)
{
Particle* p = new Particle(corpse->game_state, poi, Random3D::RandomNormalizedVector(Random3D::Rand(5)) + momentum * Random3D::Rand(), NULL, blood_material, Random3D::Rand(0.05f, 0.15f), 0.25f);
p->gravity = 9.8f;
p->damp = 0.05f;
corpse->game_state->Spawn(p);
}
Mat4 xform;
{
xform = rbi->GetTransformationMatrix();
float ori_values[] = {xform[0], xform[1], xform[2], xform[4], xform[5], xform[6], xform[8], xform[9], xform[10]};
Quaternion rigid_body_ori = Quaternion::FromRotationMatrix(Mat3(ori_values).Transpose());
Vec3 pos = xform.TransformVec3(0, 0, 0, 1);
xform = Mat4::FromPositionAndOrientation(pos, rigid_body_ori.ToMat3().Transpose());
}
Vec3 pos = xform.TransformVec3(0, 0, 0, 1);
Vec3 x_axis = xform.TransformVec3(1, 0, 0, 0);
Vec3 y_axis = xform.TransformVec3(0, 1, 0, 0);
Vec3 z_axis = xform.TransformVec3(0, 0, 1, 0);
Vec3 local_poi;
local_poi = poi - pos;
local_poi = Vec3(Vec3::Dot(local_poi, x_axis), Vec3::Dot(local_poi, y_axis), Vec3::Dot(local_poi, z_axis));
local_poi = local_poi.x * x_axis + local_poi.y * y_axis + local_poi.z * z_axis;
rbi->Activate();
rbi->ApplyImpulse(momentum, local_poi);
return true;
}
示例2: Spawned
void Spawned()
{
physics = corpse->game_state->physics_world;
// get bone pos/ori info
vector<Mat4> mats = vector<Mat4>();
unsigned int count = character->skeleton->bones.size();
for(unsigned int i = 0; i < count; ++i)
{
Bone* bone = character->skeleton->bones[i];
bone_offsets.push_back(bone->rest_pos);
mats.push_back(whole_xform * bone->GetTransformationMatrix());
}
UberModel::BonePhysics** bone_physes = new UberModel::BonePhysics* [count];
// create rigid bodies
for(unsigned int i = 0; i < count; ++i)
{
Bone* bone = character->skeleton->bones[i];
Mat4 mat = mats[i];
float ori_values[] = {mat[0], mat[1], mat[2], mat[4], mat[5], mat[6], mat[8], mat[9], mat[10]};
bone->ori = Quaternion::FromRotationMatrix(Mat3(ori_values));
Vec3 bone_pos = mat.TransformVec3(bone_offsets[i], 1);
UberModel::BonePhysics* phys = NULL;
for(unsigned int j = 0; j < model->bone_physics.size(); ++j)
if(Bone::string_table[model->bone_physics[j].bone_name] == bone->name)
phys = &model->bone_physics[j];
bone_physes[i] = phys;
if(phys != NULL)
{
btCollisionShape* shape = phys->shape;
if(shape != NULL)
{
RigidBodyInfo* rigid_body = new RigidBodyInfo(shape, MassInfo::FromCollisionShape(shape, phys->mass), bone_pos, bone->ori);
rigid_body->SetLinearVelocity(initial_vel);
// these constants taken from the ragdoll demo
rigid_body->SetDamping(0.05f, 0.85f);
rigid_body->SetDeactivationTime(0.8f);
rigid_body->SetSleepingThresholds(1.6f, 2.5f);
rigid_body->SetFriction(1.0f);
rigid_body->SetRestitution(0.01f);
physics->AddRigidBody(rigid_body);
rigid_bodies.push_back(rigid_body);
CorpseBoneShootable* shootable = new CorpseBoneShootable(corpse->game_state, corpse, rigid_body, blood_material);
shootables.push_back(shootable);
rigid_body->SetCustomCollisionEnabled(shootable);
bone_indices.push_back(i);
}
}
}
// create constraints between bones
for(unsigned int i = 0; i < rigid_bodies.size(); ++i)
{
unsigned int bone_index = bone_indices[i];
UberModel::BonePhysics* phys = bone_physes[bone_index];
if(phys != NULL)
{
Bone* bone = character->skeleton->bones[bone_index];
Bone* parent = bone->parent;
if(parent != NULL)
{
// find index of parent (bone's index is the same as rigid body info's index)
for(unsigned int j = 0; j < rigid_bodies.size(); ++j)
{
unsigned int j_index = bone_indices[j];
if(character->skeleton->bones[j_index] == parent)
{
if(bone_physes[j_index] != NULL)
{
RigidBodyInfo* my_body = rigid_bodies[i];
RigidBodyInfo* parent_body = rigid_bodies[j];
ConeTwistConstraint* c = new ConeTwistConstraint(my_body, parent_body, Quaternion::Identity(), Vec3(), phys->ori, phys->pos);
c->SetLimit(phys->span);
c->SetDamping(0.1f); // default is 0.01
constraints.push_back(c);
physics->AddConstraint(c, true); // true = prevent them from colliding normally
break;
}
}
}
//.........这里部分代码省略.........