public static warp_Camera TOP() { warp_Camera cam = new warp_Camera(); cam.setPos(0, -2f, 0); return(cam); }
public static warp_Camera RIGHT() { warp_Camera cam = new warp_Camera(); cam.setPos(-2f, 0, 0); return(cam); }
public static warp_Camera FRONT() { warp_Camera cam = new warp_Camera(); cam.setPos(0, 0, -2f); return(cam); }
public void destroy() { objects = objectData.Count; foreach (warp_Object o in objectData.Values) { o.destroy(); } objectData.Clear(); lightData.Clear(); materialData.Clear(); cameraData.Clear(); if (renderPipeline != null) { renderPipeline.Dispose(); } renderPipeline = null; environment = null; defaultCamera = null; wobject = null; }
public void render(warp_Camera cam) { rasterizer.rebuildReferences(this); warp_Math.clearBuffer(zBuffer, zFar); //System.Array.Copy(screen.zBuffer,0,zBuffer,0,zBuffer.Length); if (scene.environment.background != null) { screen.drawBackground(scene.environment.background, 0, 0, screen.width, screen.height); } else { screen.clear(scene.environment.bgcolor); } cam.setScreensize(screen.width, screen.height); scene.prepareForRendering(); emptyQueues(); // Project warp_Matrix m = warp_Matrix.multiply(cam.getMatrix(), scene.matrix); warp_Matrix nm = warp_Matrix.multiply(cam.getNormalMatrix(), scene.normalmatrix); warp_Matrix vertexProjection, normalProjection; warp_Object obj; warp_Triangle t; warp_Vertex v; warp_Material objmaterial; const double log2inv = 1.4426950408889634073599246810019; int w = screen.width; int h = screen.height; int minx; int miny; int maxx; int maxy; for (int id = 0; id < scene.objects; ++id) { obj = scene.wobject[id]; objmaterial = obj.material; if (objmaterial == null) { continue; } if (!obj.visible) { continue; } if (objmaterial.opaque && objmaterial.reflectivity == 0) { continue; } vertexProjection = obj.matrix.getClone(); normalProjection = obj.normalmatrix.getClone(); vertexProjection.transform(m); normalProjection.transform(nm); minx = int.MaxValue; miny = int.MaxValue; maxx = int.MinValue; maxy = int.MinValue; for (int i = 0; i < obj.vertices; ++i) { v = obj.fastvertex[i]; v.project(vertexProjection, normalProjection, cam); v.clipFrustrum(w, h); if (minx > v.x) { minx = v.x; } if (maxx < v.x) { maxx = v.x; } if (miny > v.y) { miny = v.y; } if (maxy < v.y) { maxy = v.y; } } maxx -= minx; maxy -= miny; if (maxy > maxx) { maxx = maxy + 1; } else { maxx++; } obj.projectedmaxMips = (int)Math.Ceiling((Math.Log(maxx) * log2inv)); obj.cacheMaterialData(); if (objmaterial.opaque) { rasterizer.loadFastMaterial(obj); for (int i = 0; i < obj.triangles; ++i) { t = obj.fasttriangle[i]; t.project(normalProjection); if (t.clipFrustrum(w, h)) { rasterizer.render(t); } } } else { for (int i = 0; i < obj.triangles; ++i) { t = obj.fasttriangle[i]; t.project(normalProjection); if (t.clipFrustrum(w, h)) { transparentQueue.Add(t); } } } } //screen.lockImage(); warp_Triangle[] tri; obj = null; tri = getTransparentQueue(); if (tri != null) { transparentQueue.Clear(); for (int i = 0; i < tri.GetLength(0); i++) { if (obj != tri[i].parent) { obj = tri[i].parent; rasterizer.loadFastMaterial(obj); } rasterizer.render(tri[i]); } } //screen.unlockImage(); }
public void project(warp_Matrix vertexProjection, warp_Matrix normalProjection, warp_Camera camera) // Projects this vertex into camera space { pos2 = pos.transform(vertexProjection); n2 = n.transform(normalProjection); if (pos2.z < 0.001f && pos2.z > -0.0001f) { pos2.z = 0.001f; } if (camera.isOrthographic) { x = (int)pos2.x; y = (int)pos2.y; invZ = -1.0f; tx = -u; ty = -v; } else { invZ = 1.0f / pos2.z; x = (int)(pos2.x * invZ + camera.halfscreenwidth); y = (int)(pos2.y * invZ + camera.halfscreenheight); invZ = -invZ; tx = u * invZ; ty = v * invZ; } z = (int)(65536f * pos2.z); nx = ((int)(n2.x * 127 + 127)) << 16; ny = ((int)(n2.y * 127 + 127)) << 16; }
public void addCamera(String key, warp_Camera c) { cameraData.Add(key, c); }