About Store Forum Documentation Contact



Post Reply 
problem with the mesh and the actors
Author Message
Babulesnik Offline
Member

Post: #1
problem with the mesh and the actors
If I start to go forward turret slides back.Drawing mesh turret is not in sync with a mesh body when there are changes in the matrix of the actor. use two actors, body and turret. After the destruction of the turret to fly off with special effects)

Code:
#include "stdafx.h"
#include "MainBRDM.h"

void StructBRDM::create()
{
    body      .load( "models/Brdm/BRDM/body.mesh"   );
    turret    .load( "models/Brdm/BRDM/turret.mesh" );
    physbody  .load( "models/Brdm/BRDM/body.phys"   );
    physturret.load( "models/Brdm/BRDM/turret.phys" );

    
    // create car
    actor_car.create(physbody).pos(Vec(0,2,0));
    actor_car.massCenterL(actor_car.massCenterL()-Vec(0,0.8f,0)); // lower mass center

    // create car wheels
    wp.radius=0.50 ;

    wheel[0].create(actor_car, Matrix().setPos(Vec( 0.9, 1.35f,  1.38f)), wp); // left -front
    wheel[1].create(actor_car, Matrix().setPos(Vec(-0.9, 1.35f,  1.38f)), wp); // right-front
    wheel[2].create(actor_car, Matrix().setPos(Vec( 0.9, 1.35f, -1.70f)), wp); // left -rear
    wheel[3].create(actor_car, Matrix().setPos(Vec(-0.9, 1.35f, -1.70f)), wp); // right-rear


    actor_turret.create(physturret);
    actor_turret.sleep(true);
    actor_car.ignore(actor_turret);
}

void StructBRDM::setPos(Vec pos)
{

}

void StructBRDM::update()
{
    actor_turret.matrix((actor_car.matrix()+Vec( 0.0f, 0.9f,-0.2f )));

    if(Kb.bp(KB_ENTER))actor_car.pos(Vec(0,3,0)); // reset car position on ENTER key
    
    // adjust car controls
    {
        AdjustValTime(angle, (Kb.b(KB_D)-Kb.b(KB_A))*PI_4, 0.01f); // adjust wheel angle

        Flt accel = (Kb.b(KB_W)-Kb.b(KB_S))*1600, // acceleration
            brake =  Kb.b(KB_SPACE)        *3200; // brakes

        wheel[0].angle(angle).accel(accel).brake(brake); // set angle, acceleration and brakes to left -front wheel
        wheel[1].angle(angle).accel(accel).brake(brake); // set angle, acceleration and brakes to right-front wheel
    }
}
void StructBRDM::draw()
{
    body  .draw(actor_car   .matrix());
    turret.draw(actor_turret.matrix());

    actor_car.massCenterW().draw(RED); // draw mass center
}


Attached File(s) Image(s)
   
11-17-2011 06:34 PM
Find all posts by this user Quote this message in a reply
Mardok Offline
Member

Post: #2
RE: problem with the mesh and the actors
Here is a problem:

void StructBRDM::update()
{
actor_turret.matrix((actor_car.matrix()+Vec( 0.0f, 0.9f,-0.2f )));
}


