示例#1
0
void NP_World::update(float deltaTime)
{
    for (size_t i = 0; i < m_objects.size(); ++i)
        m_objects[i]->update(deltaTime);

    //TODO:
    // FOR EACH STEP DO THESE THINGS: 
    //Generate collision info
    contacts.clear();
    for (size_t i = 0; i < m_objects.size(); ++i)
    {
        NP_Body* A = m_objects[i]->getBody();        

        for (size_t j = 0; j < m_objects.size(); ++j)
        {
            NP_Body* B = m_objects[j]->getBody();

            if (A->inverseMass == 0 && B->inverseMass == 0)
                continue;
            NP_CollisionInfo cI(A, B);
            updateOrientation(m_objects[i]);
            updateOrientation(m_objects[j]);
            cI.Solve(); //Do collision check
            if (cI.contact_count)
                contacts.emplace_back(cI);            
        }
    }
   
    // Integrate forces
    // - Go through objects - calc forces (calc acceleration)
    for (size_t i = 0; i < m_objects.size(); ++i)
        integrateForces(m_objects[i], deltaTime);

    // Init collision
    //for (size_t i = 0; i < contacts.size(); ++i)
    //{
    //    contacts[i].Initialize();
    //}

    //Solve collisions - apply impulse
    for (size_t i = 0; i < contacts.size(); ++i)
    {
        contacts[i].ApplyImpulse();
    }

    // Integrate velocities
    for (size_t i = 0; i < m_objects.size(); ++i)
        integrateVelocity(m_objects[i], deltaTime);

    for (size_t i = 0; i < m_objects.size(); ++i)
    {
        m_objects[i]->getBody()->m_force = glm::vec2(0, 0);
        m_objects[i]->getBody()->m_torque = 0;
    }

}
Separator::Separator(Plasma::Svg *svg, Applet *applet) : Plasma::SvgWidget(svg, "separator", applet),
    m_applet(applet),
    m_isVisible(true)
{
    setObjectName("FancyTasksSeparator");

    setAcceptsHoverEvents(true);

    setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));

    updateOrientation();

    connect(m_applet, SIGNAL(sizeChanged(qreal)), this, SLOT(setSize(qreal)));
    connect(m_applet, SIGNAL(locationChanged()), this, SLOT(updateOrientation()));
}
示例#3
0
void MainWindow::actionOrientation(){
    QAction *action = (QAction*)sender();

    setOrientation(static_cast<Orientation>(action->property("orientation").toInt()));

    updateOrientation();
}
void ScreenOrientationController::setOrientation(ScreenOrientation* orientation)
{
    m_orientation = orientation;
    if (m_orientation)
        updateOrientation();
    notifyDispatcher();
}
示例#5
0
void IntegrationTools::exponentialEuler( const VectorXs& q0, const VectorXs& v0, const std::vector<bool>& fixed, const scalar& dt, VectorXs& q1 )
{
  assert( q0.size() == q1.size() );
  assert( q0.size() % 12 == 0 );
  assert( v0.size() * 2 == q0.size() );
  assert( 12 * fixed.size() == static_cast<unsigned long>(q0.size()) );

  const int nbodies{ static_cast<int>( fixed.size() ) };

  // Center of mass update
  for( int bdy_num = 0; bdy_num < nbodies; bdy_num++ )
  {
    if( !fixed[bdy_num] )
    {
      q1.segment<3>( 3 * bdy_num ) = q0.segment<3>( 3 * bdy_num ) + dt * v0.segment<3>( 3 * bdy_num );
    }
    else
    {
      q1.segment<3>( 3 * bdy_num ) = q0.segment<3>( 3 * bdy_num );
    }
  }

  // Orientation update
  for( int bdy_num = 0; bdy_num < nbodies; bdy_num++ )
  {
    if( !fixed[bdy_num] )
    {
      updateOrientation( nbodies, bdy_num, q0, v0, dt, q1 );
    }
    else
    {
      q1.segment<9>( 3 * nbodies + 9 * bdy_num ) = q0.segment<9>( 3 * nbodies + 9 * bdy_num );
    }
  }
}
void 
Projector::update()
{
    if(!m_pkCamera)
        return;

    updateOrientation();
    updateModelViewMatrix();
    updateProjectionMatrix();

    float16 kViewPrj = m_kModelViewMatrix * m_kProjectionMatrix;
    float16 kInvViewPrj = inverse(kViewPrj);    

    findFrustumCorners(m_akFrustum, kInvViewPrj);
    m_uiIntersectionCount = findPlanarIntersections(m_akIntersections, m_akFrustum);
    if(m_uiIntersectionCount > 0)
    {
        m_kRange = findProjectedRange(m_uiIntersectionCount, m_akIntersections, kViewPrj);
        findProjectedCorners(m_akCorners, m_kRange, kInvViewPrj);
        updateRangeMatrix(m_kRange);
        m_bIsVisible = true;
    }
    else
    {
        m_bIsVisible = false;
    }
}
void ScreenOrientationController::notifyOrientationChanged()
{
    ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled());

    if (!isActiveAndVisible())
        return;

    updateOrientation();

    // Keep track of the frames that need to be notified before notifying the
    // current frame as it will prevent side effects from the change event
    // handlers.
    WillBeHeapVector<RefPtrWillBeMember<LocalFrame> > childFrames;
    for (Frame* child = frame()->tree().firstChild(); child; child = child->tree().nextSibling()) {
        if (child->isLocalFrame())
            childFrames.append(toLocalFrame(child));
    }

    // Notify current orientation object.
    if (!m_dispatchEventTimer.isActive())
        m_dispatchEventTimer.startOneShot(0, FROM_HERE);

    // ... and child frames, if they have a ScreenOrientationController.
    for (size_t i = 0; i < childFrames.size(); ++i) {
        if (ScreenOrientationController* controller = ScreenOrientationController::from(*childFrames[i]))
            controller->notifyOrientationChanged();
    }
}
示例#8
0
void KstViewLine::setFrom(const QPoint& from) {
  if (_from != from) {
    _from = from;
    // line drawing finished; update size, origin, and orientation
    updateOrientation();
    setDirty();
  }
}
示例#9
0
void KstViewLine::setTo(const QPoint& to) {
  if (_to != to) {
    _to = to;
    // line drawing finished; update size, origin, and orientation
    updateOrientation();
    setDirty();
  }
}
示例#10
0
void CFootballPlayer::update()
{
    m_canDoActions = true;
    updateOrientation();
    btVector3 velocity = m_body->getLinearVelocity();
    if(velocity.length() > 0.1) {
        setHeading(m_body->getLinearVelocity());
    }
    m_stateMachine->update();

}
JNIEXPORT void JNICALL 
JAVA_EXPORT_NAME(SDLSurfaceView_nativeAccelerometer) ( JNIEnv*  env, jobject  thiz, jfloat accPosX, jfloat accPosY, jfloat accPosZ )
{
	// Calculate two angles from three coordinates - TODO: this is faulty!
	//float accX = atan2f(-accPosX, sqrtf(accPosY*accPosY+accPosZ*accPosZ) * ( accPosY > 0 ? 1.0f : -1.0f ) ) * M_1_PI * 180.0f;
	//float accY = atan2f(accPosZ, accPosY) * M_1_PI;
	float normal = sqrt(accPosX*accPosX+accPosY*accPosY+accPosZ*accPosZ);
	if(normal <= 0.0000001f)
		normal = 1.0f;
	
	updateOrientation (accPosX/normal, accPosY/normal, 0.0f);
}
示例#12
0
void SolverThread::stepPhysics(float dt)
{
	computeForces();

	clearStiffnessAssembly();	

	if(bUseStiffnessWarping)
		updateOrientation();
	else
		resetOrientation();

	stiffnessAssembly();
	
	// addPlasticityForce(dt);
 
	dynamicsAssembly(dt);
 
#if SOLVEONGPU
	solveGpu(m_V, m_stiffnessMatrix);
#else
    solve(m_V);
#endif
 
	updatePosition(dt);
	
#if ENABLE_DBG	
	dbglg.write("Re");
	unsigned totalTetrahedra = m_mesh->numTetrahedra();
	FEMTetrahedronMesh::Tetrahedron * tetrahedra = m_mesh->tetrahedra();
	for(unsigned k=0;k<totalTetrahedra;k++) {
	    dbglg.write(k);
		dbglg.write(tetrahedra[k].Re.str());
	}

	dbglg.writeMat33(m_stiffnessMatrix->valueBuf(), 
	    m_stiffnessMatrix->numNonZero(),
	    "K ");

	dbglg.write("Rhs");
	unsigned totalPoints = m_mesh->numPoints();
	for(unsigned k=0;k<totalPoints;k++) {
	    dbglg.write(k);
		dbglg.write(rightHandSide()[k].str());
		dbglg.newLine();
	}
	dbglg.write("F0");
	for(unsigned k=0;k<totalPoints;k++) {
	    dbglg.write(k);
		dbglg.write(m_F0[k].str());
		dbglg.newLine();
	}
#endif
}
示例#13
0
void MainWindow::loadSettings(){
    setFullScreen(false);
    setHideMenu(false);

    QSettings settingsNative;

    resize(settingsNative.value("size", QSize(320, 480 + ui.menuBar->height())).toSize());
    move(settingsNative.value("pos",    QPoint(0, 0)).toPoint());

    int red = settingsNative.value("backgroundRed",     240).toInt();
    int green = settingsNative.value("backgroundGreen", 240).toInt();
    int blue = settingsNative.value("backgroundBlue",   240).toInt();
    QColor backgroundColor = QColor(red, green, blue);

    red = settingsNative.value("canvasRed",     255).toInt();
    green = settingsNative.value("canvasGreen", 255).toInt();
    blue = settingsNative.value("canvasBlue",   255).toInt();
    QColor canvasColor = QColor(red, green, blue);

    red = settingsNative.value("infoRed",     0).toInt();
    green = settingsNative.value("infoGreen", 0).toInt();
    blue = settingsNative.value("infoBlue",   0).toInt();
    QColor infoColor = QColor(red, green, blue);

    setBackgroundColor(backgroundColor);
    setCanvasColor(canvasColor);
    setInfoColor(infoColor);

    updateBackgroundColor();
    updateCanvasColor();
    updateInfoColor();

    QSettings settings(Constants::SETTINGS_FOLDER + "/" + Constants::PLAYER_SETTINGS_FILE, QSettings::IniFormat);

    setWidth(settings.value("width",             320).toInt());
    setHeight(settings.value("height",           480).toInt());
    setScale(settings.value("scale",             100).toInt());
    setFps(settings.value("fps",                 60).toInt());
    setOrientation(static_cast<Orientation>(settings.value("orientation", ePortrait).toInt()));
    setDrawInfos(settings.value("drawInfos",     false).toBool());
    setAutoScale(settings.value("autoScale",     false).toBool());
    setAlwaysOnTop(settings.value("alwaysOnTop", false).toBool());

    checkLoadedSettings();

    updateFps();
    updateDrawInfos();
    updateAlwaysOnTop();
    updateAutoScale();
    updateOrientation();
    updateResolution();
}
void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, ComputedStyle& style)
{
    if (!m_flags)
        return;

    FontDescription description = style.fontDescription();

    if (isSet(PropertySetFlag::Family)) {
        description.setGenericFamily(m_fontDescription.genericFamily());
        description.setFamily(m_fontDescription.family());
    }
    if (isSet(PropertySetFlag::Size)) {
        description.setKeywordSize(m_fontDescription.keywordSize());
        description.setSpecifiedSize(m_fontDescription.specifiedSize());
        description.setIsAbsoluteSize(m_fontDescription.isAbsoluteSize());
    }
    if (isSet(PropertySetFlag::SizeAdjust))
        description.setSizeAdjust(m_fontDescription.sizeAdjust());
    if (isSet(PropertySetFlag::Weight))
        description.setWeight(m_fontDescription.weight());
    if (isSet(PropertySetFlag::Stretch))
        description.setStretch(m_fontDescription.stretch());
    if (isSet(PropertySetFlag::FeatureSettings))
        description.setFeatureSettings(m_fontDescription.featureSettings());
    if (isSet(PropertySetFlag::Script)) {
        description.setLocale(m_fontDescription.locale());
        description.setScript(m_fontDescription.script());
    }
    if (isSet(PropertySetFlag::Style))
        description.setStyle(m_fontDescription.style());
    if (isSet(PropertySetFlag::Variant))
        description.setVariant(m_fontDescription.variant());
    if (isSet(PropertySetFlag::VariantLigatures))
        description.setVariantLigatures(m_fontDescription.variantLigatures());
    if (isSet(PropertySetFlag::TextRendering))
        description.setTextRendering(m_fontDescription.textRendering());
    if (isSet(PropertySetFlag::Kerning))
        description.setKerning(m_fontDescription.kerning());
    if (isSet(PropertySetFlag::FontSmoothing))
        description.setFontSmoothing(m_fontDescription.fontSmoothing());
    if (isSet(PropertySetFlag::TextOrientation) || isSet(PropertySetFlag::WritingMode))
        updateOrientation(description, style);

    updateSpecifiedSize(description, style);
    updateComputedSize(description, style);
    updateAdjustedSize(description, style, fontSelector.get());

    style.setFontDescription(description);
    style.font().update(fontSelector);
    m_flags = 0;
}
示例#15
0
void FontBuilder::createFontForDocument(FontSelector* fontSelector, ComputedStyle& documentStyle)
{
    FontDescription fontDescription = FontDescription();
    fontDescription.setLocale(documentStyle.locale());

    setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription());
    setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize(), 0.0f, false));
    updateSpecifiedSize(fontDescription, documentStyle);
    updateComputedSize(fontDescription, documentStyle);

    updateOrientation(fontDescription, documentStyle);
    documentStyle.setFontDescription(fontDescription);
    documentStyle.font().update(fontSelector);
}
void Camera::viewEventHandler(Event* VE)
{
	switch (VE->getId())
	{
	case ID::VE_UPDATE_POSITION:
		updatePosition(boost::get<v3>(VE->getData()));
		break;
	case ID::VE_UPDATE_ORIENTATION:
		updateOrientation(boost::get<qv4>(VE->getData()));
		break;
	default:
		throw std::logic_error("Camera::eventHandler: received unhandled event!");
	}

}
示例#17
0
文件: BondLayer.C 项目: bjnano/IQmol
void Bond::drawPrivate(bool selected) 
{
   updateOrientation(); // This should only need calling if an atom is moving
   switch (m_drawMode) {
      case Primitive::BallsAndSticks:
         drawBallsAndSticks(selected);
         break;
      case Primitive::Tubes:
         drawTubes(selected);
         break;
      case Primitive::WireFrame:
         drawWireFrame(selected);
         break;
      default:
         break;
   }
}
示例#18
0
文件: sdlv.cpp 项目: dtzWill/supernes
static void setupVideoSurface()
{
	// Real surface area.
	const unsigned gameWidth = IMAGE_WIDTH;
	const unsigned gameHeight = IMAGE_HEIGHT;

	GUI.Width = gameWidth;
	GUI.Height = gameHeight;

#if CONF_EXIT_BUTTON
	ExitBtnReset();
#endif

	// Safeguard
	if (gameHeight > GUI.Height || gameWidth > GUI.Width)
		DIE("Video is larger than window size!");

  GL_InitTexture(gameWidth, gameHeight);
  updateOrientation();
	
	SDL_ShowCursor(SDL_DISABLE);
 
	// Each scaler may have its own pitch
	GFX.Pitch = gameWidth * 2;
	GFX.ZPitch = GFX.Pitch / 2;
	// gfx & tile.cpp depend on the zbuffer pitch being always half of the color buffer pitch.
	// Which is a pity, since the color buffer might be much larger.

	GFX.Screen = (uint8 *) calloc(1,GFX.Pitch * IMAGE_HEIGHT);
	GFX.SubScreen = (uint8 *) calloc(1,GFX.Pitch * IMAGE_HEIGHT);
	GFX.ZBuffer =  (uint8 *) calloc(1,GFX.ZPitch * IMAGE_HEIGHT);
	GFX.SubZBuffer = (uint8 *) calloc(1,GFX.ZPitch * IMAGE_HEIGHT);

	GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1;
	GFX.DepthDelta = GFX.SubZBuffer - GFX.ZBuffer;
	GFX.PPL = GFX.Pitch / 2;

  GUI.ScaleX = GUI.ScaleY = 1.0;
  GUI.RenderX = GUI.RenderY = 0;
  GUI.RenderW = gameWidth;
  GUI.RenderH = gameHeight;
}
示例#19
0
void MainWindow::actionRotate(){
    QAction *action = (QAction*)sender();

    if(action->property("rotate").toInt() == eLeft){
        switch(orientation())
        {
        case ePortrait:
            ui.actionLandscape_Left->trigger();
            break;
        case eLandscapeLeft:
            ui.actionPortrait_Upside_Down->trigger();
            break;
        case ePortraitUpsideDown:
            ui.actionLandscape_Right->trigger();
            break;
        case eLandscapeRight:
            ui.actionPortrait->trigger();
            break;
        }

    }else{
        switch (orientation())
        {
        case ePortrait:
            ui.actionLandscape_Right->trigger();
            break;
        case eLandscapeRight:
            ui.actionPortrait_Upside_Down->trigger();
            break;
        case ePortraitUpsideDown:
            ui.actionLandscape_Left->trigger();
            break;
        case eLandscapeLeft:
            ui.actionPortrait->trigger();
            break;
        }
    }

    updateOrientation();
}
示例#20
0
文件: sdli.cpp 项目: dtzWill/supernes
void S9xInitInputDevices()
{
	joypads[0] = 0;
	joypads[1] = 0;
	mouse.enabled = false;
	mouse.pressed = false;

#if CONF_ZEEMOTE
	ZeeInit();
#endif

	if (Config.joypad1Enabled) {
		joypads[0] = 0x80000000UL;
	}
	if (Config.joypad2Enabled) {
		joypads[1] = 0x80000000UL;
	}

	// Pretty print some information
	printf("Input: ");
	if (Config.joypad1Enabled) {
		printf("Player 1 (joypad)");
		if (Config.joypad2Enabled) {
			printf("+ player 2 (joypad)");
		}
	} else if (Config.joypad2Enabled) {
		printf("Player 2 (joypad)");
	} else {
		printf("Nothing");
	}
	printf("\n");

	// TODO Non-awful mouse & superscope support

	S9xInputScreenChanged();
  initialize_keymappings(&Config);
  loadSkins();
  updateOrientation();
  GL_InitTexture(IMAGE_WIDTH,IMAGE_HEIGHT);
}
void StrokeProcessState::updateState(ParamBox input)
{
    this->prevParam = curParam;
    this->curParam = input;
    //Compare the difference between curParam and prevParam, then update according to the changes

    if (this->StrokeList.empty())
    {   NUS_Weibull(this->imgData->SaliencyImage, & (this->StrokeList), this->curParam.mDensity,this->curParam.mNon_Uniformity);

    }

    if (laterUpdate_graph) //re-update the saliency sampling-> initial connection graph
    {
        //NUS_Weibull(this->imgData->SaliencyImage, & (this->StrokeList), this->curParam.mDensity,this->curParam.mNon_Uniformity);
        initStrokeOrientation(StrokeList, this->imgData->GradientOrientation);
        connectStrokeGraph(StrokeList, this->imgData->SegmentImage);
        //Debug use ...Show Image
        //vis_StrokePositions(this->imgData->OriginalImage, this->StrokeList);

    }

    if (curParam.mLocal_Iostropy != prevParam.mLocal_Iostropy || laterUpdate_graph) // update connection graph
    {
        updateOrientation(this->StrokeList, this->curParam.mLocal_Iostropy);
        connectStrokeGraph(StrokeList, this->imgData->SegmentImage);
        laterUpdate_graph = true;
    }
    if (curParam.mCoarseness != prevParam.mCoarseness || laterUpdate_graph)  // reinitialize the size
    {
        initStrokeSize(this->imgData->SaliencyImage, this->imgData->GradientRatio, (this->StrokeList), this->curParam.mCoarseness);
        laterUpdate_size = true;
    }
    if (curParam.mSize_Contrast!=prevParam.mSize_Contrast || laterUpdate_graph || laterUpdate_size) //update size
    {
        updateSize(StrokeList, this->curParam.mSize_Contrast);
    }

    /*if (laterUpdate_graph || laterUpdate_size)
    {
    initStrokeColor(StrokeList, this->imgData->OriginalImage);

    }*/

    if (curParam.mHue_Constrast != prevParam.mHue_Constrast ||
            curParam.mLightness_Contrast != prevParam.mLightness_Contrast||
            curParam.mChroma_Constrast != prevParam.mChroma_Constrast||
            laterUpdate_graph||laterUpdate_size ) //update the three color channels separately
    {
        initStrokeColor(StrokeList, this->imgData->OriginalImage);
        updateHue(StrokeList,curParam.mHue_Constrast);
        updateLightness(StrokeList, curParam.mLightness_Contrast);
        updateChroma(StrokeList, curParam.mChroma_Constrast);


    }

    //if (curParam.mLightness_Contrast != prevParam.mLightness_Contrast ||laterUpdate_graph||laterUpdate_size) //update the three color channels separately
    //{
    //	updateLightness(StrokeList, curParam.mLightness_Contrast);
    //}

    //if (curParam.mChroma_Constrast != prevParam.mChroma_Constrast ||laterUpdate_graph||laterUpdate_size) //update the three color channels separately
    //{
    //	updateChroma(StrokeList, curParam.mChroma_Constrast);
    //}



}
示例#22
0
 void EnergyMeter::setOrientation(const int &newOrientation) {
     if(newOrientation != orientation) {
         orientation = newOrientation;
     }
     updateOrientation();
 }
