AlignToVector
This function can be used to orient an entity's axis to match a user-defined axis in world space.
Syntax
- void AlignToVector(float x, float y, float z, int axis=2, float rate = 1.0, float roll = 0.0)
- void AlignToVector(const Vec3& v, int axis=2, float rate = 1.0, float roll = 0.0)
Parameters
- x: the X component of the axis.
- y: the Y component of the axis.
- z: the X component of the axis.
- axis: the entity axis to align. This may be 0, 1, or 2 for the X, Y, and Z axes, respectively.
- rate: if less than 1.0, this will be used to interpolate between the entity's current rotation and the new rotation.
- roll: the rotation value around the specified axis to orient the entity to.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -6);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create a model
Model* model = Model::Box();
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Leadwerks::Time::Update();
world->Update();
//Get the vector between the mouse position and the center of the screen
Vec3 v = window->GetMousePosition();
float dx = v.x - context->GetWidth() / 2.0;
float dy = context->GetHeight() / 2.0 - v.y;
v = Vec3(dx, dy, 0).Normalize();
//Align the model to the vector
model->AlignToVector(v, 2);
world->Render();
context->Sync();
}
}