1. Temporary load your body.mesh and turret.mesh in to model editor and move turret in correct position over body. Next...
2. Load your turret.phys
3. Set your turret phys shape in the same position as turret mesh part (this will be your vector which you are setting here: +Vec( 0.0f, 0.9f,-0.2f ) ) and save changes in turret.phys file.
4. Change your code:
actor_turret.matrix( (actor_car.matrix() );
(This post was last modified: 11-17-2011 07:24 PM by Mardok.)
11-17-2011 07:20 PM
Find all posts by this user Quote this message in a reply
Babulesnik Offline
Member

Post: #3
RE: problem with the mesh and the actors
(11-17-2011 07:20 PM)Mardok Wrote:  Here is a problem:

void StructBRDM::update()
{
actor_turret.matrix((actor_car.matrix()+Vec( 0.0f, 0.9f,-0.2f )));
}


1. Temporary load your body.mesh and turret.mesh in to model editor and move turret in correct position over body. Next...
2. Load your turret.phys
3. Set your turret phys shape in the same position as turret mesh part (this will be your vector which you are setting here: +Vec( 0.0f, 0.9f,-0.2f ) ) and save changes in turret.phys file.
4. Change your code:
actor_turret.matrix( (actor_car.matrix() );

Thank you very much for the detailed response! now it works)

But now another problem.With the rotation of the turret.
If I click "KB_LEFT" turret rotates but its center is shifted(
   
Code:
void StructBRDM::update()
{
    actor_turret.matrix((actor_car.matrix()));
    
    // rotate turret
    if(Kb.b(KB_LEFT)){actor_turret.matrix(actor_turret.matrix().rotateY(5));}

...
Also, if going forward and press the button "KB_LEFT" turret detached
   
11-17-2011 10:35 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Member

Post: #4
RE: problem with the mesh and the actors
You sure that the turret itself is located at (0,0,0) position in the model editor?

SnowCloud Entertainment - We are recruiting!
http://www.sc-entertainment.com
11-18-2011 07:03 AM
Find all posts by this user Quote this message in a reply
Mardok Offline
Member

Post: #5
RE: problem with the mesh and the actors
(11-18-2011 07:03 AM)Dwight Wrote:  You sure that the turret itself is located at (0,0,0) position in the model editor?
Read my post.



Babulesnik:

load your turret.skel and turret.phys and set bone in center of turret phys shape... next save turret.skel

for the future: you should create your model in single file with separate mesh parts

btw. check tutorials->animation there is super example with tank similar to your...

" Separate parts rendering.cpp" or something that
(This post was last modified: 11-18-2011 07:58 AM by Mardok.)
11-18-2011 07:29 AM
Find all posts by this user Quote this message in a reply
Babulesnik Offline
Member

Post: #6
RE: problem with the mesh and the actors
(11-18-2011 07:29 AM)Mardok Wrote:  
(11-18-2011 07:03 AM)Dwight Wrote:  You sure that the turret itself is located at (0,0,0) position in the model editor?
Read my post.



Babulesnik:

load your turret.skel and turret.phys and set bone in center of turret phys shape... next save turret.skel

for the future: you should create your model in single file with separate mesh parts

btw. check tutorials->animation there is super example with tank similar to your...

" Separate parts rendering.cpp" or something that

"Separate parts rendering" really super example )

Thank you very much Mardok !!! you helped me very much)
11-18-2011 09:49 AM
Find all posts by this user Quote this message in a reply
Babulesnik Offline
Member

Post: #7
RE: problem with the mesh and the actors
Now everything is working well. But the problem with the wheels, the center is shifted
   
Code:
void StructBRDM::draw()
{
    mesh->hideAll().show("hull"  ).draw(actor_hull.matrix());
    mesh->hideAll().show("gun"   ).draw(cskel.getBone("gun"   ).matrix());
    mesh->hideAll().show("turret").draw(cskel.getBone("turret").matrix());

    mesh->hideAll().show("wheel_left" ).draw(wheel[0].matrix());
    mesh->hideAll().show("wheel_left" ).draw(wheel[2].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[1].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[3].matrix());

    mesh->showAll();

    actor_hull.massCenterW().draw(RED); // draw mass center
}
   
11-18-2011 05:57 PM
Find all posts by this user Quote this message in a reply
Mardok Offline
Member

Post: #8
RE: problem with the mesh and the actors
Babulesnik Wrote:
Code:
void StructBRDM::draw()
{
    mesh->hideAll().show("wheel_left" ).draw(wheel[0].matrix());
    mesh->hideAll().show("wheel_left" ).draw(wheel[2].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[1].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[3].matrix());
}

You should change names for your wheels, something like:

"wheel_front_left"
"wheel_front_right"
"wheel_rear_left"
"wheel_rear_right"

On next screenshot which you paste show us physx.

This should resolve your problem in the simplest way:
In my project i'm using seperate mesh files for wheels(2 files - wheelL.mesh and wheelR.mesh). Mesh should be centered its important!!! It's smart for me because, a lot of vehicles are using the same wheels. And problem with bad position not exists... only draw mesh by matrix and working fine.
11-19-2011 02:43 AM
Find all posts by this user Quote this message in a reply
Babulesnik Offline
Member

Post: #9
RE: problem with the mesh and the actors
(11-19-2011 02:43 AM)Mardok Wrote:  
Babulesnik Wrote:
Code:
void StructBRDM::draw()
{
    mesh->hideAll().show("wheel_left" ).draw(wheel[0].matrix());
    mesh->hideAll().show("wheel_left" ).draw(wheel[2].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[1].matrix());
    mesh->hideAll().show("wheel_right").draw(wheel[3].matrix());
}

You should change names for your wheels, something like:

"wheel_front_left"
"wheel_front_right"
"wheel_rear_left"
"wheel_rear_right"

On next screenshot which you paste show us physx.

This should resolve your problem in the simplest way:
In my project i'm using seperate mesh files for wheels(2 files - wheelL.mesh and wheelR.mesh). Mesh should be centered its important!!! It's smart for me because, a lot of vehicles are using the same wheels. And problem with bad position not exists... only draw mesh by matrix and working fine.
Thanks, but I was curious to know how to do this without creating separate files wheels.I created separate files meshes wheels "wheels_left" "wheels_right" and it was not a problem
Code:
wheel_left ->draw(wheel[0].matrix());
.It always works fine)
   

I am wondering how to do it with MeshPart mesh->hideAll().show("wheel_left" ).draw(wheel[0].matrix()); -this is a problem
11-19-2011 01:28 PM
Find all posts by this user Quote this message in a reply
Post Reply