Example #1
0
static void updateCameraAcceleration(UBYTE update)
{
	Vector3i concern = swapYZ(trackingCamera.target->pos);
	Vector2i behind(0, 0); /* Irrelevant for normal radar tracking */
	bool bFlying = false;

	/*
		This is where we check what it is we're tracking.
		Were we to track a building or location - this is
		where it'd be set up
	*/
	/*
		If we're tracking a droid, then we need to track slightly in front
		of it in order that the droid appears down the screen a bit. This means
		that we need to find an offset point from it relative to it's present
		direction
	*/
	if (trackingCamera.target->type == OBJ_DROID)
	{
		const int angle = 90 - abs((player.r.x/182) % 90);

		const DROID *psDroid = (DROID*)trackingCamera.target;
		const PROPULSION_STATS *psPropStats = &asPropulsionStats[psDroid->asBits[COMP_PROPULSION].nStat];

		if (psPropStats->propulsionType == PROPULSION_TYPE_LIFT)
		{
			bFlying = true;
		}

		/* Present direction is important */
		if (getNumDroidsSelected() > 2)
		{
			unsigned group = trackingCamera.target->selected ? GROUP_SELECTED : trackingCamera.target->group;

			uint16_t multiAngle = getAverageTrackAngle(group, true);
			getTrackingConcerns(&concern.x, &concern.y, &concern.z, group, true);

			behind = iSinCosR(multiAngle, CAM_DEFAULT_OFFSET);
		}
		else
		{
			behind = iSinCosR(trackingCamera.target->rot.direction, CAM_DEFAULT_OFFSET);
		}

		concern.y += angle*5;
	}

	Vector3i realPos = concern - Vector3i(-behind.x, 0, -behind.y);
	Vector3f separation = realPos - trackingCamera.position;
	Vector3f acceleration;
	if (!bFlying)
	{
		acceleration = separation*ACCEL_CONSTANT - trackingCamera.velocity*VELOCITY_CONSTANT;
	}
	else
	{
		separation.y /= 2.0f;
		acceleration = separation*(ACCEL_CONSTANT*4) - trackingCamera.velocity*(VELOCITY_CONSTANT*2);
	}

	if (update & X_UPDATE)
	{
		/* Need to update acceleration along x axis */
		trackingCamera.acceleration.x = acceleration.x;
	}

	if (update & Y_UPDATE)
	{
		/* Need to update acceleration along y axis */
		trackingCamera.acceleration.y = acceleration.y;
	}

	if (update & Z_UPDATE)
	{
		/* Need to update acceleration along z axis */
		trackingCamera.acceleration.z = acceleration.z;
	}
}
Example #2
0
void destroyFXDroid(DROID *psDroid, unsigned impactTime)
{
	for (int i = 0; i < 5; ++i)
	{
		iIMDShape *psImd = NULL;

		int maxHorizontalScatter = TILE_UNITS / 4;
		int heightScatter = TILE_UNITS / 5;
		Vector2i horizontalScatter = iSinCosR(rand(), rand() % maxHorizontalScatter);

		Vector3i pos = swapYZ(psDroid->pos + Vector3i(horizontalScatter, 16 + heightScatter));
		switch (i)
		{
		case 0:
			switch (psDroid->droidType)
			{
			case DROID_DEFAULT:
			case DROID_CYBORG:
			case DROID_CYBORG_SUPER:
			case DROID_CYBORG_CONSTRUCT:
			case DROID_CYBORG_REPAIR:
			case DROID_WEAPON:
			case DROID_COMMAND:
				if (psDroid->numWeaps > 0)
				{
					if (psDroid->asWeaps[0].nStat > 0)
					{
						psImd = WEAPON_MOUNT_IMD(psDroid, 0);
					}
				}
				break;
			default:
				break;
			}
			break;
		case 1:
			switch (psDroid->droidType)
			{
			case DROID_DEFAULT:
			case DROID_CYBORG:
			case DROID_CYBORG_SUPER:
			case DROID_CYBORG_CONSTRUCT:
			case DROID_CYBORG_REPAIR:
			case DROID_WEAPON:
			case DROID_COMMAND:
				if (psDroid->numWeaps)
				{
					// get main weapon
					psImd = WEAPON_IMD(psDroid, 0);
				}
				break;
			default:
				break;
			}
			break;
		}
		if (psImd == NULL)
		{
			psImd = getRandomDebrisImd();
		}
		// Tell the effect system that it needs to use this player's color for the next effect
		SetEffectForPlayer(psDroid->player);
		addEffect(&pos, EFFECT_GRAVITON, GRAVITON_TYPE_EMITTING_DR, true, psImd, getPlayerColour(psDroid->player), impactTime);
	}
}
Example #3
0
void interpolate(const Mesh & mesh, const RMatrix & vData,
                 const R3Vector & ipos, RMatrix & iData,
                 bool verbose){

    R3Vector pos(ipos);
    
    if (mesh.dim() == 2){
        if ((zVari(pos) || max(abs(z(pos))) > 0.) && 
            (!yVari(pos) && max(abs(y(pos))) < 1e-8)) {
            if (verbose) 
                std::cout << "Warning! swap YZ coordinates for query "
                            "positions to meet mesh dimensions." << std::endl;
            swapYZ(pos);
        }
    }
        
    if (iData.rows() != vData.rows()){
        iData.resize(vData.rows(), pos.size());
    }

    std::vector < Cell * > cells(pos.size());
    size_t count = 0;
    
    Cell * c = 0;
    for (uint i = 0; i < pos.size(); i ++) {
        
        c = mesh.findCell(pos[i], count, false);
//         if (!c) {__MS(pos[i])
//             c = mesh.findCell(pos[i], count, true);
//             if (!c) exit(0);
//         }
        cells[i] = c;
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << pos.size();
//                             << "\t searched: " << count << std::endl;
    }
    if (verbose) std::cout << std::endl;

    for (uint i = 0; i < vData.rows(); i ++) {
        if (verbose) std::cout << "\r" << i + 1 << " \t/ " << vData.rows();
        
        RVector data;
        
        if (vData[i].size() != 0){

            if (vData[i].size() == mesh.nodeCount()){
                data = vData[i];
            } else if (vData[i].size() == mesh.cellCount()){
                data = cellDataToPointData(mesh, vData[i]);
            } else {
                throwLengthError(EXIT_VECTOR_SIZE_INVALID,
                                 WHERE_AM_I + 
                                 " data.size not nodeCount and cellCount " + 
                                 toStr(vData[i].size()) + " != " + 
                                 toStr(mesh.nodeCount()) + " != " + 
                                 toStr(mesh.cellCount()));
            }

            for (uint j = 0; j < pos.size(); j ++) {
                if (cells[j]){
                    iData[i][j] = cells[j]->pot(pos[j], data);
                    
//              this check is obsolete if the findCell (from above) is working properly                     
//                     if (cells[j]->shape().isInside(pos[j])){
//                         iData[i][j] = cells[j]->pot(pos[j], data);
//                     } else {
//                         std::cout << WHERE_AM_I << " here is somethng wrong" << std::endl;
//                     }

//                    std::cout << j << " " << iData[i][j] << std::endl;
                    //** return cell data
//                    iData[i][j] = vData[i][cells[j]->id()];
                } else {        
                    iData[i][j] = 0.0;
                    //std::cout << "Cant find cell for " << pos[j]<< std::endl;
//                     for (uint i = 0; i < mesh.cellCount(); i ++){
//                     	if (mesh.cell(i).shape().isInside(pos[j], true)){
//                         	std::cout << mesh.cell(i) << std::endl;
//                         }
//                     }
//                     exit(0);
                }
            }
        } // if vData.size() != 0
    }  // for each in vData
    if (verbose) std::cout << std::endl;
}
Example #4
0
AViz::AViz() 
    : QMainWindow()
{
    // Make menus in menubar
    QMenu *file = menuBar()->addMenu("&File");
    QMenu *elements = menuBar()->addMenu( "&Elements");
    QMenu *view = menuBar()->addMenu( "&View");
    QMenu *settings = menuBar()->addMenu( "&Settings");
    QMenu *data = menuBar()->addMenu("&Data");
    menuBar()->addSeparator();
    QMenu *help = menuBar()->addMenu("&Help");

    // Make a cascade menu to read files
    QMenu *openfile = file->addMenu("&Open");
    openfile->addAction("Open XYZ File...", this, SLOT(openXYZ()));
    openfile->addAction("Open File List...", this, SLOT(openList()));
    openfile->addAction("Open ViewParam File...", this, SLOT(openViewParam()));



    file->addAction( "Save ViewParam File...", this, SLOT(saveViewParam()) );
    file->addSeparator();
    file->addAction( "File List...", this, SLOT(launchFileList()) );
    file->addAction( "Animation...", this, SLOT(launchAnimation()) );
    file->addSeparator();
    m_inOutWatchModelAction = file->addAction( "Watch XYZ File", this, SLOT(watchFile()) );
    file->addSeparator();
    file->addAction( "Snap PNG File...", this, SLOT(savePNGFile()) );
    file->addSeparator();
    file->addAction( "Set Default View Param", this, SLOT(setDefaultView()));
    file->addSeparator();
    file->addAction( "E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q );

    // Make a general view menu
    QMenu *viewpoint = view->addMenu("Set &Viewpoint");
    view->addAction( "Clipping...", this, SLOT(launchClip()) );
    view->addAction( "Slicing...", this, SLOT(launchSlice()) );

    // Make a cascade menu to set standard view points
    viewpoint->addAction( "Explicit...", this, SLOT(launchExplicit()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "Default View", this, SLOT(setDefaults()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XY +", this, SLOT(viewXYPlus()) );
    viewpoint->addAction( "View XY -", this, SLOT(viewXYMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View XZ +", this, SLOT(viewXZPlus()) );
    viewpoint->addAction( "View XZ -", this, SLOT(viewXZMinus()) );
    viewpoint->addSeparator();
    viewpoint->addAction( "View YZ +", this, SLOT(viewYZPlus()) );
    viewpoint->addAction( "View YZ -", this, SLOT(viewYZMinus()) );


    // Fill a general elements menu
    m_atomsMenu = elements->addMenu("Atoms...");

    // Make a submenu for atom specifications
    m_atomsMenu->addAction( "Atoms/Molecules...", this, SLOT(launchAtoms()) );
    m_atomsMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );

    m_spinsAction = elements->addAction( "Spins...", this, SLOT(launchSpins()) );
    m_liquidCrystalsAction = elements->addAction( "Liquid Crystals...", this, SLOT(launchLiquidCrystals()) );
    m_polymersMenu = elements->addMenu( "Polymers...");
    m_poresAction = elements->addAction( "Pores ...", this, SLOT(launchPores()) );
    elements->addAction( "Lights...", this, SLOT(launchLights()) );
    elements->addAction( "Annotation...", this, SLOT(launchAnnotation()) );

    // fill submenu for polymer specifications
    m_polymersMenu->addAction( "Polymers...", this, SLOT(launchPolymers()) );
    m_polymersMenu->addAction( "Bonds...", this, SLOT(launchBonds()) );


    // fill a general settings menu
    m_showHideAxesAction = settings->addAction( "Hide Axes", this, SLOT(showHideAxesCB()) );
    m_showHideContourAction = settings->addAction( "Hide Contour", this, SLOT(showHideContourCB()) );
    m_onlyContourAction = settings->addAction( "Only Contour", this, SLOT(onlyContourCB()) );

    // fill a general data menu
    data->addAction( "&Translate...", this, SLOT(launchTranslation()) );
    data->addSeparator();
    data->addAction( "Swap XY", this, SLOT(swapXY()) );
    data->addAction( "Swap XZ", this, SLOT(swapXZ()) );
    data->addAction( "Swap YZ", this, SLOT(swapYZ()) );
    data->addSeparator();
    data->addAction( "Mirror X", this, SLOT(mirrorX()) );
    data->addAction( "Mirror Y", this, SLOT(mirrorY()) );
    data->addAction( "Mirror Z", this, SLOT(mirrorZ()) );
    data->addSeparator();
    data->addAction( "Stretch XYZ...", this, SLOT(launchStretch()) );

    // fill a general help menu
    help->addAction( "&About", this, SLOT(about()), Qt::CTRL+Qt::Key_H );
    help->addAction( "License", this, SLOT(license()) );
    help->addAction( "Distribution", this, SLOT(distribute()) );

    // Now construct the main form
    // (Note having aviz as paramter for MainForm ctor
    // is "This is an ugly hack, intended to propagate the
    // address of the calling class")
    m_mainForm = new MainForm(this/*parent*/, this /*aviz*/);
    setCentralWidget(m_mainForm);

    // Construct a timer
    m_watchTimer = new QTimer(this);

    // Set initial settings
    setAtomMenus();
}