mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Add support for smoothing
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -22,7 +22,7 @@ class IMICFPS
|
|||||||
@uvs = []
|
@uvs = []
|
||||||
@normals = []
|
@normals = []
|
||||||
@faces = []
|
@faces = []
|
||||||
@color = Color.new(0.5, 0.5, 0.5)
|
@smoothing= 0
|
||||||
parse
|
parse
|
||||||
face_count = 0
|
face_count = 0
|
||||||
@objects.each {|o| face_count+=o.faces.size}
|
@objects.each {|o| face_count+=o.faces.size}
|
||||||
@@ -40,11 +40,13 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render(scale = 1)
|
def render(scale = 1)
|
||||||
|
@objects.each_with_index do |o, i|
|
||||||
glEnable(GL_CULL_FACE)
|
glEnable(GL_CULL_FACE)
|
||||||
glEnable(GL_COLOR_MATERIAL)
|
glEnable(GL_COLOR_MATERIAL)
|
||||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
|
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
|
||||||
|
glShadeModel(GL_FLAT) unless o.faces.first[4]
|
||||||
|
glShadeModel(GL_SMOOTH) if o.faces.first[4]
|
||||||
glBegin(GL_TRIANGLES) # begin drawing model
|
glBegin(GL_TRIANGLES) # begin drawing model
|
||||||
@objects.each_with_index do |o, i|
|
|
||||||
o.faces.each do |vert|
|
o.faces.each do |vert|
|
||||||
vertex = vert[0]
|
vertex = vert[0]
|
||||||
uv = vert[1]
|
uv = vert[1]
|
||||||
@@ -59,11 +61,11 @@ class IMICFPS
|
|||||||
glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale)
|
glNormal3f(normal.x*scale, normal.y*scale, normal.z*scale)
|
||||||
glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale)
|
glVertex3f(vertex.x*scale, vertex.y*scale, vertex.z*scale)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
glEnd
|
glEnd
|
||||||
glDisable(GL_CULL_FACE)
|
glDisable(GL_CULL_FACE)
|
||||||
glDisable(GL_COLOR_MATERIAL)
|
glDisable(GL_COLOR_MATERIAL)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
lines = 0
|
lines = 0
|
||||||
@@ -80,6 +82,8 @@ class IMICFPS
|
|||||||
set_material(array[1])
|
set_material(array[1])
|
||||||
when 'o'
|
when 'o'
|
||||||
change_object(array[1])
|
change_object(array[1])
|
||||||
|
when 's'
|
||||||
|
set_smoothing(array[1])
|
||||||
when 'v'
|
when 'v'
|
||||||
add_vertex(array)
|
add_vertex(array)
|
||||||
when 'vt'
|
when 'vt'
|
||||||
@@ -100,9 +104,9 @@ class IMICFPS
|
|||||||
|
|
||||||
verts.each_with_index do |v, index|
|
verts.each_with_index do |v, index|
|
||||||
if uvs.first != ""
|
if uvs.first != ""
|
||||||
face = [@vertices[Integer(v)-1], @uvs[Integer(uvs[index])-1], @normals[Integer(norms[index])-1], material]
|
face = [@vertices[Integer(v)-1], @uvs[Integer(uvs[index])-1], @normals[Integer(norms[index])-1], material, @smoothing]
|
||||||
else
|
else
|
||||||
face = [@vertices[Integer(v)-1], nil, @normals[Integer(norms[index])-1], material]
|
face = [@vertices[Integer(v)-1], nil, @normals[Integer(norms[index])-1], material, @smoothing]
|
||||||
end
|
end
|
||||||
@current_object.faces << face
|
@current_object.faces << face
|
||||||
@faces << face
|
@faces << face
|
||||||
@@ -143,6 +147,14 @@ class IMICFPS
|
|||||||
@current_object = @objects.last
|
@current_object = @objects.last
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_smoothing(value)
|
||||||
|
if value == "1"
|
||||||
|
@smoothing = true
|
||||||
|
else
|
||||||
|
@smoothing = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_material(name)
|
def set_material(name)
|
||||||
@current_material = name
|
@current_material = name
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ class IMICFPS
|
|||||||
def render
|
def render
|
||||||
gl do
|
gl do
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||||
glShadeModel(GL_SMOOTH)
|
|
||||||
|
|
||||||
#glMatrixMode(matrix) indicates that following [matrix] is going to get used
|
#glMatrixMode(matrix) indicates that following [matrix] is going to get used
|
||||||
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
||||||
|
|||||||
Reference in New Issue
Block a user