Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ middleware with GUI in C Pin
Member 83997696-Aug-12 21:58
Member 83997696-Aug-12 21:58 
GeneralRe: C++ middleware with GUI in C Pin
Richard MacCutchan6-Aug-12 22:46
mveRichard MacCutchan6-Aug-12 22:46 
GeneralRe: C++ middleware with GUI in C Pin
JohnAspras6-Aug-12 21:21
JohnAspras6-Aug-12 21:21 
GeneralRe: C++ middleware with GUI in C Pin
Software_Developer6-Aug-12 22:42
Software_Developer6-Aug-12 22:42 
AnswerRe: C++ middleware with GUI in C Pin
pasztorpisti7-Aug-12 11:53
pasztorpisti7-Aug-12 11:53 
GeneralRe: C++ middleware with GUI in C Pin
Member 83997697-Aug-12 19:18
Member 83997697-Aug-12 19:18 
GeneralRe: C++ middleware with GUI in C Pin
pasztorpisti7-Aug-12 21:13
pasztorpisti7-Aug-12 21:13 
GeneralNeed help for a Ray Cast Function Pin
SD1016-Aug-12 8:15
SD1016-Aug-12 8:15 
Hi i have a program to do with ray casting and i am really struggling tryng to code the void view::RayCast function. I have covered the code with comments to help you understand the code, I have looked all oevr the web for help but no success. If there is anyone that is capable of doing this, it would mean the world to me Wink | ;)

