Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actual___

Posted 23 March 2013 - 07:17 PM

hello, i am trying to create a 3d box from on screen. (from a specified modelview)

 

 

here is what i do:

 

get from modelview 3 vectors (front, right and up) (they're versors)

then i check when i clicked at the beggining and i make a vertex (the first box vertex) call it A (red dot)

after that i check where actually mouse pos is and create a second vertex (the last box front face vertex) call it B (green dot)

 

 

i make a vector from first vertex to last vertex (AB)

 

and then project it onto 2 versors (right and up)

 

then i make a depth vector (from front versor)

 

but i does not work : )

 

here is a vid:

 

 

I am using the formula from wikipedia

 

result = lengthof(projected_vec) * cosine_between_those_2_vectors * versor_direction_of_vec_that_will_be projected_on

vec_projection.jpg

 

 

please look at my code it looks fine but maybe i can't find bug there

 

and here is code with (stage 2 - green dot and rest of box creation)

 

 





void __fastcall TModelGroupHandler::ResizeBox(int X, int Y, HWND hwnd)
{
if (n2ddistance(float(lastx), float(lasty), float(X), float(Y) ) < 10.0f) return;
if (insert_box_first_stage_completed == false) return;


double * m_PickInfo_ModelView = new double[16];
t3dpoint vX; t3dpoint vY;

glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);
		/*

			AIR_MATRIX[0] = rr.x; //right
			AIR_MATRIX[1] = rr.y;
			AIR_MATRIX[2] = rr.z;
			AIR_MATRIX[3] = 0.0f;
			AIR_MATRIX[4] = ru.x; //up
			AIR_MATRIX[5] = ru.y;
			AIR_MATRIX[6] = ru.z;
			AIR_MATRIX[7] = 0.0f;
			AIR_MATRIX[8]  = -rf.x; //front
			AIR_MATRIX[9]  = -rf.y;
			AIR_MATRIX[10] = -rf.z;
			AIR_MATRIX[11] = 0.0f;
			AIR_MATRIX[12] =  0.0f;  //point
			AIR_MATRIX[13] =  0.0f;
			AIR_MATRIX[14] =  0.0f;
			AIR_MATRIX[15] = 1.0f;

        */

vX.x = float(m_PickInfo_ModelView[0]);
vX.y = float(m_PickInfo_ModelView[1]);
vX.z = float(m_PickInfo_ModelView[2]);


vY.x =	float(m_PickInfo_ModelView[4]);
vY.y =	float(m_PickInfo_ModelView[5]);
vY.z =	float(m_PickInfo_ModelView[6]);
  //vector projection onto another vector
  

  
t3dpoint nX = vX;
t3dpoint nY = vY;

vX = vector_multiple(vX, 10000.0f);
vY = vector_multiple(vY, 10000.0f);

delete m_PickInfo_ModelView;

t3dpoint res;        t3dpoint res2;  

res = GetPositionFromSpaceDepth(X, Y, hwnd); //GREEN DOT

//==================================================================================
//right vector projection
t3dpoint projected_vec;     projected_vec = vectorAB(base->p1, res);

