Hi all.
My first extrude in a direction.
I have updated my code to acount for the up by using a perpendicular vector.
Thank you GameDev.
here is the updated code to create a 8 location of a cube faceing any direction
//the face vertex points defines our cube
//float3 p1, p2, p3, p4, p5, p6, p7, p8;
float3 vetexdata[8];
//we need to get the direction we are heading
float3 dir = normalize(target - pos);
//create a up vector
float3 up = Perpendicular(dir);//float3(0.0, 1.0, 0.0);
float halfsize = 200;//wdthp * 0.5;
float extrudelength = length(target - pos);
// todo: handle case when (dir == up)
float3 o1 = normalize(cross(dir, up)) * halfsize;
float3 o2 = normalize(cross(o1, dir)) * halfsize;
//this is the first face of the cube starting at our position facing the direction we want to extrude in
vetexdata[0] = pos + o1 + o2;
vetexdata[1] = pos + o1 - o2;
vetexdata[2] = pos - o1 - o2;
vetexdata[3] = pos - o1 + o2;
//the second face at the target location
vetexdata[4] = vetexdata[0] + dir* extrudelength;
vetexdata[5] = vetexdata[1] + dir* extrudelength;
vetexdata[6] = vetexdata[2] + dir* extrudelength;
vetexdata[7] = vetexdata[3] + dir* extrudelength;
//the above defines our cubes face vertices now we need to lay them out
//to form eighter the 4 faces with no end caps or the whole cube with end caps
//the easyest way I think is to make a index list with 3 index for a triangle
/*
uint indices[37]
{
// Front face
0,1,2,
0,2,3,
// Back face
4,6,5,
4,7,6,
// Left face
4,5,1,
4,1,0,
// Right face
3,2,6,
3,6,7,
// Top face
1,5,6,
1,6,2,
// Bottom face
4,0,3,
4,3,7,
};
*/
Image has glow but its a cube facing up
Thanks Again All.