Jump to content
  • Advertisement

Hype84

Member
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Hype84

  • Rank
    Newbie
  1. Excellent replies thank you everyone.
  2. Hype84

    Mouse Rotation

    A very interesting program. You have done a good job so far. Perhaps you could control the movement of the pointer by monitoring the actual mouse movement delta and timesing it by a vynal pixel poisition dependent value between 0 and 1 with the inner circle approching 1 and decreasing rapidly to 0 at the outer circle. You could then set the pointer to the computed value using setCursorPos. This would give the impression of increasing resistance on the surface. Well thats just my idea, I hope it your project works out ok. Alex
  3. Hi guys, I'm having problems trying to code a fairly simple geometry problem into a C++ project. I've tried many times without success and now I really need some assistant from some better coders/mathmaticians than myself. I am trying to write some code that will calculate the float distance of a known point from a known line in 2D. The data available is the beginning and end points of the line startPx and endPx and the point, called point. These are in my own CPixel object format which have their x and y co-ordinates. Below is the relavent code I have already written using resources on the internet for help but my maths are very rusty (I havent had to use it in a while). If you can help in any way at all I will be eternally greatful, and will do my best to help others on this board (my C++ and general software engineering are better than my maths!). // Begin code sample // I've taken this and simplified it from an online article, I will replace it // with my own structures if I can get this to work! typedef struct tagXY { float x, y; } XY; float CPixelRow::GetMagnitude(int startX, int startY, int endX, int endY) { XY vector; vector.x = endX - startX; vector.y = endY - startY; return (float)sqrt(vector.x * vector.x + vector.y * vector.y); } int CPixelRow::DistancePointLine(CPixel *point, float *distance) { float LineMag; float U; XY intersection; CPixel *headPx = surface.GetHead (); CPixel *tailPx = surface.GetTail (); LineMag = GetMagnitude(headPx->x, headPx->y, tailPx->x, tailPx->y); U = ( ( ( point->x - headPx->x ) * ( tailPx->x - headPx->x ) ) + ( ( point->y - headPx->y ) * ( tailPx->y - headPx->y ) ) ) / ( LineMag * LineMag ); if( U < 0.0f || U > 1.0f ) return 0; // closest point does not fall within the line segment intersection.x = headPx->x + U * ( tailPx->x - headPx->x ); intersection.y = headPx->y + U * ( tailPx->y - headPx->y ); *distance = GetMagnitude(point->x, point->y, intersection.x, intersection.y); return 1; } // End sample code Your expert help will be greatly appreciated. Thankyou, Alex
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!