Hi,
I need to perform some basic AI for models.
The models runs in the scene, following some targets, like quake.
how to perform the orientation and translation of the models to the targets?.
I have tried to put one camera child of model, and setTarget() of the camera to the next target, but the model don't get the rotation of the camera.
for example:
person->addChild(camera);
camera->setTarget(flag);
person->setRotation(camera->getRotation());
but, dont work.... (
any help, niko?
path finding
Re: path finding
... and i have tried other metod:
// --------------- function Dot and Magnitude
float Dot(vector3df vVector1, vector3df vVector2) {
// (V1.x * V2.x + V1.y * V2.y + V1.z * V2.z)
return ( (vVector1.X * vVector2.X) + (vVector1.Y * vVector2.Y) + (vVector1.Z * vVector2.Z) );
}
float Magnitude(vector3df vNormal){
return (float)sqrt( (vNormal.X * vNormal.X) + (vNormal.Y * vNormal.Y) + (vNormal.Z * vNormal.Z) );
}
//----------------------
float dotP = Dot(vigiapos, navepos);
float vmagnitude = Magnitude(vigiapos) * Magnitude(navepos);
double angle = acos(dotP / vmagnitude);
printf("angle = %d\n", angle);
vigia->setRotation(vector3df(nave->getRotation().X, angle, nave->getRotation().Z));
... but it dont work, either.
i get desesperated.... sure.
// --------------- function Dot and Magnitude
float Dot(vector3df vVector1, vector3df vVector2) {
// (V1.x * V2.x + V1.y * V2.y + V1.z * V2.z)
return ( (vVector1.X * vVector2.X) + (vVector1.Y * vVector2.Y) + (vVector1.Z * vVector2.Z) );
}
float Magnitude(vector3df vNormal){
return (float)sqrt( (vNormal.X * vNormal.X) + (vNormal.Y * vNormal.Y) + (vNormal.Z * vNormal.Z) );
}
//----------------------
float dotP = Dot(vigiapos, navepos);
float vmagnitude = Magnitude(vigiapos) * Magnitude(navepos);
double angle = acos(dotP / vmagnitude);
printf("angle = %d\n", angle);
vigia->setRotation(vector3df(nave->getRotation().X, angle, nave->getRotation().Z));
... but it dont work, either.
i get desesperated.... sure.
Re: path finding
OK... i have been get the solution myself...
I send soon the source and the executable about basic path finding.
It is the example of code:
// --------------- function Dot, Magnitude and Angle
float Dot(vector3df vVector1, vector3df vVector2) {
// (V1.x * V2.x + V1.y * V2.y + V1.z * V2.z)
return ( (vVector1.X * vVector2.X) + (vVector1.Y * vVector2.Y) + (vVector1.Z * vVector2.Z) );
}
float Magnitude(vector3df vNormal){
return (float)sqrt( (vNormal.X * vNormal.X) + (vNormal.Y * vNormal.Y) + (vNormal.Z * vNormal.Z) );
}
double AngleBetweenVectors(vector3df Vector1, vector3df Vector2){
float dotProduct = Dot(Vector1, Vector2);
float vectorsMagnitude = Magnitude(Vector1) * Magnitude(Vector2) ;
double angle = acos( dotProduct / vectorsMagnitude );
return( angle);
}
//---------------------- and lather....
float vangle = AngleBetweenVectors(vigiapos, navepos);
vangle /= (PI / 180);
vector3df vrot = vigia->getRotation();
vrot.Y = vangle;
vigia->setRotation(vrot);
OKIS, OKIS.... HOUSTON
I send soon the source and the executable about basic path finding.
It is the example of code:
// --------------- function Dot, Magnitude and Angle
float Dot(vector3df vVector1, vector3df vVector2) {
// (V1.x * V2.x + V1.y * V2.y + V1.z * V2.z)
return ( (vVector1.X * vVector2.X) + (vVector1.Y * vVector2.Y) + (vVector1.Z * vVector2.Z) );
}
float Magnitude(vector3df vNormal){
return (float)sqrt( (vNormal.X * vNormal.X) + (vNormal.Y * vNormal.Y) + (vNormal.Z * vNormal.Z) );
}
double AngleBetweenVectors(vector3df Vector1, vector3df Vector2){
float dotProduct = Dot(Vector1, Vector2);
float vectorsMagnitude = Magnitude(Vector1) * Magnitude(Vector2) ;
double angle = acos( dotProduct / vectorsMagnitude );
return( angle);
}
//---------------------- and lather....
float vangle = AngleBetweenVectors(vigiapos, navepos);
vangle /= (PI / 180);
vector3df vrot = vigia->getRotation();
vrot.Y = vangle;
vigia->setRotation(vrot);
OKIS, OKIS.... HOUSTON
hello,
i'm trying to do the same thing, and have tried your code, but i can't get it to work..here's what i'm doing:
any ideas??
i'm trying to do the same thing, and have tried your code, but i can't get it to work..here's what i'm doing:
Code: Select all
vangle = AngleBetweenVectors(botPos, lookToPos);
vangle /= (core::PI / 180);
vrot = botNode->getRotation();
vrot.Y = vangle;
botNode->setRotation(vrot);