Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Problem with construction of two vectors from one [opengl]

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 WiredCat   Members   


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 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




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;



Edited by ___, 23 March 2013 - 07:17 PM.

#2 grhodes_at_work   Members   


Posted 30 April 2013 - 10:41 AM

I realize this is a late reply, and you may have moved on from this post. In any case...


I would first comment that the term versor isn't that commonly used, and it can mean different things. A versor is a unit quaternion. But sometimes, for some reason, versor is used to denote a set of unit length basis vectors aligned with the axes of a coordinate system...and this is how you are using the term. I've been involved in modeling and geometric representations and coordinate space representations for some 30 years, on the practical side rather than theoretical, and I had never seen the word used before in this context. Not that this is a problem, but it confused me.


So, I would like to help on this problem, but your code isn't particularly intuitive. It would help to better understand the outcome that you are looking for. Can you repost your video? It does not seem to exist on YouTube. I can envision a much simpler way to create such a box, but it would help to know what you expect to happen as you move the mouse around.



Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

#3 apatriarca   Members   


Posted 05 May 2013 - 08:34 AM

@grhodes_at_work: I have always seen the term versor used to represent a unit vector, not necessarily aligned with the axes. You can found this term used with this meaning in this wikipedia page on unit vectors. Since the quaternion algebra is also a vector space, the usage of the term on quaternions is in my opinion just a specialization of the term in that context.

#4 grhodes_at_work   Members   


Posted 09 May 2013 - 10:32 AM



Thank you for the comment. Its interesting how we come to learn different terminologies. Somehow my path just never crossed with versor. The Wikipedia page specific to versor, http://en.wikipedia.org/wiki/Versor, introduces the quaternion use case, but also mentions the unit vector use case. There has to be some origin point for this word! I think I agree with your view.



Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

#5 WiredCat   Members   


Posted 18 May 2013 - 04:48 PM

the topic was solved by myself but moderator refused to delete topic

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.