Author Topic: Cubic texture mapping  (Read 2371 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Cubic texture mapping
« on: May 24, 2013, 12:04:24 PM »
Mapping procedural (Perlin Noise) textures onto a sphere divided into squarish facets. the 6 surfaces of a cube are mapped onto the sphere.

from cubicsphere.o2bas / shapes.inc

 'GLOBE
  if not csface
    csface=CompileList
    CubicFace 8
    glEndList
  end if
  glPushMatrix
  glTranslatef -1.0,0.,-6.0
  glRotatef ang1,0,1,0
  'RedShinyMaterial.act
  whiteMaterial.act
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t2'texn(3)
  glCallList csface
  glRotatef 90.0,0,1,0
    glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,1,0,0
  glCallList csface
  glRotatef 180.0,1,0,0 'top
  glCallList csface
  glPopMatrix


--->

 sub CubicFace(sys n)
  ====================
  sys   i,j
  float u,v,w,x,y,z,sc,su,sv
  sc=1./n
  su=sc
  sv=sc
  float w1,w2,x1,y1,z1,x2,y2,z2,u1,u2,v1,v2
  y=-1.0
  w=1/sqr(3)
  y1=y*w
  v=0.
  v1=v
  for j=-n to <n
    x=-1.0
    u= 0.
    u1=u
    if v1+sv<0 or v1+sv>1.0 then sv=-sv
    v2=v1+sv
    glBegin GL_QUAD_STRIP
    for i=-n to n
      w1=1/sqr(x*x+y*y+1.0) '1/(distance to centre of cube)
      y+=sc
      w2=1/sqr(x*x+y*y+1.0) '1/(distance to centre of cube)
      'unity radius adjustment
      x1=x*w1
      x2=x*w2
      y2=y*w2
      y-=sc
      y1=y*w1
      z1=w1
      z2=w2
      glTexCoord2f u1,v2 : glNormal3f x2,y2,z2 : glVertex3f x2,y2,z2'*1.2
      glTexCoord2f u1,v1 : glNormal3f x1,y1,z1 : glVertex3f x1,y1,z1'*1.2
      x+=sc
      if u1+su<0 or u1+su>1.0 then su=-su
      u1+=su
    next
    glEnd
    y+=sc
    v1=v2
  next
  end sub




X

Peter

  • Guest
Re: Cubic texture mapping
« Reply #1 on: May 24, 2013, 12:26:22 PM »
Looks good, only the golf balls are a little bit too big.

Charles Pegge

  • Guest
Re: Cubic texture mapping
« Reply #2 on: May 24, 2013, 12:33:36 PM »
In this world, the golf course is made of hard rubber, and the golf balls are made of turf.