示例#23
0
void traverse2(int previousNode, int currentNode, Location* currentLocation, int* orientation, Location mazeCoords[], int visited[], int dijkstraPath[]) {
	int i, j;
	
	// If graph uninitialised, initialise it
	if (!graphInitialised) {
		for (i = 0; i < 17; i++) {
			for (j = 0; j < 17; j++) {
				graph[i][j] = 0;
			}
		}
		
		graphInitialised = 1;
	}
	
	int adjacentNodes[3];
	findAdjacentNodes(currentNode, *orientation, adjacentNodes);
	
	visited[currentNode] = 1;
	
	/*
	printf("Visited nodes:");
	for (i = 0; i < 17; i++) {
		if (visited[i]) {
			printf(" %d", i);
		}
	}
	printf("\n");
	*/
	graph[0][1] = 1;
	graph[1][0] = 1;
	
	for (i = 0; i < 3; i++) {
		if (adjacentNodes[i] >= 0) {
			graph[currentNode][adjacentNodes[i]] = 1;
			graph[adjacentNodes[i]][currentNode] = 1;
		}
	}
	
	for (i = 0; i < 3; i++) {
		if (adjacentNodes[i] >= 0 && visited[adjacentNodes[i]] == 0) {	
			updateOrientation(orientation, currentNode, adjacentNodes[i]);
			
			printf("Traverse \n");
			printf("Current node: %d \n", currentNode);
			printf("Orientation: %d \n", *orientation);
			printf("Current location: x = %f; y = %f \n", currentLocation->x, currentLocation->y);
			printf("Target location: x = %f; y = %f \n", mazeCoords[adjacentNodes[i]].x, mazeCoords[adjacentNodes[i]].y);
		
			goToPoint(currentLocation, &mazeCoords[adjacentNodes[i]]);
			
			correctLocation(adjacentNodes[i], currentLocation, orientation, mazeCoords);
			
			traverse2(currentNode, adjacentNodes[i], currentLocation, orientation, mazeCoords, visited, dijkstraPath);
		}
	}
	
	updateOrientation(orientation, currentNode, previousNode);
	goToPoint(currentLocation, &mazeCoords[previousNode]);
	correctLocation(previousNode, currentLocation, orientation, mazeCoords);
	
	printf("Current location: x = %f; y = %f \n", currentLocation->x, currentLocation->y);
	
	int explored = 1;
	for (i = 0; i < 17; i++) {
		if (visited[i] == 0) {
			explored = 0;
		}
	}
	
	if (explored) {
		//printgraph();
		dijkstra(0, dijkstraPath);
	}
}
JNIEXPORT void JNICALL 
JAVA_EXPORT_NAME(SDLSurfaceView_nativeOrientation) ( JNIEnv*  env, jobject  thiz, jfloat accX, jfloat accY, jfloat accZ )
{
	updateOrientation (accX, accY, accZ);
}
示例#25
0
void Molecule::update(){
	x = x + v*dt;
	updateOrientation();
}
示例#26
0
void GL_RenderPix(u8 * pix,int w, int h)
{
    // Update the texture dimensions/scaling depending on the rendered image size.
    if ( srcWidth != w || srcHeight != h )
    {
        srcWidth = w;
        srcHeight = h;
        GL_InitTexture(w,h);
        updateOrientation();
    }

    glClear( GL_COLOR_BUFFER_BIT );
    checkError();

    /*-----------------------------------------------------------------------------
     *  Background Skin
     *-----------------------------------------------------------------------------*/
    if ( use_on_screen && skin && !skin->transparent)
    {
        drawSkin();
    }

    /*-----------------------------------------------------------------------------
     *  Draw the frame of the snes
     *-----------------------------------------------------------------------------*/

    // Use the program object
    glUseProgram ( programObject );
    checkError();

    glVertexAttribPointer( positionLoc, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), vertexCoords );
    checkError();
    glVertexAttribPointer( texCoordLoc, 2, GL_FLOAT, GL_FALSE, 2*sizeof(GLfloat), texCoords );

    checkError();

    glEnableVertexAttribArray( positionLoc );
    checkError();
    glEnableVertexAttribArray( texCoordLoc );
    checkError();

    glBindTexture(GL_TEXTURE_2D, texture);
    glTexSubImage2D( GL_TEXTURE_2D,0,
                     0,0, srcWidth,srcHeight,
                     GL_RGB,GL_UNSIGNED_SHORT_5_6_5,pix);

    checkError();

    //sampler texture unit to 0
    glUniform1i( samplerLoc, 0 );
    checkError();

    glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
    checkError();

    /*-----------------------------------------------------------------------------
     *  Skin Overlay
     *-----------------------------------------------------------------------------*/
    if ( use_on_screen && skin && skin->transparent)
    {
        drawSkin();
    }


    //Push to screen
    SDL_GL_SwapBuffers();
    checkError();

}
示例#27
0
void render(BeagleRTContext *context, void *userData)
{
	/* Step 2: use gReadPointer to play a drum sound */


	if (gStartup > 0)
	{

		gXCalibrate = 0.42;
		gYCalibrate = 0.42;
		gZCalibrate = 0.42;

		gStartup--;

		gShouldPlayFill = 0;

		rt_printf("Callibration: X: %f\tY: %f\tZ: %f\n", gXCalibrate, gYCalibrate, gZCalibrate);
	} 


	for (int n = 0; n < context->digitalFrames; n++)
	{
		// initialize output
		float output = 0.0;

		// check button state and change gIsPlaying if just pressed
		int button1State = digitalReadFrame(context, n, buttonPin1);
		if (button1State == 0 && previousButton1State == 1)
		{
			if (gIsPlaying == 0) {
				gIsPlaying = 1;
				gSampleCount = 0;
			} else {
				gIsPlaying = 0;
			}
		}
		previousButton1State = button1State;

		float gEventIntervalMilliseconds = map(analogReadFrame(context, n/gNumAudioFramesPerAnalog, potPin), 0, 0.829, 50, 1000);

		gCountForSensor++;


		float x = analogReadFrame(context, n/gNumAudioFramesPerAnalog, xPin) - gXCalibrate;
		float y = analogReadFrame(context, n/gNumAudioFramesPerAnalog, yPin) - gYCalibrate;
		float z = analogReadFrame(context, n/gNumAudioFramesPerAnalog, zPin) - gZCalibrate;

		float accelerationMagnitude = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));

 			// Filter out gravity

		float filteredAcceleration = gB0 * accelerationMagnitude + gB1 * gX1 + gB2 * gX2 
		- gA1 * gY1 - gA2 * gY2;

		gX2 = gX1;
		gX1 = accelerationMagnitude;
		gY2 = gY1;
		gY1 = filteredAcceleration;


		if (filteredAcceleration > 0.2 && gShouldPlayFill == 0) {
			rt_printf("Filtered acceleration: %f\n", filteredAcceleration);
			gShouldPlayFill = 1;
			if (gCurrentPattern != gFillPattern)
				gPreviousPattern = gCurrentPattern;
			gCurrentIndexInPattern = 0;
		}

		if (gCountForSensor == 128)
		{
			gCountForSensor = 0;

			updateOrientation(x, y, z);

			if(gShouldPlayFill == 0) 
				gCurrentPattern = gOrientation;
			else if (gShouldPlayFill == 1)
				gCurrentPattern = gFillPattern;
			gCurrentIndexInPattern = gCurrentIndexInPattern % gPatternLengths[gCurrentPattern];
			// rt_printf("X: %d\tY: %d\tZ: %d Pattern: %d\n", gXState, gYState, gZState, gCurrentPattern);

		}
		



		// count samples and trigger event if running

		if (gIsPlaying)
		{
			if (gSampleCount >= gEventIntervalMilliseconds * 0.001 * context->audioSampleRate)
			{
				startNextEvent();
				gSampleCount = 0;

				if(gLedState == 0) {
					gLedState = 1;
				}
				else {
					gLedState = 0;
				}

			}		
			gSampleCount++;
		}

		digitalWriteFrame(context, n, ledPin, gLedState);

		// If drum triggered read through samples and add to output buffer

		for (int i = 0; i < NUMBER_OF_READPOINTERS; i++)
		{
			int buffer = gDrumBufferForReadPointer[i];
			// rt_printf("Buffer %d: %d\n", i, buffer);
			if (buffer != -1)
			{
				output += gDrumSampleBuffers[buffer][gReadPointers[i]];

				if (gPlaysBackwards == 0) {
					gReadPointers[i]++;

					if (gReadPointers[i] >= gDrumSampleBufferLengths[buffer])
					{
						gDrumBufferForReadPointer[i] = -1;
					}
				} else if (gPlaysBackwards == 1)
				{
					gReadPointers[i]--;

					if (gReadPointers[i] == 0 )
					{
						gDrumBufferForReadPointer[i] = -1;
					}
				}
			}
		}
		// Write to output buffers

		output *= 0.25;

		audioWriteFrame(context, n, 0, output);
		audioWriteFrame(context, n, 1, output);

	}


}