Added access to kart location to scripts

This commit is contained in:
Sachith Hasaranga Seneviratne
2014-07-11 11:27:11 +05:30
parent f9e1f16c47
commit 060eb35898
2 changed files with 16 additions and 0 deletions

View File

@@ -11,4 +11,7 @@ void onUpdate()
}
Vec3 speed = Vec3(10,0,0);
setVelocity(0,speed);
Vec3 kartLoc = getKartLocation(0);
sheepMesh.move(kartLoc);
printVec3(kartLoc);
}

View File

@@ -83,6 +83,16 @@ namespace Scripting
kart->setVelocity(btVector3(velocity * normalized_dx, velocity, velocity * normalized_dy));
}
void getKartLocation(asIScriptGeneric *gen)
{
int id = (int)gen->GetArgDWord(0);
AbstractKart* kart = World::getWorld()->getKart(id);
Vec3 kart_loc = kart->getXYZ();
void *pointer = &kart_loc;
gen->SetReturnObject(pointer);
}
void setVelocity(asIScriptGeneric *gen)
{
int id = (int)gen->GetArgDWord(0);
@@ -102,6 +112,9 @@ namespace Scripting
r = engine->RegisterGlobalFunction("void teleportKart(int id, Vec3 &in)", asFUNCTION(teleportKart), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void setVelocity(int id, Vec3 &in)", asFUNCTION(setVelocity), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("void jumpKartTo(int id, float x, float y)", asFUNCTION(jumpKartTo), asCALL_GENERIC); assert(r >= 0);
r = engine->RegisterGlobalFunction("Vec3 getKartLocation(int id)", asFUNCTION(getKartLocation), asCALL_GENERIC); assert(r >= 0);
}
}
}