Skip to content

Instantly share code, notes, and snippets.

@cjameshuff
Created July 12, 2011 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjameshuff/1077278 to your computer and use it in GitHub Desktop.
Save cjameshuff/1077278 to your computer and use it in GitHub Desktop.
def obj_yrotate(srcobjfile, dstobjfile, amt)
sinang = Math.sin(amt*Math::PI/180.0)
cosang = Math.cos(amt*Math::PI/180.0)
fin = File.open(srcobjfile, 'r')
fout = File.open(dstobjfile, 'w')
fin.each_line {|line|
if(line.start_with?('v '))
v = line.split(' ')[1, 3].map{|x| x.to_f}
fout.puts "v #{v[0]*cosang + v[2]*sinang} #{v[1]} #{-v[0]*sinang + v[2]*cosang}"
elsif(line.start_with?('vn '))
v = line.split(' ')[1, 3].map{|x| x.to_f}
fout.puts "vn #{v[0]*cosang + v[2]*sinang} #{v[1]} #{-v[0]*sinang + v[2]*cosang}"
else
fout.puts line
end
}
fin.close
fout.close
end
obj_yrotate("testfile.obj", "testfileout90.obj", 90)
obj_yrotate("testfile.obj", "testfileout30.obj", 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment