Texture Koordinaten

  • Themenstarter Themenstarter StonedOne
  • Beginndatum Beginndatum
Status
Nicht offen für weitere Antworten.
S

StonedOne

Gast
Hallo an alle,

dies ist mein erster Post hier und ich hätte eine Frage, da ich über die Suchfunktion einer Suchmaschine nicht finden kann.

Ich arbeite seid Anfang 2006 an einem Projekt namens www.FhitKick.de und es gab ein Turnier Ende 2006. Mit der Version 2.0 wird das ganze zu einem OpenSource-Projekt und wenn jemand Interesse hat kann er gerne Zugang zum SVN bekommen.

Nun zum eigentlichen Problem:

Mit dieser Funktion erstelle ich eine Fläche die aus vielen kleinen Quadraten besteht ( dies mache ich um korrekte Lichteffekte auf zB einer grossen Fläche zu bekommen), leider ist es mir nicht möglich eine Texture auf die komplette Fläche zu ziehen. Die gewählte Texture wird immer gekachelt ...

Code:
    private Shape3D createXYPlane( float x, float y, Point3f p0 ) {
        Shape3D plane = new Shape3D();
        Vector3f norm = new Vector3f(0.0f, 0.0f, 1.0f);

        // Map the texture coordinate
        TexCoord2f[] texCoords = new TexCoord2f[(int)(16)];
        for (int i = 0; i < texCoords.length; i += 4) {
        	texCoords[i] = new TexCoord2f(1.0f, 0.0f);
        	texCoords[i + 1] = new TexCoord2f(0.0f, 0.0f);
        	texCoords[i + 2] = new TexCoord2f(0.0f, 1.0f);
        	texCoords[i + 3] = new TexCoord2f(1.0f, 1.0f);
        }
        
		int count=0, step = 5;

		QuadArray planeGeom = new QuadArray((int)(x*y*4*2), QuadArray.COORDINATES | QuadArray.NORMALS |                      
                                    QuadArray.TEXTURE_COORDINATE_2);
				
		for ( double countx = 0; countx < x; countx += step ){
			for ( double county = 0; county < y; county += step ){
				planeGeom.setCoordinate(count, new Point3d(p0.x - x/2 + countx, p0.y - y/2 + county, p0.z));
		        planeGeom.setNormal(count++, norm);
				planeGeom.setCoordinate(count, new Point3d(p0.x - x/2 + countx + step, p0.y - y/2 + county, p0.z));
		        planeGeom.setNormal(count++, norm);
				planeGeom.setCoordinate(count, new Point3d(p0.x - x/2 + countx + step, p0.y - y/2 + county + step, p0.z));
		        planeGeom.setNormal(count++, norm);
				planeGeom.setCoordinate(count, new Point3d(p0.x - x/2 + countx, p0.y - y/2 + county + step, p0.z));
		        planeGeom.setNormal(count++, norm);
			}
		}

        planeGeom.setTextureCoordinates(0, 0, texCoords);
            
        plane.setGeometry(planeGeom);
        
        return plane;
    }
Ist es möglich auf alle Quadrate zusammen eine einzige Texture zu ziehen? Wenn ja, könnt ihr mir einen Anhaltspunkt geben wie ich das hin bekomme?

Grüsse aus Hessen

Stoned
 
Code:
new TexCoord2f[(int)(16)];

ist natürlich

Code:
new TexCoord2f[(int)(x*y*4)];

und

Code:
new QuadArray((int)(x*y*4*2) ... )

hat auch einen anderen Wert, ich habe nur leider den abgeänderten Code eingefügt. Das alles sollte für das Problem aber nicht relevant sein. Nur damit ihr euch nicht wundert 😉
 
So ich habe es hin bekommen, ein wenig nachdenken hat geholfen 😉

Hier die fertige Funktion mit einer netten Texturfeature, vielleicht kann es noch wer gebrauchen

Code:
    /**
     * Diese Funktion erstellt eine ebene Fläche über die X,Y-Achsen und die dazu passenden Texturkoordinaten
     * 
     * @param x Länge der X-Achse
     * @param y Länge der Y-Achse
     * @param p0 Mittelpunkt der Fläche
     * @param faktorX Wie oft soll die Textur über die X-Ebene Angezeigt werden
     * @param faktorY Wie oft soll die Textur über die Y-Ebene Angezeigt werden
     * @return Gibst die Fläche zurück
     */
    private Shape3D createXYPlane( float x, float y, Point3f p0, int faktorX, int faktorY ) {
        Shape3D plane = new Shape3D();
        Vector3f norm = new Vector3f(0.0f, 0.0f, 1.0f);
		int count=0, step = 1;

        TexCoord2f[] texCoords = new TexCoord2f[(int)(x*y*4)];

		QuadArray planeGeom = new QuadArray((int)(x*y*4), QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
				
		for ( float countx = 0; countx < x; countx += step ){
			for ( float county = 0; county < y; county += step ){
				planeGeom.setCoordinate(count, new Point3f(p0.x - x/2 + countx, p0.y - y/2 + county, p0.z));
	        	texCoords[count] = new TexCoord2f(countx * faktorX/x, county * faktorY/y);
		        planeGeom.setNormal(count++, norm);
				
		        planeGeom.setCoordinate(count, new Point3f(p0.x - x/2 + countx + step, p0.y - y/2 + county, p0.z));
	        	texCoords[count] = new TexCoord2f((countx + 1) * faktorX/x, (county) * faktorY/y);
		        planeGeom.setNormal(count++, norm);
				
		        planeGeom.setCoordinate(count, new Point3f(p0.x - x/2 + countx + step, p0.y - y/2 + county + step, p0.z));
	        	texCoords[count] = new TexCoord2f((countx + 1) * faktorX/x, (county + 1) * faktorY/y);
		        planeGeom.setNormal(count++, norm);
				
		        planeGeom.setCoordinate(count, new Point3f(p0.x - x/2 + countx, p0.y - y/2 + county + step, p0.z));
	        	texCoords[count] = new TexCoord2f((countx) * faktorX/x, (county + 1) * faktorY/y);
		        planeGeom.setNormal(count++, norm);
			}
		}

        planeGeom.setTextureCoordinates(0, 0, texCoords);
            
        plane.setGeometry(planeGeom);
        
        return plane;
    }
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben