Esempio n. 1
0
void Skeleton::Draw( DebugRenderer& rend )
{
    ColorRGBA color = ColorRGBA::Green;

    for( u32 i = 0; i < m_joint_count; ++i )
    {
        SkeletonJoint& joint = m_joints[i];

        Matrix4x4 bind_pose = joint.GetInvBindPose();
        bind_pose.InverseIt();

        Vec4 pos = bind_pose * Vec4(0.f, 0.f, 0.f, 1.f);
        rend.AddAxis(bind_pose, 0.5f);

        // draw parent-child connection (if applicable).
        if( joint.GetParentIndex() != (u32)-1 && joint.GetParentIndex() < m_joint_count )
        {
            SkeletonJoint& parent = m_joints[joint.GetParentIndex()];

            Matrix4x4 parent_bind_pose = parent.GetInvBindPose();
            parent_bind_pose.InverseIt();

            Vec4 parent_pos = parent_bind_pose * Vec4(0.f, 0.f, 0.f, 1.f);

            rend.AddLine(Vec3(pos.x, pos.y, pos.z), Vec3(parent_pos.x, parent_pos.y, parent_pos.z), color);
        }
    }
}
Esempio n. 2
0
void GameApplication::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
    // If draw debug mode is enabled, draw viewport debug geometry. Disable depth test so that we can see the effect of occlusion
    if (drawDebug_)
	{
        GetSubsystem<Renderer>()->DrawDebugGeometry(false);
	}

	DebugRenderer* debug = scene_->GetComponent<DebugRenderer>();

	//4
	for(int i = 0;i < 5;i ++)
	{
		//横线
		debug->AddLine(Vector3(- 2,0,i - 2),Vector3(2,0,i - 2),Color::YELLOW);
		//竖线
		debug->AddLine(Vector3(i - 2,0,- 2),Vector3(i - 2,0,2),Color::GREEN);
	}
}
Esempio n. 3
0
void GameMain::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
#if 0 // debug waypoints trigger

	DebugRenderer* debug = scene_->GetComponent<DebugRenderer>();
	
	if (world.flyingBot.aiWaypoints_.Size() > 1)
	for(int i=0; i < world.flyingBot.aiWaypoints_.Size()-1; ++i) 
	{
		debug->AddLine(world.flyingBot.aiWaypoints_[i]->GetWorldPosition(),world.flyingBot.aiWaypoints_[i+1]->GetWorldPosition(), Color(1.0f, 1.0f, 0.0f));

	}
	debug->AddLine(world.flyingBot.aiWaypoints_[0]->GetWorldPosition(),world.flyingBot.aiWaypoints_[world.flyingBot.aiWaypoints_.Size()-1]->GetWorldPosition(), Color(1.0f, 1.0f, 0.0f));


	if (world.flyingBot.botSplinePath_ != NULL)
		world.flyingBot.botSplinePath_->DrawDebugGeometry(debug, true);

#endif
}
Esempio n. 4
0
void Navigation::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
    // If draw debug mode is enabled, draw navigation mesh debug geometry
    if (drawDebug_)
        scene_->GetComponent<NavigationMesh>()->DrawDebugGeometry(true);

    if (currentPath_.Size())
    {
        // Visualize the current calculated path
        DebugRenderer* debug = scene_->GetComponent<DebugRenderer>();
        debug->AddBoundingBox(BoundingBox(endPos_ - Vector3(0.1f, 0.1f, 0.1f), endPos_ + Vector3(0.1f, 0.1f, 0.1f)),
            Color(1.0f, 1.0f, 1.0f));

        // Draw the path with a small upward bias so that it does not clip into the surfaces
        Vector3 bias(0.0f, 0.05f, 0.0f);
        debug->AddLine(jackNode_->GetPosition() + bias, currentPath_[0] + bias, Color(1.0f, 1.0f, 1.0f));

        if (currentPath_.Size() > 1)
        {
            for (unsigned i = 0; i < currentPath_.Size() - 1; ++i)
                debug->AddLine(currentPath_[i] + bias, currentPath_[i + 1] + bias, Color(1.0f, 1.0f, 1.0f));
        }
    }
}
Esempio n. 5
0
void Navigation::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
{
    // If draw debug mode is enabled, draw navigation mesh debug geometry
    if (drawDebug_)
        scene_->GetComponent<NavigationMesh>()->DrawDebugGeometry(true);
    
    // Visualize the start and end points and the last calculated path
    DebugRenderer* debug = scene_->GetComponent<DebugRenderer>();
    if (startPosDefined_)
        debug->AddBoundingBox(BoundingBox(startPos_ - 0.1f * Vector3::ONE, startPos_ + 0.1f * Vector3::ONE), Color::WHITE);
    if (endPosDefined_)
        debug->AddBoundingBox(BoundingBox(endPos_ - 0.1f * Vector3::ONE, endPos_ + 0.1f * Vector3::ONE), Color::WHITE);
    if (currentPath_.Size() > 1)
    {
        // Draw the path with a small upward bias so that it does not clip into the surfaces
        Vector3 bias = 0.05f * Vector3::UP;
        for (unsigned i = 0; i < currentPath_.Size() - 1; ++i)
            debug->AddLine(currentPath_[i] + bias, currentPath_[i + 1] + bias, Color::WHITE);
    }
}
void EnemyEntity::UpdateCast()
{
    DebugRenderer* debug = GetScene()->GetComponent<DebugRenderer>();
    PhysicsWorld2D* physicsWorld = GetScene()->GetComponent<PhysicsWorld2D>();
    RigidBody2D* body = GetComponent<RigidBody2D>();

    /*cast ground*/
    Vector2 originpos = node_->GetPosition2D();
    Vector2 FinishC;
    Vector2 FinishD;

    if(!isLeft)
    {
        FinishC = originpos + Vector2(-0.60,-0.35);
        FinishD = originpos + Vector2(-0.60,0);
    }

    else
    {
        FinishC = originpos + Vector2(0.60,-0.35);
        FinishD = originpos + Vector2(0.60,0);
    }


    PhysicsRaycastResult2D RayCastC;
    physicsWorld->RaycastSingle(RayCastC, originpos , FinishC,1);
    if ( !RayCastC.body_ && body->GetLinearVelocity().y_ >= -0.05f)
    {
        SetReturn();
    }

    PhysicsRaycastResult2D RayCastD;
    physicsWorld->RaycastSingle(RayCastD, originpos , FinishD,1);
    if ( RayCastD.body_)
    {
        SetReturn();
    }
    /*end cast ground*/

    /*cast player*/
    if(!isBusy && !isCooldDown)
    {
        Node* target = GetScene()->GetChild("Player",false);
        if(target)
        {
            Vector2 targetpos = target->GetPosition2D();
            Vector2 direction = targetpos - originpos;
            direction.Normalize();
            Vector2 FinishT = originpos + Vector2(direction.x_*2.5f,direction.y_*2.5);
            PhysicsRaycastResult2D RayCastT;
            physicsWorld->RaycastSingle(RayCastT, originpos , FinishT, 4);
            if (RayCastT.body_)
            {
                Node* node = RayCastT.body_->GetNode();
                if(node->GetName() == "Player")
                {
                    if(direction.x_ < 0)
                        setRight();
                    else
                        setLeft();
                    SetAtack();
                }
            }

            debug->AddLine( Vector3(originpos.x_, originpos.y_,0),
                        Vector3(FinishT.x_, FinishT.y_,0),
                        Color(0, 1, 1, 1),
                        false );

        }

    }

    /*end castplayer*/
    debug->AddLine( Vector3(originpos.x_, originpos.y_,0),
                            Vector3(FinishC.x_, FinishC.y_,0),
                            Color(1, 0, 0, 1),
                            false );

    debug->AddLine( Vector3(originpos.x_, originpos.y_,0),
                            Vector3(FinishD.x_, FinishD.y_,0),
                            Color(1, 0, 0, 1),
                            false );

}
Esempio n. 7
0
bool IK::Solve(Vector3 targetPos)
{
	//http://mrl.nyu.edu/~perlin/gdc/ik/ik.java.html

	//Get nodes
	Node* hip = effector_->GetParent()->GetParent();
	Node* knee = effector_->GetParent();

	// Get current world position for the 3 joints of the IK chain
	Vector3 hipPos = hip->GetWorldPosition(); // Thigh pos (hip joint)
	Vector3 kneePos = knee->GetWorldPosition(); // Calf pos (knee joint)
	Vector3 effectorPos = effector_->GetWorldPosition(); // Foot pos (ankle joint)

	// Pre IK Direction vectors
	Vector3 thighDir = kneePos - hipPos; // Thigh direction
	Vector3 calfDir = effectorPos - kneePos; // Calf direction	

	// Vectors lengths
	float A = Vector3(thighDir).Length();//length of hip to knee
	float B = Vector3(calfDir).Length();//length of knee to foot
	Vector3 P = hip->WorldToLocal(targetPos);//target at origin
	Vector3 D = hip->WorldToLocal(kneePos);//pre solve knee at origin
	//float limbLength = length1 + length2;
	//float lengthH = targetDir.Length();

	//PERLINS STUFF
	//bool test = Perlin(A,B,C,D);
	//GetSubsystem<DebugHud>()->SetAppStats("ik:", String(test) );
	//------
	Vector3 R;
	DefineM(P,D);
	R = Rot(Minv,P);
	//FIND D
	float c = R.Length();
    float d = Max(0.0f, Min(A, (c + (A*A-B*B)/c) / 2.0f));//FindD(A,B,R.Length());
    //FIND E
    float e = sqrtf(A*A-d*d);//FindE(A,d);
    Vector3 S = Vector3(d,e,0.0f);
    Vector3 Q = Rot(Mfwd,S);

    //Convert Q back to world space
    Vector3 worldQ = effector_->GetParent()->GetParent()->LocalToWorld(Q);

    //Get angles
    Vector3 tdn = thighDir.Normalized();
    Vector3 ntdn = Vector3(worldQ-hipPos).Normalized();
    Vector3 cdn = calfDir.Normalized();
    Vector3 ncdn = Vector3(targetPos-worldQ).Normalized();

    //Vector3 hipAxis = tdn.CrossProduct(ntdn); 
    //float hipAngle = tdn.Angle(ntdn);
    //Vector3 kneeAxis = cdn.CrossProduct(ncdn);
    //float kneeAngle = cdn.Angle(ncdn);

    //GetSubsystem<DebugHud>()->SetAppStats("ik:", String(hipAngle)+":"+String(kneeAngle) );

    //knee->SetWorldRotation(knee->GetWorldRotation() * Quaternion(kneeAngle,kneeAxis) );
	//hip->SetWorldRotation(hip->GetWorldRotation() * Quaternion(hipAngle,hipAxis) );
	//do top level first, then get new angle for lower level, since it might mangle it
	bool success = d > 0.0f && d < A;

	if(success)
	{
		Quaternion hipRot = Quaternion(tdn,ntdn);
		hip->Rotate(hipRot,TS_WORLD );
		knee->Rotate(Quaternion(cdn,ncdn)*hipRot.Inverse(),TS_WORLD );
	}

    if(drawDebug_)
    {
	    DebugRenderer* dbg = effector_->GetScene()->GetComponent<DebugRenderer>();
	    
	    /*dbg->AddLine(hipPos,hipPos+tdn,Color(0.0f,1.0f,0.0f),false);
    	dbg->AddLine(hipPos,hipPos+ntdn,Color(0.0f,0.0f,1.0f),false);
	    dbg->AddLine(kneePos,kneePos+cdn,Color(0.0f,1.0f,0.0f),false);
    	dbg->AddLine(kneePos,kneePos+ncdn,Color(0.0f,0.0f,1.0f),false);

    	dbg->AddSphere(Sphere(effectorPos,0.2f),Color(0.0f,1.0f,0.0f),false);
    	dbg->AddSphere(Sphere(targetPos,0.2f),Color(0.0f,0.0f,1.0f),false);*/
	    //at origin
	    /*dbg->AddSphere(Sphere(Vector3(),0.2f),Color(0.0f,0.0f,0.0f),false);//origin
	    dbg->AddSphere(Sphere(D,0.2f),Color(0.1f,0.0f,0.0f),false);//old elbow
	    dbg->AddSphere(Sphere(P,0.2f),Color(0.0f,1.0f,0.0f),false);//target
	    dbg->AddLine(Vector3(),P,Color(0.1f,0.1f,0.1f),false);

	    //show solve at origin
	    dbg->AddSphere(Sphere(Q,0.2f),Color(1.0f,0.0f,0.0f),false);
		dbg->AddLine(Vector3(),Q,Color(1.0f,0.0f,0.0f),false);
		dbg->AddLine(Q,P,Color(1.0f,0.0f,0.0f),false);*/

		//show solve at position
		dbg->AddSphere(Sphere(worldQ,0.2f),Color(1.0f,0.0f,0.0f),false);
		dbg->AddSphere(Sphere(targetPos,0.2f),Color(0.0f,1.0f,0.0f),false);
		dbg->AddLine(hipPos,worldQ,Color(1.0f,0.0f,0.0f),false);
		dbg->AddLine(worldQ,targetPos,Color(1.0f,0.0f,0.0f),false);
	}

    return success;

	
}