void Model_Impl::insert_vbo(int vertex_count, const struct aiScene* sc, const struct aiNode* nd) { int i; unsigned int n = 0, t; bool use_texcoords = !vbo_texcoords.is_null(); // All meshes assigned to this node for (; n < nd->mNumMeshes; ++n) { const struct aiMesh* mesh = sc->mMeshes[nd->mMeshes[n]]; int num_vertex = mesh->mNumFaces * 3; if (!num_vertex) continue; std::vector<CL_Vec3f> normals; std::vector<CL_Vec3f> vertices; std::vector<CL_Vec2f> tex_coords; normals.reserve(num_vertex); vertices.reserve(num_vertex); if (use_texcoords) { if (mesh->mTextureCoords == NULL || mesh->mTextureCoords[0] == NULL) throw CL_Exception("This example expects texcoords to be set for this object"); tex_coords.reserve(num_vertex); } for (t = 0; t < mesh->mNumFaces; ++t) { const struct aiFace* face = &mesh->mFaces[t]; if (face->mNumIndices != 3) throw CL_Exception("This example only supports triangles"); for(i = 0; i < face->mNumIndices; i++) { int index = face->mIndices[i]; normals.push_back(CL_Vec3f(&mesh->mNormals[index].x)); vertices.push_back( CL_Vec3f(&mesh->mVertices[index].x)); if (use_texcoords) tex_coords.push_back( CL_Vec2f(&mesh->mTextureCoords[0][index].x)); } } vbo_positions.upload_data(vertex_count * sizeof(CL_Vec3f), &vertices[0], num_vertex * sizeof(CL_Vec3f)); vbo_normals.upload_data(vertex_count * sizeof(CL_Vec3f), &normals[0], num_vertex * sizeof(CL_Vec3f)); if (use_texcoords) vbo_texcoords.upload_data(vertex_count * sizeof(CL_Vec2f), &tex_coords[0], num_vertex * sizeof(CL_Vec2f)); vertex_count += num_vertex; } // All children for (n = 0; n < nd->mNumChildren; ++n) { insert_vbo(vertex_count, sc, nd->mChildren[n]); } }
void App::create_scene(CL_GraphicContext &gc) { std::vector<CL_Collada_Image> library_images; Model model_cone("../SpotLight/Resources/cone.dae", library_images); Model model_teapot("../Clan3D/Resources/teapot.dae", library_images); camera = new SceneObject(scene, scene.base); camera->position = CL_Vec3f(-20.0f, 40.0f, -60.0f); camera->rotation_x = CL_Angle(20.0f, cl_degrees); light_distant = new SceneObject(scene, scene.base); light_distant->model = model_cone; light_distant->position = CL_Vec3f(0.0f, 32.0f, 20.0f); // Note, these are updated by the options light_distant->rotation_y = CL_Angle(45.0f, cl_degrees); light_distant->rotation_x = CL_Angle(35.0f, cl_degrees); teapot = new SceneObject(scene, scene.base); teapot->model = model_teapot; teapot->position = CL_Vec3f(-2.5f, 0.0f, 20.0f); teapot->scale = CL_Vec3f(50.0f, 50.0f, 50.0f); scene.gs->LoadImages(gc, library_images); }
void App::create_scene(CL_GraphicContext &gc) { camera = new SceneObject(scene, scene.base); camera->position = CL_Vec3f(0.0f, 50.0f, -20.0f); camera->rotation_y = CL_Angle(0.0f, cl_degrees); object_particles = new ParticleObject(gc, scene, scene.base); object_particles->position = CL_Vec3f(-110.0f, 54.0f, -5.0f); object_particles->rotation_y = CL_Angle(0.0f, cl_degrees); object_particles->rotation_x = CL_Angle(0.0f, cl_degrees); object_particles->rotation_z = CL_Angle(0.0f, cl_degrees); object_particles->scale = CL_Vec3f(1.0f, 1.0f, 1.0f); }
inline CL_Vec3f CL_RenderBatch3D::to_position(float x, float y) const { return CL_Vec3f( modelview.matrix[0*4+0]*x + modelview.matrix[1*4+0]*y + modelview.matrix[3*4+0], modelview.matrix[0*4+1]*x + modelview.matrix[1*4+1]*y + modelview.matrix[3*4+1], modelview.matrix[0*4+2]*x + modelview.matrix[1*4+2]*y + modelview.matrix[3*4+2]); }
inline CL_Vec3f CL_RenderBatch2D::to_position(float x, float y) const { return CL_Vec3f( origin.x + x_dir.x * x + y_dir.x * y, origin.y + x_dir.y * x + y_dir.y * y, 1.0f); }
CL_Rectf RotateRect(CL_Rect r, float angleDegrees, CL_Vec2f srcScreenSize) { //Clanlib is missing functions for CL_Mat2 and CL_Vec2f.. so I'll do it this way.. CL_Mat4f mat = CL_Mat4f::rotate(CL_Angle(-angleDegrees, cl_degrees), 0,0,1); switch ((int)angleDegrees) { case 90: mat = mat * CL_Mat4f::translate(0, srcScreenSize.x, 0); break; case 180: mat = mat * CL_Mat4f::translate(srcScreenSize.x, srcScreenSize.y, 0); break; case 270: mat = mat * CL_Mat4f::translate(srcScreenSize.y, 0, 0); break; case 0: break; default: assert(!"Unsupported angle.. uh.."); } //apply CL_Vec3f v; v = mat.get_transformed_point(CL_Vec3f((float)r.left, (float)r.top, 0.0f)); r.left = (int)v.x; r.top = (int)v.y; v = mat.get_transformed_point(CL_Vec3f((float)r.right, (float)r.bottom, 0.0f)); r.right = (int)v.x; r.bottom = (int)v.y; r.normalize(); return r; }
ShaderBumpMap::ShaderBumpMap(CL_GraphicContext &gc) { CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } program_object = CL_ProgramObject(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(0, "InPosition"); program_object.bind_attribute_location(1, "InNormal"); program_object.bind_attribute_location(2, "InTexCoord0"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } material_updated = false; light_updated = false; material_shininess = 64.0f; material_emission = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f); material_ambient = CL_Vec4f(1.0f, 0.0f, 0.0f, 1.0f); material_specular = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f); light_ambient = CL_Vec4f(0.2f, 0.2f, 0.2f, 1.0f); light_vector = CL_Vec3f(0.0f, 0.0f, 1.0f); light_specular = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); light_diffuse = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); program_object.set_uniform1i("Texture0", 0); program_object.set_uniform1i("Texture1", 1); }
void App::control_camera() { camera_angle += ((float) time_delta) / 20.0f; if (camera_angle > 360.0f) { camera_angle -= 360.0f; } float camera_angle_rad = (camera_angle * CL_PI) / 180.0f; float radius = 50.0f; float xpos = cos(camera_angle_rad) * radius; float zpos = sin(camera_angle_rad) * radius; camera->position = CL_Vec3f(xpos, 50.0f, zpos); camera->rotation_x = CL_Angle(20.0f, cl_degrees); camera->rotation_y = CL_Angle(-(camera_angle+90.0f), cl_degrees); }
void App::update_light(CL_GraphicContext &gc, Options *options) { CL_Mat4f light_modelview_matrix = CL_Mat4f::identity(); light_distant->GetWorldMatrix(light_modelview_matrix); CL_Mat4f work_matrix = scene.gs->camera_modelview; work_matrix.multiply(light_modelview_matrix); // Clear translation work_matrix.matrix[0+3*4] = 0.0f; work_matrix.matrix[1+3*4] = 0.0f; work_matrix.matrix[2+3*4] = 0.0f; CL_Vec4f light_vector = work_matrix.get_transformed_point(CL_Vec3f(0.0f, 0.0f, -1.0f)); CL_Vec4f light_specular(options->light_specular_color.r, options->light_specular_color.g, options->light_specular_color.b, options->light_specular_color.a); CL_Vec4f light_diffuse(options->light_diffuse_color.r, options->light_diffuse_color.g, options->light_diffuse_color.b, options->light_diffuse_color.a); CL_Vec4f light_ambient(options->light_ambient_color.r, options->light_ambient_color.g, options->light_ambient_color.b, options->light_ambient_color.a); scene.gs->shader_color.SetLight(light_vector, light_specular, light_diffuse, light_ambient); }
void ObjectPolygon::CalcNormal(void) { if (m_NumVertex < 3) { m_Normal = CL_Vec3f(0.0f, 0.0f, 0.0f); return; } CL_Vec3f point_a; CL_Vec3f point_b; point_a.x = m_pVertex[0].m_Point.x - m_pVertex[2].m_Point.x; point_a.y = m_pVertex[0].m_Point.y - m_pVertex[2].m_Point.y; point_a.z = m_pVertex[0].m_Point.z - m_pVertex[2].m_Point.z; point_b.x = m_pVertex[1].m_Point.x - m_pVertex[2].m_Point.x; point_b.y = m_pVertex[1].m_Point.y - m_pVertex[2].m_Point.y; point_b.z = m_pVertex[1].m_Point.z - m_pVertex[2].m_Point.z; CL_Vec3f point_cross; point_cross.x = point_a.y * point_b.z - point_a.z * point_b.y; point_cross.y = point_a.z * point_b.x - point_a.x * point_b.z; point_cross.z = point_a.x * point_b.y - point_a.y * point_b.x; float size; size = (point_cross.x) * (point_cross.x); size += (point_cross.y) * (point_cross.y); size += (point_cross.z) * (point_cross.z); if (size > 0.0f) { size = sqrt(size); point_cross.x /= size; point_cross.y /= size; point_cross.z /= size; } m_Normal = point_cross; }
void App::update_light(CL_GraphicContext &gc) { CL_Mat4f light_modelview_matrix = CL_Mat4f::identity(); light->GetWorldMatrix(light_modelview_matrix); CL_Mat4f work_matrix = scene.gs->camera_modelview; work_matrix.multiply(light_modelview_matrix); // Clear translation work_matrix.matrix[0+3*4] = 0.0f; work_matrix.matrix[1+3*4] = 0.0f; work_matrix.matrix[2+3*4] = 0.0f; CL_Vec4f light_vector = work_matrix.get_transformed_point(CL_Vec3f(0.0f, 0.0f, -1.0f)); CL_Vec4f light_specular(0.5f, 0.5f, 0.5f, 1.0f); CL_Vec4f light_diffuse(0.5f, 0.5f, 0.5f, 1.0f); scene.gs->shader_texture.SetLight(light_vector, light_specular, light_diffuse); scene.gs->shader_color.SetLight(light_vector, light_specular, light_diffuse); }
void App::create_shooter( const CL_InputEvent &key, const CL_StringRef &str, bool use_red, bool use_green, bool use_blue) { // Set the firing line CL_Vec3f vector(0.0f, 0.0f, 20.0f); CL_GraphicContext gc = window.get_gc(); float width = (float) gc.get_width(); float height = (float) gc.get_height(); vector.x = ((key.mouse_pos.x - width/2)* 10.0f) / width; vector.y = -((key.mouse_pos.y - height/2) * 10.0f) / height; // Create the text offset TextShooter shooter(vector_font, str); shooter.set_start_time(CL_System::get_time()); shooter.set_duration(2 * 1000); shooter.set_initial_white_time(1000); shooter.set_end_fade_time(1000); shooter.set_start_position(CL_Vec3f(0.0f, 0.0f, 0.2f)); shooter.set_end_position(vector); shooter.set_color_component(use_red, use_green, use_blue); text_shooter.push_back(shooter); }
Shader::Shader(CL_GraphicContext &gc) { CL_ShaderObject vertex_shader(gc, cl_shadertype_vertex, vertex); if(!vertex_shader.compile()) { throw CL_Exception(cl_format("Unable to compile vertex shader object: %1", vertex_shader.get_info_log())); } CL_ShaderObject fragment_shader(gc, cl_shadertype_fragment, fragment); if(!fragment_shader.compile()) { throw CL_Exception(cl_format("Unable to compile fragment shader object: %1", fragment_shader.get_info_log())); } program_object = CL_ProgramObject(gc); program_object.attach(vertex_shader); program_object.attach(fragment_shader); program_object.bind_attribute_location(cl_attrib_position, "InPosition"); program_object.bind_attribute_location(cl_attrib_normal, "InNormal"); program_object.bind_attribute_location(cl_attrib_color, "InMaterialAmbient"); program_object.bind_attribute_location(cl_attrib_texture_position, "InTextureCoords"); if (!program_object.link()) { throw CL_Exception(cl_format("Unable to link program object: %1", program_object.get_info_log())); } material_shininess = 64.0f; material_emission = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f); material_specular = CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f); light_position = CL_Vec3f(0.0f, 0.0f, 1.0f); light_specular = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); light_diffuse = CL_Vec4f(0.7f, 0.7f, 0.7f, 1.0f); }
std::vector<CL_Lib3dsMesh> CL_Lib3dsFile::export_meshes(Lib3dsNode *node) { if (node == 0) { lib3ds_file_eval(file, 0.0f); node = file->nodes; } std::vector<CL_Lib3dsMesh> meshes; for (; node; node = node->next) { if (node->type == LIB3DS_NODE_MESH_INSTANCE) { Lib3dsMeshInstanceNode *instance_node = (Lib3dsMeshInstanceNode *) node; Lib3dsMesh *mesh = lib3ds_file_mesh_for_node(file, (Lib3dsNode*)node); if (mesh && mesh->vertices) { float inv_matrix[4][4], M[4][4]; lib3ds_matrix_copy(M, instance_node->base.matrix); lib3ds_matrix_translate(M, -instance_node->pivot[0], -instance_node->pivot[1], -instance_node->pivot[2]); lib3ds_matrix_copy(inv_matrix, mesh->matrix); lib3ds_matrix_inv(inv_matrix); lib3ds_matrix_mult(M, M, inv_matrix); std::vector<CL_Vec3f> positions; for (int i = 0; i < mesh->nvertices; ++i) { float position[3]; lib3ds_vector_transform(position, M, mesh->vertices[i]); positions.push_back(CL_Vec3f(position[0], position[1], position[2])); } std::vector<CL_Vec2f> texcoords; if (mesh->texcos) { for (int i = 0; i < mesh->nvertices; ++i) { float tx = mesh->texcos[i][0]; float ty = mesh->texcos[i][1]; texcoords.push_back(CL_Vec2f(tx, ty)); } } std::vector<CL_Vec3f> normals; if (mesh->faces && mesh->nfaces > 0) { float (*normals_array)[3] = (float(*)[3])malloc(sizeof(float) * 9 * mesh->nfaces); lib3ds_mesh_calculate_vertex_normals(mesh, normals_array); for (int i = 0; i < 3 * mesh->nfaces; ++i) { normals.push_back(CL_Vec3f(normals_array[i][0], normals_array[i][1], normals_array[i][2])); } free(normals_array); } CL_Lib3dsMesh mesh_object; for (int i = 0; i < mesh->nfaces; ++i) { int material_index = mesh->faces[i].material; mesh_object.face_materials.push_back(material_index); for (int j = 0; j < 3; ++j) { int vertex_index = mesh->faces[i].index[j]; mesh_object.positions.push_back(positions[vertex_index]); if (!texcoords.empty()) mesh_object.texcooords.push_back(texcoords[vertex_index]); if (!normals.empty()) mesh_object.normals.push_back(normals[i*3+j]); } } meshes.push_back(mesh_object); } if (node->childs) { std::vector<CL_Lib3dsMesh> child_meshes = export_meshes(node->childs); meshes.insert(meshes.end(), child_meshes.begin(), child_meshes.end()); } } } return meshes; }
void TestApp::test_line_segment3() { CL_Console::write_line(" Header: line_segment.h"); CL_Console::write_line(" Class: CL_LineSegment3"); CL_Console::write_line(" Function: get_midpoint()"); { CL_LineSegment3f line_a(CL_Vec3f(2.0f, 8.0f, 1.0f), CL_Vec3f(4.0f, 20.0f, 3.0f)); if (line_a.get_midpoint() != CL_Vec3f(3.0f, 14.0f, 2.0f) ) fail(); } CL_Console::write_line(" Function: point_distance()"); { CL_LineSegment3f line_a(CL_Vec3f(1.0f, 0.0f, 0.0f), CL_Vec3f(9.0f, 0.0f, 0.0f)); CL_Vec3f point; CL_Vec3f intercept; float distance; point = CL_Vec3f(-1.0f, 0.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(1.0f, 0.0f, 0.0f) ) fail(); point = CL_Vec3f(6.0f, 0.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 0.0f ) fail(); if (intercept != CL_Vec3f(6.0f, 0.0f, 0.0f) ) fail(); point = CL_Vec3f(11.0f, 0.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(9.0f, 0.0f, 0.0f) ) fail(); line_a = CL_LineSegment3f(CL_Vec3f(0.0f, 1.0f, 0.0f), CL_Vec3f(0.0f, 9.0f, 0.0f)); point = CL_Vec3f(0.0f, -1.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 1.0f, 0.0f) ) fail(); point = CL_Vec3f(0.0f, 6.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 0.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 6.0f, 0.0f) ) fail(); point = CL_Vec3f(0.0f, 11.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 9.0f, 0.0f) ) fail(); line_a = CL_LineSegment3f(CL_Vec3f(0.0f, 0.0f, 1.0f), CL_Vec3f(0.0f, 0.0f, 9.0f)); point = CL_Vec3f(0.0f, 0.0f, -1.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 0.0f, 1.0f) ) fail(); point = CL_Vec3f(0.0f, 0.0f, 6.0f); distance = line_a.point_distance(point, intercept); if (distance != 0.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 0.0f, 6.0f) ) fail(); point = CL_Vec3f(0.0f, 0.0f, 11.0f); distance = line_a.point_distance(point, intercept); if (distance != 2.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 0.0f, 9.0f) ) fail(); line_a = CL_LineSegment3f(CL_Vec3f(0.0f, 1.0f, 0.0f), CL_Vec3f(0.0f, 9.0f, 0.0f)); point = CL_Vec3f(25.0f, 5.0f, 0.0f); distance = line_a.point_distance(point, intercept); if (distance != 25.0f ) fail(); if (intercept != CL_Vec3f(0.0f, 5.0f, 0.0f) ) fail(); } }
CL_Vec3f TimelineEvent::getEmitterLocationOffset() const { return CL_Vec3f(0, 0, 0); }
void App::create_scene(CL_GraphicContext &gc) { Model model_teapot(gc, "../Clan3D/Resources/teapot.dae", true); Model model_landscape(gc, "Resources/land.dae", false); Model model_tree(gc, "Resources/tree.dae", false); Model model_gear(gc, "../Clan3D/Resources/gear.dae", false); model_teapot.SetMaterial( 32.0f, // shininess CL_Vec4f(0.0f, 0.0f, 0.0f, 1.0f), // emission CL_Vec4f(1.5f, 1.5f, 0.5f, 1.0f), // ambient CL_Vec4f(0.5f, 0.5f, 0.5f, 1.0f) ); // specular camera = new SceneObject(scene, scene.base); camera->position = CL_Vec3f(0.0f, 50.0f, -20.0f); camera->rotation_y = CL_Angle(0.0f, cl_degrees); camera->scale = CL_Vec3f(1.0f, 1.0f, 1.0f); light = new SceneObject(scene, scene.base); light->position = CL_Vec3f(-20.4732f, 48.7872f, -20.5439f); light->rotation_y = CL_Angle(45.0f, cl_degrees); light->rotation_x = CL_Angle(35.0f, cl_degrees); light->scale = CL_Vec3f(1.0f, 1.0f, 1.0f); SceneObject *object_landscape = new SceneObject(scene, scene.base); object_landscape->model = model_landscape; object_landscape->position = CL_Vec3f(0.0f, 0.0f, 0.0f); object_teapot1 = new SceneObject(scene, object_landscape); object_teapot1->model = model_teapot; object_teapot1->position = CL_Vec3f(-8.2f, 37.3f, 8.0f); object_teapot1->scale = CL_Vec3f(8.0f, 8.0f, 8.0f); object_teapot2 = new SceneObject(scene, object_landscape); object_teapot2->model = model_teapot; object_teapot2->position = CL_Vec3f(2.0f, 40.0f, 1.0f); object_teapot2->scale = CL_Vec3f(8.0f, 8.0f, 8.0f); SceneObject *object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-7.2701f, 25.58f, -9.0932f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-11.829f, 25.8125f, 0.0f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(-5.0f, 27.6963f, 0.0f); object_tree = new SceneObject(scene, object_landscape); object_tree->model = model_tree; object_tree->position = CL_Vec3f(0.0f, 29.4237f, 0.0f); object_gear = new SceneObject(scene, object_landscape); object_gear->model = model_gear; object_gear->position = CL_Vec3f(10.0f, 40.58f, 10.0); object_gear->scale = CL_Vec3f(3.0f, 3.0f, 3.0f); scene.gs->LoadImages(gc); }
gc.set_texture(0, skybox_texture); gc.set_program_object(program_object); program_object.set_uniform1i(("texture1"), 0); CL_PrimitivesArray prim_array(gc); prim_array.set_attributes(0, positions); gc.draw_primitives(cl_triangles, 6*6, prim_array); gc.reset_program_object(); gc.reset_texture(0); } CL_Vec3f Skybox::positions[6*6] = { CL_Vec3f(-0.5f, 0.5f, 0.5f), CL_Vec3f( 0.5f, 0.5f, 0.5f), CL_Vec3f( 0.5f, -0.5f, 0.5f), CL_Vec3f( 0.5f, -0.5f, 0.5f), CL_Vec3f(-0.5f, -0.5f, 0.5f), CL_Vec3f(-0.5f, 0.5f, 0.5f), CL_Vec3f( 0.5f, -0.5f, -0.5f), CL_Vec3f( 0.5f, 0.5f, -0.5f), CL_Vec3f(-0.5f, 0.5f, -0.5f), CL_Vec3f(-0.5f, 0.5f, -0.5f), CL_Vec3f(-0.5f, -0.5f, -0.5f), CL_Vec3f( 0.5f, -0.5f, -0.5f),
void Effect::setAtPosition(unsigned int x, unsigned int y, int z) { setLocation(CL_Vec3f(x, y, z)); effectType_ = TYPE_AT_POSITION; }
void App::create_cube( std::vector<CL_Vec3f> &object_positions, std::vector<CL_Vec3f> &object_normals, std::vector<CL_Vec4f> &object_material_ambient ) { CL_Vec3f position; position.x = (float) ((rand() & 0x1FF) - 0xFF); position.y = (float) ((rand() & 0x1FF) - 0xFF); position.z = (float) ((rand() & 0x1FF) - 0xFF); CL_Vec4f material_ambient; material_ambient.r = ((float) (rand() & 0xFF)) / 255.0f; material_ambient.g = ((float) (rand() & 0xFF)) / 255.0f; material_ambient.b = ((float) (rand() & 0xFF)) / 255.0f; material_ambient.a = 1.0f; CL_Vec3f size(5.0f, 5.0f, 5.0f); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(-size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, -size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, size.z) +position); object_positions.push_back(CL_Vec3f(size.x, -size.y, -size.z) +position); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(-1.0f, 0.0f, 0.0f)); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(0.0f, 0.0f, 1.0f)); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(0.0f, 1.0f, 0.0f)); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(0.0f, 0.0f, -1.0f)); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(0.0f, -1.0f, 0.0f)); for (int cnt=0; cnt<6; cnt++) object_normals.push_back(CL_Vec3f(1.0f, 0.0f, 0.0f)); for (int cnt=0; cnt<36; cnt++) object_material_ambient.push_back(material_ambient); }
CL_Vec3f hsv_to_rgb( float h, float s, float v ) { float r, g, b; int i; // Make sure our arguments stay in-range h = std::max(0.0f, std::min(1.0f, h)); s = std::max(0.0f, std::min(1.0f, s)); v = std::max(0.0f, std::min(1.0f, v)); if(s == 0) { // Achromatic (grey) r = g = b = v; return CL_Vec3f(v, v, v); } h *= 6; // sector 0 to 5 i = floor(h); float f = h - i; // factorial part of h float p = v * (1 - s); float q = v * (1 - s * f); float t = v * (1 - s * (1 - f)); switch(i) { case 0: r = v; g = t; b = p; break; case 1: r = q; g = v; b = p; break; case 2: r = p; g = v; b = t; break; case 3: r = p; g = q; b = v; break; case 4: r = t; g = p; b = v; break; default: // case 5: r = v; g = p; b = q; } return CL_Vec3f( r, g, b ); }
void MotionModelStatic::get(const CL_Vec3f& emitterLocation, const CL_Vec3f& particleLocation, CL_Vec3f& outParam1, CL_Vec3f& outParam2) const { outParam1 = CL_Vec3f(0, 0, 0); outParam2 = CL_Vec3f(0, 0, 0); }