xnewix's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Contributors
Active Posts:
197 (0.11 per day)
Joined:
23-May 09
Profile Views:
4,456
Last Active:
User is offline Apr 28 2014 07:49 AM
Currently:
Offline

Previous Fields

Country:
GB
OS Preference:
Windows
Favorite Browser:
Internet Explorer
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
25

Latest Visitors

Icon   xnewix has not set their status

Posts I've Made

  1. In Topic: Normal Calculations

    Posted 17 Apr 2014

    I do, at least I think I do.

    the numbers are references to which points to use in the calculation of a normal.

    so

    assignnormal(0,1,2); uses point3d[0], point3d[1] and point3d[2]

    consider this grid. where 0 has co-ordinates (x,y,x) (0,0,0)

    6 7 8
    3 4 5
    0 1 2

    (0,0,2) (1,0,2) (2,0,2)
    (0,0,1) (1,0,1) (2,0,1)
    (0,0,0) (1,0,0) (2,0,0)

    therefore, using assignnormal(0,1,2);

    v1 =0
    v2 =1
    v3 =2

    double u_x = point3d[v2].getx()-point3d[v1].getx();

    double u_x = point3d[1].x - point3d[0].x

    point3d[1].x = 1 and point3d[0].x = 0

    the normal function then outputs this to the Point3d resultantnormal
    where the values are stored into

        void assignnormal(int v1, int v2, int v3) {
            normals(v1,v2,v3);
            tempnormals.push_back(resultantnormal);
        }
    


    std::vector<Point3d> tempnormals;
    


    i don't pass straight to the point3d[i].normal[0] as I need to find the average of all adjacent normals.
  2. In Topic: Normal Calculations

    Posted 17 Apr 2014

    Yes, it compiles.

    The mesh is a 1201*1201 grid of points.
    The aim was to take 8 other point surrounding a central point and calculate its average normal.

    p8 p1 p2
    p7 A p3
    p6 p5 p4

    so to calculate the normal here I calculate normals using

    A,p1,p2
    A,p2,p3
    A,p3,p4
    A,p4,p5.....etc

    the vertexnormal function is where this happens.
    but first the code decides how many points are surrounding the central point A.

    reason being, if A was the bottom left of the grid, i.e point3d[0] then there are no points to the left or under it.
    no p8,p7,p6.... p5 or p4

    once it has been decided on the number of adjacent points, the referance of each of those points is stored in tempids.
    so for the bottom right the ids should be stored as...

    tempid[0] = 0
    tempid[1] = 1201
    tempid[2] = 1202
    tempid[3] = 1

    then I call the assignnormal function to calculate normals using the values

    // this is my first mistake. there is no 4 id.

    assignnormal(0,1,2); use points 0, 1201, 1202
    assignnormal(0,2,3); use points 0, 1202, 1
    assignnormal(0,3,4); use points 0, 1, non
    assignnormal(0,4,1); use points 0, non, 1201

    // should be?

    assignnormal(0,1,2); use points 0, 1201, 1202
    assignnormal(0,2,3); use points 0, 1202, 1
    assignnormal(0,3,1); use points 0, 1, 1201

    // second mistake,
    assign normal function uses ints which are then passed to the normal function.
    the normal function uses v1,v2,v3

    point3d[v1]

    so only the points 0,1,2,3,4,5,6,7,8 will ever be used out of 1,442,401
    this should probably be....

    assignnormal(tempid[0],tempid[1],tempid[2]);
    assignnormal(tempid[0],tempid[2],tempid[3]);
    assignnormal(tempid[0],tempid[3],tempid[1]);
    


    also I question calculating a normal using 0,3,1

    The output I get with sqrt in normal function.

    with: point i = -1#INF, -1#INF, -1#INF

    without: point i = 000
  3. In Topic: Stopping duplicate entries into vector. Opengl icosahedron

    Posted 27 Dec 2013

    Quote

    Why are you using an iterator and also using pos?


    I need the getMidPoint() function to return and int. At least I think I do. I could remove the iterator and just use pos, but wont that create a warning?

    Quote

    It seems to me that addPoint() should be checking for an identical point before deciding whether or not to add it, no?


    I do. addPoint() is only used in the constructor.
    I start checking for existing midpoints at line 60 of the 2nd code extract and add a new point if one was not found at line 71, although, I guess that line could be substituted for the addPoint() function.
  4. In Topic: STL vectors and lists. unable to store class objects correctly

    Posted 5 Sep 2013

    this is taken from the opengl version, so there are a few redundant bits of code.

    this works but doesn't store the new data.

    all i can think of now is the way that the triangles are added. or it has something to do with the extra points.

    the image shows the same sphere from different distances.
    the solid sphere looks fine but looking closer in wiremesh mode there are incorrectly/extra? placed lines.

    Posted Image


    #include <iostream>
    #include <fstream>
    #include <cmath>
    #include <vector>
    
    
    class Point3d {
    private:
    	double x,y,z;
    public:
    	Point3d(double nx,double ny,double nz) : x(nx),y(ny),z(nz) { }
    	Point3d()   {}
    	~Point3d()  {}
    
    	double getx() { return x; }
    	double gety() { return y; }
    	double getz() { return z; }
    };
    
    class Triangle3d {
    private:
    	int v1,v2,v3;
    public:
    	Triangle3d(int nv1, int nv2, int nv3) : v1(nv1),v2(nv2),v3(nv3) { }
    	Triangle3d()  {}
    	~Triangle3d() {}
    	
    	int getv1() { return v1; }
    	int getv2() { return v2; }
    	int getv3() { return v3; }
    };
    
    class Sphere3d {
    private:
    	double radius;
    	double size;
    	double depth; // subdivisions
    
    	std::vector<Point3d>      point3d;	
    	std::vector<Triangle3d>   triangle3d;
    	std::vector<Triangle3d>   newtriangles3d;
    
    public:
    	Sphere3d(double nsize, double ndepth)  : size(nsize), depth(ndepth) {
    
    		radius =(1.0+sqrt(5.0))/2.0;
    
    		addPoint(-size, radius*size,0.0);
    		addPoint( size, radius*size,0.0);
    		addPoint(-size,-radius*size,0.0);
    		addPoint( size,-radius*size,0.0);
        
    		addPoint(0.0,-size, radius*size);
    		addPoint(0.0, size, radius*size);
    		addPoint(0.0,-size,-radius*size);
    		addPoint(0.0, size,-radius*size);
    
    		addPoint( radius*size,0.0,-size);
    		addPoint( radius*size,0.0, size);
    		addPoint(-radius*size,0.0,-size);
    		addPoint(-radius*size,0.0, size);
    
    		addTriangle(0,11,5);
    		addTriangle(0,5,1);
    		addTriangle(0,1,7);
    		addTriangle(0,7,10);
    		addTriangle(0,10,11);
    
    		addTriangle(1,5,9);
    		addTriangle(5,11,4);
    		addTriangle(11,10,2);
    		addTriangle(10,7,6);
    		addTriangle(7,1,8);
    
    		addTriangle(3,9,4);
    		addTriangle(3,4,2);
    		addTriangle(3,2,6);
    		addTriangle(3,6,8);
    		addTriangle(3,8,9);
    
    		addTriangle(4,9,5);
    		addTriangle(2,4,11);
    		addTriangle(6,2,10);
    		addTriangle(8,6,7);
    		addTriangle(9,8,1);
    
    		generate();	
    	} 
    	~Sphere3d() {}	
    	
    	void addPoint(double x,double y, double z) {
    		point3d.push_back(Point3d(x,y,z));	
    	}  
    	void addTriangle(int xindex,int yindex, int zindex) {
    		triangle3d.push_back(Triangle3d(xindex,yindex,zindex));	
    	} 
    	int getMidPoint(int p1, int p2) {		
    		
    		//N.B - Still need to Eliminate duplicates
    		double nx = (point3d[p1].getx()+point3d[p2].getx())/2;
    		double ny = (point3d[p1].gety()+point3d[p2].gety())/2;
    		double nz = (point3d[p1].getz()+point3d[p2].getz())/2;
    
    		double n = sqrt((nx*nx)+(ny*ny)+(nz*nz));
    		nx /=n;	ny /=n;	nz /=n;
    
            nx *=sqrt(radius*radius+1.0)*size; 
    		ny *=sqrt(radius*radius+1.0)*size; 
    		nz *=sqrt(radius*radius+1.0)*size;
    
    		point3d.push_back(Point3d(nx,ny,nz));
    		return point3d.size()-1;
    	}
    	void subdivide(int v1,int v2,int v3,double depth) {
    		
    		if(depth == 0) {				
    			return;
    		}
    
    		int v12 = getMidPoint(v1,v2);
    		int v23 = getMidPoint(v2,v3);
    		int v31 = getMidPoint(v3,v1);
    
    		newtriangles3d.push_back(Triangle3d(v1,v12,v31));
    		newtriangles3d.push_back(Triangle3d(v2,v23,v12));
    		newtriangles3d.push_back(Triangle3d(v3,v31,v23));
    		newtriangles3d.push_back(Triangle3d(v12,v23,v31));
    
    		subdivide(v1,v12,v31,depth-1);	
                    subdivide(v2,v23,v12,depth-1);
    		subdivide(v3,v31,v23,depth-1);
    		subdivide(v12,v23,v31,depth-1);	
    
    	}
    	void generate() {		
    		for(int i=0; i<20; i++) {
    			subdivide(triangle3d[i].getv1(),triangle3d[i].getv2(),triangle3d[i].getv3(),depth);			
    		}
    		if(depth != 0) {	
    			triangle3d = newtriangles3d;
    			newtriangles3d.clear();
    		}		
    		outputdata();
    	}
    	/*
    	void draw() {
    		for(int i=0; i<triangle3d.size(); i++) {
    			glBegin(GL_TRIANGLES);
    
                    glColor3f(0.5,0.5,0.5); 
    				glNormal3f(point3d[triangle3d[i].getv1()].getx(),point3d[triangle3d[i].getv1()].gety(),point3d[triangle3d[i].getv1()].getz());
       			    glVertex3f(point3d[triangle3d[i].getv1()].getx(),point3d[triangle3d[i].getv1()].gety(),point3d[triangle3d[i].getv1()].getz());
    		        
    				glColor3f(0.5,0.5,0.5); 
    				glNormal3f(point3d[triangle3d[i].getv2()].getx(),point3d[triangle3d[i].getv2()].gety(),point3d[triangle3d[i].getv2()].getz());
    				glVertex3f(point3d[triangle3d[i].getv2()].getx(),point3d[triangle3d[i].getv2()].gety(),point3d[triangle3d[i].getv2()].getz());
    				
    				glColor3f(0.5,0.5,0.5); 
    				glNormal3f(point3d[triangle3d[i].getv3()].getx(),point3d[triangle3d[i].getv3()].gety(),point3d[triangle3d[i].getv3()].getz());
    		        glVertex3f(point3d[triangle3d[i].getv3()].getx(),point3d[triangle3d[i].getv3()].gety(),point3d[triangle3d[i].getv3()].getz());
    		    
    			glEnd();
    		}
    	}
    	*/
    	void outputdata() {
    		std::ofstream datafile;
    		datafile.open("data.txt");
    		datafile << "New Triangles: " << newtriangles3d.size() << std::endl;
    		for(std::size_t i=0; i<point3d.size(); i++) {
    			datafile  << i << "  x: " << point3d[i].getx() << "  y: " << point3d[i].gety() << "  z: " << point3d[i].getz() << std::endl;
    			//std::cout << i << "  x: " << point3d[i].getx() << "  y: " << point3d[i].gety() << "  z: " << point3d[i].getz() << std::endl;
    		}	 
            for(std::size_t i=0; i<triangle3d.size(); i++) {
    			datafile  << i << "  x: " << triangle3d[i].getv1() << "  y: " << triangle3d[i].getv2() << "  z: " << triangle3d[i].getv3() << std::endl;
    			//std::cout << i << "  x: " << triangle3d[i].getv1() << "  y: " << triangle3d[i].getv2() << "  z: " << triangle3d[i].getv3() << std::endl;
    		}	 
    		datafile.close();
    	}
    	double displaydepth()  { return depth; }
    	int pointcount()    { return point3d.size(); }
    	int trianglecount() { return triangle3d.size(); }
    };
    
    int main() {
    	Sphere3d sphere3d(10.0,1.0);
    	std::cout << "subsdivisions:  " << sphere3d.displaydepth() << std::endl;
    	std::cout << "points:         " << sphere3d.pointcount() << std::endl;
    	std::cout << "triangles       " << sphere3d.trianglecount() << std::endl;
    
    	int num=0; std::cin >> num;
    	return 0;
    }
    
  5. In Topic: STL vectors and lists. unable to store class objects correctly

    Posted 4 Sep 2013

    At the moment im getting the same output.

    72 points and 80 triangles.

    though i'm getting some undesirable results when running through Opengl.
    but apart from that and the redundant midpoints it looks like a sphere.

    I'll posst an larger update with code tommorow,

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://ageofgreeks.darkbb.com/forum.htm

Friends

Comments

Page 1 of 1
  1. Photo

    ce0swald Icon

    23 Jun 2010 - 19:15
    FYI... Your website is down.
Page 1 of 1