static bool Init() { graphics = new GraphicsContext(); //Window size: Change if Tablet, default is Vita graphics.SetViewport(0, 0, graphics.Screen.Width, graphics.Screen.Height); //Background Color Set graphics.SetClearColor(0.0f, 0.0f, 0.0f, 0.0f); program = new ShaderProgram("/Application/shaders/VertexColor.cgx"); program.SetUniformBinding(0, "WorldViewProj"); //Detect if processing shadow or not program.SetUniformBinding(1, "ShadowOn"); program.SetUniformBinding(2, "LocalLightDirection"); program.SetUniformBinding(3, "EyePosition"); program.SetUniformBinding(4, "K_A"); program.SetUniformBinding(5, "K_D"); program.SetUniformBinding(6, "K_S"); program.SetUniformBinding(7, "Shininess"); program.SetUniformBinding(8, "Modelmatrix"); program.SetUniformBinding(9, "ModelmatrixIT"); program.SetUniformBinding(10, "viewMatrix"); program.SetUniformBinding(11, "projMatrix"); program.SetAttributeBinding(0, "a_Position"); program.SetAttributeBinding(1, "a_Color"); //Select Model //model = new Model("house"); model = new Model("skull"); //Set buffers to hold position data vbuffer = model.SetBuffer(); //Find size of model to be used in camera positioning model.computeModelDimensions(); //Set Light Vector light = new Light(model.centerX-model.diagonal*1.5f, model.centerY+model.diagonal*1.5f, 0); Console.WriteLine (light.light.X + " " + light.light.Y + " " + light.light.Z); stopwatch = new Stopwatch(); stopwatch.Start(); //Required to render model without holes graphics.Enable (EnableMode.DepthTest); graphics.Enable(EnableMode.CullFace); graphics.SetCullFace(CullFaceMode.Front, CullFaceDirection.Cw); return true; }
public float[] computeModelDimensions(Model model) { float xmin, xmax, ymin, ymax, zmin, zmax; int k; bool firstvertex = true; for (k=0; k<model.count; k++){ Matrix4 m = model.modelMatrix[k]; float[] pos = GetPos("Part_"+k); for(int i = 0; i< pos.Length; i++){ if(firstvertex){ xmin = xmax = pos[0]; ymin = ymin = pos[1]; zmin = zmax = pos[2]; firstvertex = false; } } } float[] result = new float[xmin, ymin, zmin, xmax, ymax, zmax]; Console.WriteLine(result); return result; }