Sign in to follow this  
EmptyVoid

Creating a matrix using just it's forward vector

Recommended Posts

EmptyVoid    102
I cant figure this out it's really hard for me. I need a 3x3 matrix and the vector would be the forward vector but I need to make a up and right vector from the forward vector. I know once I have the up or right one I can get the cross product to create the other vector can anyone help me please?

Share this post


Link to post
Share on other sites
Evil Steve    2017
You can't. There's an infinite number of possibilties.

However, you can pick an arbitrary vector for up (E.g. (0, 1, 0)), and just make sure it's not perpendicular to your forward vector. Then you can use that the get a right vector, and then you can use those two to regenerate a correct up vector.

I think anyway...

Share this post


Link to post
Share on other sites
EmptyVoid    102
Quote:
Original post by Evil Steve
You can't. There's an infinite number of possibilties.

However, you can pick an arbitrary vector for up (E.g. (0, 1, 0)), and just make sure it's not perpendicular to your forward vector. Then you can use that the get a right vector, and then you can use those two to regenerate a correct up vector.

I think anyway...


I understand what your saying but it would be quite a hack job. lol

Quote:
Original post by dragongame
input vector f

let u and r be vectors

u.z = f.z;
if(f.y == 0)
{
u.x = 0;
u.y = 1;
}
else
{
u.x = 1;
u.y = -f.x / f.y;
}
normalize(u);
r = cross(f,u);
normalize(r);



heres what I did:


VS_OUTPUT VS(float3 position : POSITION, float2 tex1 : TEXCOORD0)
{
VS_OUTPUT Out;
float3 f = normalize(View[3]);
float3 u;
float3 r;

u.z = f.z;
if(f.y == 0)
{
u.x = 0;
u.y = 1;
}
else
{
u.x = 1;
u.y = -f.x / f.y;
}
u = normalize(u);
r = cross(f,u);
r = normalize(r);
Out.position = mul(float4(mul(position,float3x3(r,u,f)),1), WorldViewProj);
Out.tex1 = tex1;
return Out;
}





and it didnt work... makes it flat and it does crazy things. btw going to use it in a shader for a billboard and the object is at 0,0,0 so I just normalized the camera's position.

Share this post


Link to post
Share on other sites
EmptyVoid    102
They actually both work it was just that 3D max puts the z axis as the y but now I want to know witch is faster?


VS_OUTPUT VS(float3 position : POSITION, float2 tex1 : TEXCOORD0)
{
VS_OUTPUT Out;
float3 f = normalize(View[3]);
float3 u=float3(0,0,1);
float3 r=normalize(cross(f,u));
u=cross(f,r);

Out.position = mul(float4(mul(position,float3x3(u,r,f)),1), WorldViewProj);
Out.tex1 = tex1;
return Out;
}




VS_OUTPUT VS(float3 position : POSITION, float2 tex1 : TEXCOORD0)
{
VS_OUTPUT Out;
float3 f = normalize(View[3]);
float3 u;
float3 r;

u.z = f.z;
if(f.y == 0)
{
u.x = 0;
u.y = 1;
}
else
{
u.x = 1;
u.y = -f.x / f.y;
}
u = normalize(u);
r = cross(f,u);
r = normalize(r);
Out.position = mul(float4(mul(position,float3x3(r,u,f)),1), WorldViewProj);
Out.tex1 = tex1;
return Out;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this