Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Do Mär 28, 2024 08:46

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mo Jan 10, 2011 15:57 
Offline
DGL Member
Benutzeravatar

Registriert: Di Jul 01, 2003 18:59
Beiträge: 887
Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Is there easy to use code (under mpl ) to generate/draw basic shapes like cube/sphere/cylinder/cone etc?
Shapes should be drawable by GL_TRIANGLES.

My results so sofar:
cube ok
sphere ok
cylinder fail/ok (closed/open)

I have this feeling it should not be to hard , just draw some stacked circles, but ...

At this moment i feel like giving up with my 4th attempt from scratch making a cylinder.
I post my (broken) code here for you to give comments on:
Code:
function createCylinder(radius: GLFloat; height: GLFloat; var vertices: GLBufferf;var normals: GLbufferf; var texCoords: GLbufferf; var indices: GLBufferi;var numberVertices: GLuint): GLuint;
var
  i,j: GLuint;
  CIRCLE_RESOLUTION : integer;
  WIDTH_RESOLUTION : integer;
  WIDTH : glFloat;
  totalElements : integer;
  MAX_VERTICIES: integer;
  curidx: integer;
  anglestep: GLFloat;
begin

//stacking is wrong


RADIUS := RADIUS /2; //why div 2 is that because i define with instead of radious

  CIRCLE_RESOLUTION := 35;
  WIDTH_RESOLUTION := 10;
  WIDTH := height/2;


  MAX_VERTICIES := (CIRCLE_RESOLUTION * WIDTH_RESOLUTION);
  numberVertices := MAX_VERTICIES;

      angleStep := (2.0 * PI) / CIRCLE_RESOLUTION;


  // Vertices
  setlength(vertices, (CIRCLE_RESOLUTION * WIDTH_RESOLUTION * 4) + (2*4));

  curidx := 0;




  for j:=0 to WIDTH_RESOLUTION-1 do
  begin
    for i:=0 to CIRCLE_RESOLUTION-1 do
    begin

      vertices[curidx + 0] := cos( ( anglestep * i )) * RADIUS;
      vertices[curidx + 1] := (WIDTH*j) / (WIDTH_RESOLUTION);
      vertices[curidx + 2] := sin( ( anglestep * i )) * RADIUS;
      vertices[curidx + 3] := 1.0;
      curidx := curidx + 4;
    end;
  end;

  vertices[curidx + 0] := 0.0;
  vertices[curidx + 1] := -1.0 * width;
  vertices[curidx + 2] := 0.0;
  vertices[curidx + 3] := 1.0;
  curidx := curidx + 4;

  vertices[curidx + 0] := 1.0;
  vertices[curidx + 1] := 1.0 ;//* width;
  vertices[curidx + 2] := 1.0;
  vertices[curidx + 3] := 1.0;

  curidx := curidx + 4;

  // Indices
  totalElements := (CIRCLE_RESOLUTION * WIDTH_RESOLUTION * 6) + (CIRCLE_RESOLUTION * 3 * 2);
  setlength(indices, totalElements);

  curidx :=0;
  for i:=0 to CIRCLE_RESOLUTION-1 do
  begin
      for j:=0 to WIDTH_RESOLUTION-1 do
    begin

      if j= 0 then
      begin

      Indices[(curidx)+0]:=((CIRCLE_RESOLUTION * WIDTH_RESOLUTION * 4) + (2*4))-8;
      Indices[(curidx)+1]:=(i*j)+1;
      if ((i*j) = CIRCLE_RESOLUTION-1) then
        Indices[(curidx)+2]:=1
      else
        Indices[(curidx)+2]:=(i*j)+2;

      curidx := curidx + 3;
    end;
  end;
  end;


    for i:=0 to CIRCLE_RESOLUTION-1 do
  begin
      for j:=0 to WIDTH_RESOLUTION-1 do
    begin


      indices[curidx+0]:=((i*WIDTH_RESOLUTION + j + 1) mod MAX_VERTICIES);
      indices[curidx+1]:=((i*WIDTH_RESOLUTION + j) mod MAX_VERTICIES);
      indices[curidx+2]:=(((i+1) * WIDTH_RESOLUTION + j) mod MAX_VERTICIES);

      indices[curidx+3]:=((i*WIDTH_RESOLUTION + j + 1) mod MAX_VERTICIES);
      indices[curidx+4]:=(((i+1) * WIDTH_RESOLUTION + j) mod MAX_VERTICIES);
      indices[curidx+5]:=(((i+1) * WIDTH_RESOLUTION + j + 1) mod MAX_VERTICIES);

      curidx := curidx +6;
    end;
  end;



  // Normals
  setlength(normals, (CIRCLE_RESOLUTION * WIDTH_RESOLUTION * 3) + (2*3) );

  curidx := 0;

  normals[curidx + 0] := 0.0;
  normals[curidx + 1] := 1.0;
  normals[curidx + 2] := 0.0;

  curidx := curidx + 3;

  for i:=0 to CIRCLE_RESOLUTION-1 do
  begin
    for j:=0 to WIDTH_RESOLUTION-1 do
    begin
      normals[curidx + 0] := cos( ( anglestep * i ));//cos( degtorad( (360.0 / CIRCLE_RESOLUTION) * i ) );// * RADIUS) / radius;
      normals[curidx + 1] := ((j*WIDTH) / WIDTH_RESOLUTION) /radius;
      normals[curidx + 2] := sin( ( anglestep * i ));//sin( degtorad( (360.0 / CIRCLE_RESOLUTION) * i ) );// * RADIUS) / radius;
      curidx := curidx + 3;
    end;
  end;

  normals[curidx + 0] := 0.0;
  normals[curidx + 1] := -1.0;
  normals[curidx + 2] := 0.0;

  curidx := curidx + 3;

  // TexCoords
  setlength(texcoords, CIRCLE_RESOLUTION * WIDTH_RESOLUTION * 2 );
  curidx := 0;
  for i:=0 to CIRCLE_RESOLUTION-1 do
  begin
    for j:=0 to WIDTH_RESOLUTION-1 do
    begin
      texcoords[curidx + 0] := 0;
      texcoords[curidx + 1] := 0;
      curidx := curidx + 2;
    end;
  end;

  result := totalElements;

end;

_________________
http://3das.noeska.com - create adventure games without programming


Nach oben
 Profil  
Mit Zitat antworten  
BeitragVerfasst: Mo Jan 10, 2011 18:19 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7804
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
We have some code in the wiki for this

see: http://wiki.delphigl.com/index.php/Techniken_und_Algorithmen#Geometrie_Objekte

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 2 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.030s | 17 Queries | GZIP : On ]