Some questions

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Some questions

Postby supermael » Thu Jun 10, 2010 9:28 am

Hello,
I'm French so excuse me for my bad English. I'm creating an RPG game, and so I've some questions.

First, I control a character, the collisions are good, but I've a problem. I don't want this character to rotate on X and Y axis, because he has to stay on his feet, and not on his head... I hope you understand :D I discovered the existence of joins, but I don't know at all how to proceed.

Second question : I want to be able to scale objects in physic world. I know I have to use ConvexHullModifier, but like before, I don't know how to do. I test this code, but it don't works :

Code: Select all
void CPhysConvex::SetScale(CVector3f& vScale)
{
    CMatrix4f temp_matrix;
    NewtonConvexHullModifierGetMatrix(NewtonBodyGetCollision(m_pBody), &temp_matrix.matrix[0]);
    temp_matrix.scale(vScale);

    NewtonConvexHullModifierSetMatrix(NewtonBodyGetCollision(m_pBody), &temp_matrix.matrix[0]);*/
}


I have searched on the web, and on the french sites, but I didn't find something to help me.


I hope you have understood what I meant, it'es not easy for me to talk in english.

Thank you in advance,
Supermael.
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Thu Jun 10, 2010 10:30 am

you need to use the player controller, Read the wikki tutorials, so that you get an idea how to get setup things.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Some questions

Postby supermael » Thu Jun 10, 2010 10:38 am

Thank you ! Now, i understand how to keep my character upright.
The first question is resolved.

What about the scaling ?

Thanks for your helping.
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby supermael » Fri Jun 11, 2010 9:14 am

I have another question about the PlayerController. I need a class for my game, so I've tried to adapt the structure of the tutorial. But when I call the function NewtonUpdate(world, 1/60), the application stops.
My class is :

Code: Select all
CPhysCharacter::CPhysCharacter() : CPhysic()
{

}

CPhysCharacter::~CPhysCharacter()
{
    delete m_playerController;
}

void CPhysCharacter::Update()
{
   float mag2 = velocity * velocity + strafeVeloc * strafeVeloc;
    if (mag2 > PLAYER_SPEED * PLAYER_SPEED)
    {
        mag2 = PLAYER_SPEED * sqrt(1.0f / mag2);
        velocity *= mag2;
        strafeVeloc *= mag2;
    }

    CustomPlayerControllerSetVelocity (m_playerController, velocity, strafeVeloc, headinAngle);

    velocity = strafeVeloc = 0;
}

void CPhysCharacter::CreateObject(NewtonWorld * nWorld, const char* fileName)
{
    SCharacter params; //Load params from a file to create the body
    CMatrix4f mat, mat_controller, mat_body;
    mat.setIdentity();
    mat_controller.setIdentity();
    mat_body.setIdentity();
    NewtonCollision * nCollision = NULL;

    CCharacterParser* parser = new CCharacterParser();
    parser->loadFile(fileName); // Load the file
    params = parser->getParams(); // Load the params

    nCollision = NewtonCreateCapsule(nWorld, params.high, params.radius, 0, &mat.matrix[0]);

    m_pBody = NewtonCreateBody (nWorld, nCollision);

    NewtonReleaseCollision (nWorld, nCollision);

    NewtonBodySetMatrix (m_pBody, &mat_body.matrix[0]);

    NewtonBodySetAutoSleep (m_pBody, 0);

    float maxStairStepFactor = PLAYER_MAX_STEP / params.high;
    m_playerController = CreateCustomPlayerController (&mat_controller.matrix[0], m_pBody, maxStairStepFactor, 1/64.0f);

    CustomPlayerControllerSetMaxSlope (m_playerController, PLAYER_MAX_SLOPE * TORADIAN);
}


The other functions of the class aren't important (Move, strafe...).
I don't understand what's the problem.

Can you help me ?
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby supermael » Fri Jun 11, 2010 1:24 pm

I found my mistake, it was in another part of the code. But I still have a problem, my player doesn't move.
I call my function Update, but the function CustomPlayerControllerSetVelocity (m_playerController, velocity, strafeVeloc, headinAngle);
seems to do nothing.

Someone has a solution ?
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Fri Jun 11, 2010 1:30 pm

what is maxStairStepFactor?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Some questions

Postby supermael » Fri Jun 11, 2010 1:34 pm

I saw it in the tutorial, there :
Code: Select all
 // the player can take step up to 0.7 units;
      dFloat maxStairStepFactor = 0.7f / playerHigh;
      playerController = CreateCustomPlayerController (&orientation[0][0], playerBody, maxStairStepFactor, padding);
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Fri Jun 11, 2010 1:48 pm

the maxplayerhigh cannot be bigger than the capsule high,
did you implement debug display?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Some questions

Postby supermael » Fri Jun 11, 2010 2:01 pm

With debug display, you mean show all faces of my physics body ? If is that, i did.
Params.high = 1.5 and play_max_step = 0.7 so maxStairStepFactor < capsule hight
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Fri Jun 11, 2010 2:02 pm

so how does the shape looks?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Some questions

Postby supermael » Fri Jun 11, 2010 2:13 pm

It looks good, collisions are good. I've just a little problem with my capsule, which is like a sphere :
Image
High = 2 Radius = 1
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby supermael » Fri Jun 11, 2010 2:24 pm

I think I found the problem. The upVector I use is Z axis, whereas the upVector here is Y axis. How can I change that ?
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Fri Jun 11, 2010 2:42 pm

in the CreateCustomPlayerController teh matrix define the local cordenate system of teh player.

the first row is the up direction of the player (0, 0, 1) for you
the secund row is the front (0, 1, 0) maybe for you
the third in crossproduct (front, up)
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Some questions

Postby supermael » Fri Jun 11, 2010 4:14 pm

Thanks so much, it works :)

And last question, to draw my entity, I use the matrix from the function CustomPlayerControllerGetVisualMaTrix(const NewtonUserJoint* playerController, dFloat* matrix) ?
supermael
 
Posts: 10
Joined: Thu Jun 10, 2010 9:02 am

Re: Some questions

Postby Julio Jerez » Fri Jun 11, 2010 4:58 pm

GetVisualMatrix is for when you want to snap the visual shape to the floor after each step,
you can just use the Matrix in the transform callback which is the matrix of the body.
Just experiment with it and use whichever feels better to you.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Next

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron