Пример #1
0
void drawCharByParams(int x, int z, double footy, int n) {
    MD2Model::Pose pose(MD2Model::STAND, n + gameTime);

    CoordinateFrame cframe(
        Matrix3::fromAxisAngle(Vector3::UNIT_Y, n * .5 + 4),
        Vector3(x * 6 + (z % 2) * 2, -footy, z * 6));

    if (modelTexture.size() > 0) {
        renderDevice->setTexture(0,
            modelTexture[(n + 1 + z * 2) % modelTexture.size()]);
    }

    drawCharWithShadow(cframe, pose);
}
Пример #2
0
/**
 * @brief Convert NAIF code to frame or body name
 *
 * This routine will convert a NAIF integer code to either the frame (first) or
 * body (second) name.
 *
 * @author kbecker (3/26/2011)
 *
 * @param naifid NAIF integer code to convert to a name
 *
 * @return QString Returns the frame or body name.
 */
QString SpiceSegment::getNaifName(int naifid) const {
  SpiceChar naifBuf[40];
  frmnam_c ( (SpiceInt) naifid, sizeof(naifBuf), naifBuf);
  string cframe(naifBuf);

  if ( cframe.empty() ) {
    SpiceBoolean found;
    bodc2n_c((SpiceInt) naifid, sizeof(naifBuf), naifBuf, &found);
    if ( found ) cframe = naifBuf;
  }

  // If it fails, just report it missing
  if ( cframe.empty() ) {
    string mess = "Failed to convert FrameId (" + IString(naifid) +
                  ") to string - perhaps the frame kernel is missing or not" +
                  " loaded.";
    cframe = "_UNKNOWN_";
  //  throw iException::Message(iException::User, mess.c_str(), _FILEINFO_);
  }


  return (cframe.c_str());
}
Пример #3
0
void Demo::onGraphics(RenderDevice* rd) {

    rd->clear(sky == NULL, true, false);
    rd->setProjectionAndCameraMatrix(app->debugCamera);
    LightingParameters lighting(gameTime, false);

    if (sky.notNull()) {
       sky->render(rd, lighting);
    }
                    
    rd->pushState();
        // Setup lighting
        rd->setSpecularCoefficient(1);
        rd->setShininess(64);
        debugAssertGLOk();
        rd->enableLighting();
        rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor));
        rd->setLight(1, GLight::directional(-lighting.lightDirection, Color3::white() * .25, false));
        rd->setAmbientLightColor(lighting.ambient);

        rd->setShadeMode(RenderDevice::SHADE_SMOOTH);

        static const Color3 color[] = {Color3::black(), Color3::white(), Color3::orange(), Color3::blue()};
        double  t[2];
        Vector3 c[2];

        t[0] = System::time();
        t[1] = t[0] + 0.01;

		// Draw the planes
        for (int x = 0; x < N; ++x) {

            for (int i = 0; i < 2; ++i) {
                double a = x + t[i] + 2; 
                double a2 = t[i] * (x + 1) * .01 + 1005.1;
                c[i] = Vector3(cos(a) * (10 + x / 2.0), sin(a2) * 10, sin(a) * 15);
            }

            CoordinateFrame cframe(c[0]);

            double a = t[0] * (x + 1) * .1; 
            cframe.lookAt(c[1], Vector3(cos(a), 3, sin(a)).direction());


            rd->setColor(color[x % 4]);
            model->render(rd, cframe, lighting, varStream);
        }
    rd->popState();


    if (sky.notNull()) {
        sky->renderLensFlare(rd, lighting);
    }
    
    rd->push2D();
        char* str = NULL;
        switch (renderMethod) {
        case TRIANGLES:
            str = "Using begin/end (SPACE to change)";
            break;

        case VARSTREAM:
            str = "Using streaming vertex array (SPACE to change)";
            break;

        case VARSTATIC:
            str = "Using static vertex array (SPACE to change)";
            break;

        default:;
        }

       app->debugFont->draw2D(rd, str, Vector2(10, rd->height() - 40), 20, Color3::yellow(), Color3::black());

    rd->pop2D();

    debugAssertGLOk();    
    varStream->reset();
}
Пример #4
0
void doGraphics() {

    bool screenshot = singleScreen || batchScreen;

    LightingParameters lighting(G3D::toSeconds(10, 00, 00, AM));

    // Some models have part of their geometry stored in the "weapon" file.
    // Darth Maul, for example, has his lower half in the weapon.
    const double footy = 0.98 *
            min(model.boundingBox(MD2Model::STAND).getCorner(0).y, 
                weapon.boundingBox(MD2Model::STAND).getCorner(0).y);

    renderDevice->beginFrame();
        renderDevice->clear(true, true, true);
        renderDevice->pushState();
			    
		    camera->setProjectionAndCameraMatrix();
            
            beginLighting(lighting);

                int n = 1;
            
                if (!screenshot) {
                    // Draw a bunch of characters
                    for (int z = 0; z < 6; ++z) {
                        for (int x = -2; x <= 2; ++x) {
                            drawCharByParams(x, z, footy, n);
                            ++n;
                        }
                    }
                }

                // Draw the main character
                {
                    CoordinateFrame cframe(Vector3(0, -footy, -8));
                
                    if (modelTexture.size() > 0) {
                        renderDevice->setTexture(0, modelTexture.last());
                    }

                    // use global pose variable
                    drawCharWithShadow(cframe, pose);
                }

            endLighting();

            renderDevice->setObjectToWorldMatrix(CoordinateFrame());
        
            // Ground plane (to hide parts of characters that stick through ground)
            renderDevice->setColor(Color3::WHITE);
            renderDevice->beginPrimitive(RenderDevice::QUADS);
                renderDevice->sendVertex(Vector3(-50, -.01, 50));
                renderDevice->sendVertex(Vector3(50, -.01, 50));
                renderDevice->sendVertex(Vector3(50, -.01, -50));
                renderDevice->sendVertex(Vector3(-50, -.01, -50));
            renderDevice->endPrimitive();
        renderDevice->popState();

        renderDevice->push2D();
            double x = 10;
            double y = 10;
            double f = 16;
            int fontSize = (batchScreen) ? (22) : (30);
            font->draw2DString(model.name, renderDevice->getWidth()/2, 
                renderDevice->getHeight() - 45, fontSize, Color3::BLACK, Color3::WHITE, GFont::XALIGN_CENTER);

            if (!screenshot) {
                font->draw2DString(format("%d fps", 
iRound(renderDevice->getFrameRate())), x, y, 20, Color3::YELLOW, Color3::BLACK); y += 30;
                font->draw2DString(format("%d characters", n), x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString(format("%1.1f MB", model.mainMemorySize() / 1e6), x, 
y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5;
                font->draw2DString(format("%1.0f Mtris/sec", 
renderDevice->getTriangleRate() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5;

                x = renderDevice->getWidth() - 130;
                y = 10;
                f = 12;
                font->draw2DString("CLICK   attack", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("SPACE  jump", x, y, f, Color3::CYAN, Color3::BLACK); 
y += f * 1.5;
                font->draw2DString("CTRL     crouch", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("1 . . 5    taunt", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("6 . . 8    die", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("9 . . -    pain", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("R/T       run/back", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("E           new character", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
                font->draw2DString("Z           single screen", x, y, f, Color3::CYAN, 
Color3::BLACK); y += f * 1.5;
            }
        renderDevice->pop2D();
	   
    renderDevice->endFrame();
}
Пример #5
0
void App::setViewer(const std::string& newFilename) {
    logPrintf("App::setViewer(\"%s\")\n", filename.c_str());
    drawMessage("Loading " + newFilename);
    filename = newFilename;

    CFrame cframe(Vector3(0,8,15));
    cframe.lookAt(Point3::zero());
    m_debugCamera->setFrame(cframe);
    m_debugController->setFrame(m_debugCamera->frame());

    //modelController->setFrame(CoordinateFrame(Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(180))));
    delete viewer;
    viewer = NULL;

    if (filename == "<events>") {
        viewer = new EventViewer();
    } else {
        std::string ext = toLower(filenameExt(filename));
        std::string base = toLower(filenameBase(filename));
        
        if ((ext == "3ds")  ||
            (ext == "ifs")  ||
            (ext == "obj")  ||
            (ext == "ply2") ||
            (ext == "off")  ||
            (ext == "ply")  ||
            (ext == "bsp")  ||
            (ext == "stl")  ||
            (ext == "stla") ||
            (ext == "dae")  ||
            (ext == "fbx")  ||
            ((ext == "any" && endsWith(base, ".am")) || (ext == "any" && endsWith(base, ".articulatedmodel")))) {
            
            showDebugText = false;
            viewer = new ArticulatedViewer();
            
        } else if (Texture::isSupportedImage(filename)) {
            
            // Images can be either a Texture or a Sky, TextureViewer will figure it out
            viewer = new TextureViewer();
            
            // Angle the camera slightly so a sky/cube map doesn't see only 1 face
            m_debugController->setFrame(Matrix3::fromAxisAngle(Vector3::unitY(), (float)halfPi() / 2.0f) * Matrix3::fromAxisAngle(Vector3::unitX(), (float)halfPi() / 2.0f));
            
        } else if (ext == "fnt") {
            
            viewer = new FontViewer(debugFont);
            
/*        } else if (ext == "bsp") {
            
            viewer = new BSPViewer();
  */          
        } else if (ext == "md2") {
            
            viewer = new MD2Viewer();
            
        } else if (ext == "md3") {

            viewer = new MD3Viewer();

        } else if (ext == "gtm") {
            
            viewer = new GUIViewer(this);
            
        } else if (ext == "icn") {
            
            viewer = new IconSetViewer(debugFont);
            
        } else if (ext == "pk3") {
            // Something in Quake format - figure out what we should load
            Array <std::string> files;
            bool set = false;
            
            // First, try for a .bsp map
            std::string search = filename + "/maps/*";
            FileSystem::getFiles(search, files, true);
            
            for (int t = 0; t < files.length(); ++t) {
                
                if (filenameExt(files[t]) == "bsp") {
                    
                    filename = files[t];
                    viewer = new ArticulatedViewer();
//                    viewer = new BSPViewer();
                    set = true;
                }
            }
            if (! set) {
                viewer = new EmptyViewer();
            }
            
        } else if (ext == "avi" || ext == "wmv" || ext == "mp4" || ext == "asf" || 
                   (ext == "mov") || (ext == "dv") || (ext == "qt") || (ext == "asf") ||
                   (ext == "mpg")) {
            viewer = new VideoViewer();
            
        } else {
            
            viewer = new EmptyViewer();
            
        }
    }
    
    if (viewer != NULL) {
        viewer->onInit(filename);
    }
    
    if (filename != "") {
        if (filename == "<events>") {
            window()->setCaption("Events - G3D Viewer");
        } else {
            window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer");
        } 
    }
    
    logPrintf("Done App::setViewer(...)\n");
}