CCamera CCamera::CreateCamera(CVector position, CVector lookAt) { auto forward = lookAt.Subtract(position).Normalize(); auto down = CVector(0.0, -1.0, 0.0); auto right = forward.Cross(down).Normalize().Scale(1.5); auto up = forward.Cross(right).Normalize().Scale(1.5); return CCamera(position, forward, right, up); }
LUALIB_FUNCTION(_G, Camera) { auto self = CCamera(); my->Push(self); return 1; }
std::string cur_s; s_stream >> cur_s; if(cur_s == "sphere") { double c_x, c_y, c_z, radius; int r, g, b; s_stream >> c_x >> c_y >> c_z >> radius; s_stream >> r >> g >> b; CMaterial mat; mat.set_color(CColor(r, g, b)); CSphere* sphere = new CSphere(radius, CPoint3D(c_x, c_y, c_z), mat); m_objects.push_back(sphere); } else if(cur_s == "camera") { double p_x, p_y, p_z, v_x, v_y, v_z; s_stream >> p_x >> p_y >> p_z >> v_x >> v_y >> v_z; m_camera = CCamera(CPoint3D(p_x, p_y, p_z), CPoint3D(v_x, v_y, v_z)); } else if(cur_s == "lighter") { double i, p_x, p_y, p_z; s_stream >> i >> p_x >> p_y >> p_z; m_lighters.push_back(CLighter(CPoint3D(p_x, p_y, p_z), i)); } else if(cur_s == "triangle") { double p_x1, p_y1, p_z1, p_x2, p_y2, p_z2, p_x3, p_y3, p_z3; int r, g, b; s_stream >> p_x1 >> p_y1 >> p_z1 >> p_x2 >> p_y2 >> p_z2 >> p_x3 >> p_y3 >> p_z3; s_stream >> r >> g >> b; CMaterial mat; mat.set_color(CColor(r, g, b)); std::vector<CPoint3D> vec = { CPoint3D(p_x1, p_y1, p_z1), CPoint3D(p_x2, p_x2, p_z2), CPoint3D(p_x3, p_y3, p_z3) };