float cos_angle = RadToDeg(   AngleBetweenVectors(vX,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh



float magni;
magni = magnitude( projected_vec );

float fp; /* floating point */
 fp = magni * cos_angle;

t3dpoint proper_right_vec = vector_multiple(nX, fp);
//==================================================================================
//down vector projection
//==================================================================================

projected_vec = vectorAB(base->p1, res);



cos_angle = RadToDeg(   AngleBetweenVectors(vY,projected_vec)  );      //vY should be reversed now but i does not matter now because box right vector is wrong too)




cos_angle = cos(cos_angle*imopi);                                 //ssh

fp = magni * cos_angle;

t3dpoint proper_down_vec = vector_multiple(vY, fp);

proper_down_vec = reverse_point( proper_down_vec );
 
//==================================================================================
t3dpoint depth_v = vectorAB(base->eyepos, base->eyepointingpos);    depth_v = Normalize( depth_v );

depth_v = vector_multiple(depth_v, 50.0f); //default 50 meters depth


//*************************************************
//** proper_down_vec
//** proper_right_vec
//** depth_v
//**
//**  p1    p2       p5  p6
//**
//**   front          back
//**  p4    p3       p8  p7
//**
//**
//**
//*************************************************

base->p5 = 	vectors_add(base->p1, depth_v);

base->p3 = res;
base->p7 = 	vectors_add(base->p3, depth_v);

base->p2 	=  vectors_add(base->p1, proper_right_vec);
base->p6 	=  vectors_add(base->p2, depth_v);

base->p4 	= vectors_add(base->p1, proper_down_vec);
base->p8 	= vectors_add(base->p4, depth_v);



box_can_be_drawn = true;
}

 

cheers


#2___

Posted 23 March 2013 - 07:14 PM

hello, i am trying to create a 3d box from on screen. (from a specified modelview)

 

 

here is what i do:

 

get from modelview 3 vectors (front, right and up) (they're versors)

then i check when i clicked at the beggining and i make a vertex (the first box vertex) call it A (red dot)

after that i check where actually mouse pos is and create a second vertex (the last box front face vertex) call it B (green dot)

 

 

i make a vector from first vertex to last vertex (AB)

 

and then project it onto 2 versors

 

then i make a depth vector (from front versor)

 

but i does not work : )

 

here is a vid:

 

 

I am using the formula from wikipedia

 

result = lengthof(projected_vec) * cosine_between_those_2_vectors * versor_direction_of_vec_that_will_be projected_on

vec_projection.jpg

 

 

please look at my code it looks fine but maybe i can't find bug there

 

and here is code with (stage 2 - green dot and rest of box creation)

 

 



void __fastcall TModelGroupHandler::ResizeBox(int X, int Y, HWND hwnd)
{
if (n2ddistance(float(lastx), float(lasty), float(X), float(Y) ) < 10.0f) return;
if (insert_box_first_stage_completed == false) return;


double * m_PickInfo_ModelView = new double[16];
t3dpoint vX; t3dpoint vY;

glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);
		/*

			AIR_MATRIX[0] = rr.x; //right
			AIR_MATRIX[1] = rr.y;
			AIR_MATRIX[2] = rr.z;
			AIR_MATRIX[3] = 0.0f;
			AIR_MATRIX[4] = ru.x; //up
			AIR_MATRIX[5] = ru.y;
			AIR_MATRIX[6] = ru.z;
			AIR_MATRIX[7] = 0.0f;
			AIR_MATRIX[8]  = -rf.x; //front
			AIR_MATRIX[9]  = -rf.y;
			AIR_MATRIX[10] = -rf.z;
			AIR_MATRIX[11] = 0.0f;
			AIR_MATRIX[12] =  0.0f;  //point
			AIR_MATRIX[13] =  0.0f;
			AIR_MATRIX[14] =  0.0f;
			AIR_MATRIX[15] = 1.0f;

        */

vX.x = float(m_PickInfo_ModelView[0]);
vX.y = float(m_PickInfo_ModelView[1]);
vX.z = float(m_PickInfo_ModelView[2]);


vY.x =	float(m_PickInfo_ModelView[4]);
vY.y =	float(m_PickInfo_ModelView[5]);
vY.z =	float(m_PickInfo_ModelView[6]);
  //vector projection onto another vector
  

  
t3dpoint nX = vX;
t3dpoint nY = vY;

vX = vector_multiple(vX, 10000.0f);
vY = vector_multiple(vY, 10000.0f);

delete m_PickInfo_ModelView;

t3dpoint res;        t3dpoint res2;  

res = GetPositionFromSpaceDepth(X, Y, hwnd);
//==================================================================================
//right vector projection
t3dpoint projected_vec;     projected_vec = vectorAB(base->p1, res);

float cos_angle = RadToDeg(   AngleBetweenVectors(vX,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh



float magni;
magni = magnitude( projected_vec );

float fp; /* floating point */
 fp = magni * cos_angle;

t3dpoint proper_right_vec = vector_multiple(nX, fp);
//==================================================================================
//down vector projection
//==================================================================================

projected_vec = vectorAB(base->p1, res);

cos_angle = RadToDeg(   AngleBetweenVectors(vY,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh

fp = magni * cos_angle;

t3dpoint proper_down_vec = vector_multiple(vY, fp);

proper_down_vec = reverse_point( proper_down_vec );
//==================================================================================
t3dpoint depth_v = vectorAB(base->eyepos, base->eyepointingpos);    depth_v = Normalize( depth_v );

depth_v = vector_multiple(depth_v, 50.0f); //default 50 meters depth


//*************************************************
//** proper_down_vec
//** proper_right_vec
//** depth_v
//**
//**  p1    p2       p5  p6
//**
//**   front          back
//**  p4    p3       p8  p7
//**
//**
//**
//*************************************************

base->p5 = 	vectors_add(base->p1, depth_v);

base->p3 = res;
base->p7 = 	vectors_add(base->p3, depth_v);

base->p2 	=  vectors_add(base->p1, proper_right_vec);
base->p6 	=  vectors_add(base->p2, depth_v);

base->p4 	= vectors_add(base->p1, proper_down_vec);
base->p8 	= vectors_add(base->p4, depth_v);



box_can_be_drawn = true;
}

 

cheers


#1___

Posted 23 March 2013 - 07:13 PM

hello, i am trying to create a 3d box from on screen. (from a specified modelview)

 

 

here is what i do:

 

get from modelview 3 vectors (front, right and up) (they're versors)

then i check when i clicked at the beggining and i make a vertex (the first box vertex) call it A (red dot)

after that i check where actually mouse pos is and create a second vertex (the last box front face vertex) call it B (green dot)

 

 

i make a vector from first vertex to last vertex (AB)

 

and then project it onto 2 vectors (two versors multiplied by 1000 [up and right])

 

then i make a depth vector (from front versor)

 

but i does not work : )

 

here is a vid:

 

 

I am using the formula from wikipedia

 

result = lengthof(projected_vec) * cosine_between_those_2_vectors * versor_direction_of_vec_that_will_be projected_on

vec_projection.jpg

 

 

please look at my code it looks fine but maybe i can't find bug there

 

and here is code with (stage 2 - green dot and rest of box creation)

 

 

void __fastcall TModelGroupHandler::ResizeBox(int X, int Y, HWND hwnd)
{
if (n2ddistance(float(lastx), float(lasty), float(X), float(Y) ) < 10.0f) return;
if (insert_box_first_stage_completed == false) return;


double * m_PickInfo_ModelView = new double[16];
t3dpoint vX; t3dpoint vY;

glGetDoublev(GL_MODELVIEW_MATRIX, m_PickInfo_ModelView);
		/*

			AIR_MATRIX[0] = rr.x; //right
			AIR_MATRIX[1] = rr.y;
			AIR_MATRIX[2] = rr.z;
			AIR_MATRIX[3] = 0.0f;
			AIR_MATRIX[4] = ru.x; //up
			AIR_MATRIX[5] = ru.y;
			AIR_MATRIX[6] = ru.z;
			AIR_MATRIX[7] = 0.0f;
			AIR_MATRIX[8]  = -rf.x; //front
			AIR_MATRIX[9]  = -rf.y;
			AIR_MATRIX[10] = -rf.z;
			AIR_MATRIX[11] = 0.0f;
			AIR_MATRIX[12] =  0.0f;  //point
			AIR_MATRIX[13] =  0.0f;
			AIR_MATRIX[14] =  0.0f;
			AIR_MATRIX[15] = 1.0f;

        */

vX.x = float(m_PickInfo_ModelView[0]);
vX.y = float(m_PickInfo_ModelView[1]);
vX.z = float(m_PickInfo_ModelView[2]);


vY.x =	float(m_PickInfo_ModelView[4]);
vY.y =	float(m_PickInfo_ModelView[5]);
vY.z =	float(m_PickInfo_ModelView[6]);
  //vector projection onto another vector
  

  
t3dpoint nX = vX;
t3dpoint nY = vY;

vX = vector_multiple(vX, 10000.0f);
vY = vector_multiple(vY, 10000.0f);

delete m_PickInfo_ModelView;

t3dpoint res;        t3dpoint res2;  

res = GetPositionFromSpaceDepth(X, Y, hwnd);
//==================================================================================
//right vector projection
t3dpoint projected_vec;     projected_vec = vectorAB(base->p1, res);

float cos_angle = RadToDeg(   AngleBetweenVectors(vX,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh



float magni;
magni = magnitude( projected_vec );

float fp; /* floating point */
 fp = magni * cos_angle;

t3dpoint proper_right_vec = vector_multiple(nX, fp);
//==================================================================================
//down vector projection
//==================================================================================

projected_vec = vectorAB(base->p1, res);

cos_angle = RadToDeg(   AngleBetweenVectors(vY,projected_vec)  );      //ssh

cos_angle = cos(cos_angle*imopi);                                 //ssh

fp = magni * cos_angle;

t3dpoint proper_down_vec = vector_multiple(vY, fp);

proper_down_vec = reverse_point( proper_down_vec );
//==================================================================================
t3dpoint depth_v = vectorAB(base->eyepos, base->eyepointingpos);    depth_v = Normalize( depth_v );

depth_v = vector_multiple(depth_v, 50.0f); //default 50 meters depth


//*************************************************
//** proper_down_vec
//** proper_right_vec
//** depth_v
//**
//**  p1    p2       p5  p6
//**
//**   front          back
//**  p4    p3       p8  p7
//**
//**
//**
//*************************************************

base->p5 = 	vectors_add(base->p1, depth_v);

base->p3 = res;
base->p7 = 	vectors_add(base->p3, depth_v);

base->p2 	=  vectors_add(base->p1, proper_right_vec);
base->p6 	=  vectors_add(base->p2, depth_v);

base->p4 	= vectors_add(base->p1, proper_down_vec);
base->p8 	= vectors_add(base->p4, depth_v);



box_can_be_drawn = true;
}

 

cheers


PARTNERS