hi everyone,
i am struggling with a code and i need help! if u help me i appriciate...
the result that i want to get is "value of myarray[0]=0.577 or 0.5" and the others value of myarray[1] and value of my array[2] is zero. i am using devc++ compiler. i am not a good programmer as you will understand when you check the code!
i just need help...

Recommended Answers

All 2 Replies

Please post your code here between [code=cpp] code here [/code]
I personally don't like opening attachments

the result that i want to get is "value of myarray[0]=0.577 or 0.5" and the others value of myarray[1] and value of my array[2] is zero.

So what value ARE you getting?

the reason why i attached is that i saw someone attached his/her file in the forum!
the results are;
Value for myArray[0]=7.88196e+33,
Value for myArray[1]=1.53538e-37,
Value for myArray[2]=5.34649e+36,
i should also explain it is a little part of my source code it only contains some functions that i need!
here is the code:

#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include<stdlib.h>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <fstream>
#include<math.h>
#include<windows.h>
#include<conio.h>


using namespace std;


double VectorLength(float x,float y,float z)
{
     
     return sqrt((x*x) + (y*y)+ (z*z));
} 



float Normalize(float x,float y,float z)
{
       
  double len =VectorLength(x,y,z);
  x /= len;
  y /= len;
  z /= len;
  float vc[3] = {x,y,z};
  return (vc[3]);
}




float vectorSub(float*p1,float*p2)
{
    float U[3];
    U[0] = p2[0]-p1[0];
    U[1] = p2[1]-p1[1];
    U[2] = p2[2]-p1[2];
    return (U[3]);
     
}

float crossProduct(float*u,float*v)
{
          float uv[3];
          float Normalizeduv[3];
          uv[0]=u[1]*v[2]-u[2]*v[1];
          uv[1]=u[2]*v[0]-u[0]*v[2];
          uv[2]=u[0]*v[1]-u[1]*v[0];   
          Normalizeduv[3] = Normalize(uv[0],uv[1],uv[2]);
          return (Normalizeduv[3]);
}

float computeSurfaceNormal(float*p1,float*p2,float*p3)
{
         float u[3];
         float v[3];
         u[3]= vectorSub(p1,p2);
         v[3]= vectorSub(p1,p3);
         float SurfaceNormal[3];
         SurfaceNormal[3]= crossProduct(u,v);
         return (SurfaceNormal[3]);
  
}



 
int main()
{
        
       float p1[3]={1,1,0};
       float p2[3]={1,1,1};
       float p3[3]={1,0,0};
       float SurfaceNormal1[3];
       SurfaceNormal1[3]= static_cast<int> (computeSurfaceNormal(p1,p2,p3));
       for (int i=0; i<3; i++)
       {
       cout << "Value for myArray[" << i << "]: ";
       cout <<SurfaceNormal1[i]<<"\n";
   }    
       getch();
        
 
   }

thank you for your consideration...
regards,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.