C#
void view::RayCast( float fRayStartX, float fRayStartY, unsigned int uViewingAngle )
{
  float fDX, fDY; // General purpose change in X and Y variables.
  int nGridX = 0; // The map array position of the next square intersecting the ray
  int nGridY = 0; // The map array position of the next square intersecting the ray
  int nTextIndex = 0; // The index into the relevant column of the texture map


  // Set the column angle to the angle of first ray with respect to the view.
  unsigned int nColumnAngle = m_nViewColAngStart;

  // Loop through all columns of pixels in viewport:
  for (int nColumn = 0; nColumn < m_nViewWidth; nColumn++)
  {
        // ***************************************************************************************
        // STEP 1: Use the starting position of the ray (fRayStartX, fRayStartY), the viewing
        // angle (uViewingAngle) and the column angle for this pixel column (nColumnAngle) to
        // calculate the end position (fRayEndX, fRayEndY) of a ray 1024 units long.
        // ***************************************************************************************

        // Avoid the situation where the column angle is 0
        if (nColumnAngle == 0) { nColumnAngle++; }

        // Calculate the angle of ray in with respect to the world
        // Ensure the angle is in the range of 0-4096


        // Look up the sin and cos of the ray angle in the relevant arrays


        // Rotate endpoint of a ray 1024 units long by the viewing angle:


        // Create variables to hold the ray's current position (fRayX, fRayY) and initialise them
        // to the start position.
        float fRayX = fRayStartX;
        float fRayY = fRayStartY;

        // ***************************************************************************************
        // STEP 2: Using the endpoint of the ray (fRayEndX, fRayEndY) calculate the change in
        // x and y (fDRayX and fDRayY) along the length of the ray. Then use these values to calculate
        // the slope (fSlope) of the ray (which is also m in the line equation y = mx + c).
        // ***************************************************************************************

        // Find difference in x,y coordinates along ray:


        // Make sure fDRayX is never exactly 0 otherwise you could get divide by zero errors


        // Calculate fSlope and make sure that is never exactly 0 either


        // Cast ray from grid line to grid line until the loop breaks out
        while( true )
        {
            // ***********************************************************************************
            // STEP 3: Calculate the co-ordinates of the intersection points between the ray and
            // the next map grid line in both the x and y axis: (fXCrossX, fXCrossY) for the x axis
            // and (fYCrossX, fYCrossY) for the y axis.
            // ***********************************************************************************

            float fXCrossX, fXCrossY; // Intersection point between the ray and the next grid line in the x axis

            // The sign of fDRayX tells you the direction of the ray in the x axis which will help you
            // to calculate fXCrossX. Once you have fXCrossX you can calculate fXCrossY based on the
            // fact that the change in x position (fXCrossX - fRayX) and the slope (fSlope) allows
            // you to calculate the change in the y position (fXCrossY - fRayY) for the movement to
            // the next x gridline. i.e. dy = m * dx

            // Check sign of fDRayX and calculate fXCrossX


            // Calculate fXCrossY


            float fYCrossX, fYCrossY; // Intersection point between the ray and the next grid line in the y axis

            // The sign of fDRayY tells you the direction of the ray in the y axis which will help you
            // to calculate fYCrossX. Once you have fYCrossX you can calculate fYCrossY based on the
            // fact that the change in y position (fXCrossY - fRayY) and the slope (fSlope) allows
            // you to calculate the change in the x position (fYCrossY - fRayX) for the movement to
            // the next y gridline. i.e. dx = dy / m

            // Check sign of fDRayY and calculate fXCrossX


            // Calculate fXCrossX


            // ***********************************************************************************
            // STEP 4: Use Pythagoras to calculate the relative distance to each of the grid line
            // intersection points(dXDistSq and dYDistSq) No need to use square roots here!
            // Double precision is necessary though.
            // ***********************************************************************************

            // Calculate dXDistSq
            double dXDistSq = 0.0;

            // Calculate dYDistSq
            double dYDistSq = 0.0;

            // ***********************************************************************************
            // STEP 5: Depending on which grid line is closer, update the ray position and
            // calcuate the map grid position (nGridX, nGridY). Check this map position to for an
            // obstruction and break out of the while loop if there is.
            // ***********************************************************************************

            // If x grid line is closer...
            if (dXDistSq < dYDistSq) {

                // Calculate maze grid coordinates of square nGridX and nGridY


                // Move current ray position to ray intersection point


                // Is there a maze cube here? If so, stop looping:
                if ( m_pViewWorld->m_pWorldTextures[nGridX][nGridY] != NULL)
                    break;


            } else { // If y grid line is closer:

                // Calculate maze grid coordinates of square nGridX and nGridY


                // Move current ray position to ray intersection point


                // Is there a maze cube here? If so, stop looping:
                if ( m_pViewWorld->m_pWorldTextures[nGridX][nGridY] != NULL)
                    break;


            }// End of If Else

        }// End of infinate for

GeneralRe: Need help for a Ray Cast Function Pin
Wes Aday6-Aug-12 8:20
professionalWes Aday6-Aug-12 8:20 
GeneralRe: Need help for a Ray Cast Function Pin
Software_Developer6-Aug-12 9:02
Software_Developer6-Aug-12 9:02 
Questionvectors Pin
Xarzu6-Aug-12 7:10
Xarzu6-Aug-12 7:10 
GeneralRe: vectors Pin
Software_Developer6-Aug-12 7:34
Software_Developer6-Aug-12 7:34 
AnswerRe: vectors Pin
Albert Holguin6-Aug-12 7:38
professionalAlbert Holguin6-Aug-12 7:38 
QuestionI'm doing a file download client,use http or ftp Pin
jiang1988jian5-Aug-12 23:34
jiang1988jian5-Aug-12 23:34 
GeneralRe: I'm doing a file download client,use http or ftp Pin
pasztorpisti6-Aug-12 3:29
pasztorpisti6-Aug-12 3:29 
GeneralRe: I'm doing a file download client,use http or ftp Pin
jiang1988jian12-Aug-12 15:07
jiang1988jian12-Aug-12 15:07 
GeneralRe: I'm doing a file download client,use http or ftp Pin
pasztorpisti12-Aug-12 19:46
pasztorpisti12-Aug-12 19:46 
AnswerRe: I'm doing a file download client,use http or ftp Pin
Software_Developer6-Aug-12 6:06
Software_Developer6-Aug-12 6:06 
GeneralRe: I'm doing a file download client,use http or ftp Pin
pasztorpisti6-Aug-12 6:38
pasztorpisti6-Aug-12 6:38 
GeneralRe: I'm doing a file download client,use http or ftp Pin
pasztorpisti6-Aug-12 6:43
pasztorpisti6-Aug-12 6:43 
QuestionHow to retain the state of check box in a dialog box in MFC.? Pin
mbatra315-Aug-12 21:20
mbatra315-Aug-12 21:20 
AnswerRe: How to retain the state of check box in a dialog box in MFC.? Pin
«_Superman_»5-Aug-12 23:00
professional«_Superman_»5-Aug-12 23:00 
GeneralRe: How to retain the state of check box in a dialog box in MFC.? Pin
mbatra316-Aug-12 2:21
mbatra316-Aug-12 2:21 
Generalget the txt of wordArt with VBA (C++ code) Pin
BCN-1635-Aug-12 20:21
BCN-1635-Aug-12 20:21 
QuestionRe: get the txt of wordArt with VBA Pin
CPallini5-Aug-12 21:03
mveCPallini5-Aug-12 21:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.