本文整理汇总了C++中sf::Window::GetEvent方法的典型用法代码示例。如果您正苦于以下问题:C++ Window::GetEvent方法的具体用法?C++ Window::GetEvent怎么用?C++ Window::GetEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Window
的用法示例。
在下文中一共展示了Window::GetEvent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: inputFn
void inputFn()
{
sf::Event evt;
while (window.GetEvent(evt)) {
if (window.GetInput().IsKeyDown(sf::Key::Down)) {
if (max_tess > 1) max_tess -= 1;
}
else if(window.GetInput().IsKeyDown(sf::Key::Up)) {
if (max_tess < 50) max_tess += 1;
}
switch (evt.Type) {
case sf::Event::Closed:
window.Close();
break;
case sf::Event::KeyPressed:
fflag = evt.Key.Code;
break;
case sf::Event::KeyReleased:
fflag = 0;
if (evt.Key.Code == 'r')
move = !move;
break;
case sf::Event::MouseMoved:
mouse = vec2(evt.MouseMove.X,
WIN_H - evt.MouseMove.Y);
break;
default:
break;
}
}
}
示例2: handleEvents
void handleEvents()
{
const sf::Input& Input = App->GetInput();
bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
sf::Event Event;
while (App->GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App->Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App->Close();
// This is for grading your code. DO NOT REMOVE
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Space) {
firing = 6;
}
if(Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::Space) {
firing = 0;
}
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::F12){
render = RenderEngine();
render.init();
}
if (Event.Type == sf::Event::Resized)
{ glViewport(0, 0, Event.Size.Width, Event.Size.Height); }
}
}
示例3: handleEvents
void handleEvents()
{
const sf::Input& Input = App->GetInput();
bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
sf::Event Event;
while (App->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App->Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App->Close();
if (Event.Type == sf::Event::Resized)
{
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
}
}
示例4: handleInput
void handleInput() {
sf::Event evt;
while (window.GetEvent(evt)) {
switch (evt.Type) {
case sf::Event::Closed:
// Close the window. This will cause the game loop to exit,
// because the IsOpened() function will no longer return true.
window.Close();
break;
case sf::Event::KeyPressed:
if (evt.Key.Code == sf::Key::W) {
cameraZ -= .1f;
} else if (evt.Key.Code == sf::Key::S) {
cameraZ += .1f;
} else if (evt.Key.Code == sf::Key::A) {
cameraX -= .1f;
} else if (evt.Key.Code == sf::Key::D) {
cameraX += .1f;
}
break;
}
}
}
示例5: main
//.........这里部分代码省略.........
{
show = true;
cursor.set((MouseX - windowsWidth/2), (MouseY - windowsHeight/2));
}
if (Shift) {
test=true;
}else{
test=false;
}
if (LeftKeyDown) {
camcam.tumble(0.005, 0);
LeftKeyDown = false;
}
if (RightKeyDown) {
camcam.tumble(-0.005, 0);
RightKeyDown = false;
}
if (UpKeyDown) {
camcam.tumble(0, 0.005);
}
if (DownKeyDown) {
camcam.tumble(0, -0.005);
}
//unsigned int delta =mouseT3 - mouseT1;
//cout << delta<< endl;
while (Application.GetEvent(Event))
{
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
// Fen�tre ferm�e
if (Event.Type == sf::Event::Closed)
Application.Close();
// Touche 'echap' appuy�e
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Application.Close();
if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::Space)) {
/// box ///////////////////////////////////////////
// create a shape
btCollisionShape* shape_kapla = new btBoxShape( btVector3(3,1,15) );
myTransform.setIdentity();
int dropX((MouseX - windowsWidth/2));
int dropY((MouseY - windowsHeight/2));
myTransform.setOrigin(btVector3(dropX,5,dropY));
btVector3 localInertia(0,0,0);
mass = 0.5f;
shape_kapla->calculateLocalInertia( mass, localInertia );
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
myMotionState = new btDefaultMotionState(myTransform);
btRigidBody::btRigidBodyConstructionInfo myBoxRigidBodyConstructionInfo( mass,myMotionState, shape_kapla, localInertia );
body_kapla = new btRigidBody(myBoxRigidBodyConstructionInfo);
示例6: handleInput
void handleInput() {
// this handles setting keyboard booleans for motion
go_forward = Input.IsKeyDown(sf::Key::W);
go_backward = Input.IsKeyDown(sf::Key::S);
go_left = Input.IsKeyDown(sf::Key::A);
go_right = Input.IsKeyDown(sf::Key::D);
go_up = Input.IsKeyDown(sf::Key::Space);
go_down = Input.IsKeyDown(sf::Key::C);
// Event loop, for processing user input, etc. For more info, see:
// http://www.sfml-dev.org/tutorials/1.6/window-events.php
sf::Event evt;
while (window.GetEvent(evt)) {
switch (evt.Type) {
case sf::Event::Closed:
// Close the window. This will cause the game loop to exit,
// because the IsOpened() function will no longer return true.
window.Close();
break;
case sf::Event::Resized:
// If the window is resized, then we need to change the perspective
// transformation and viewport
glViewport(0, 0, evt.Size.Width, evt.Size.Height);
break;
// Mouse Movement
case sf::Event::MouseMoved:
if (!mouseInit) {
cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
last_mouse = cur_mouse;
mouseInit = true;
}
else {
cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
}
mouse_move = cur_mouse - last_mouse;
h_angle += .01 * mouse_move.x;
v_angle += .01 * mouse_move.y;
if (v_angle < 0) {
v_angle = 0.01;
}
else if (v_angle > MY_PI) {
v_angle = MY_PI-.01;
}
current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle));
current_forward.Normalize();
current_right = STVector3::Cross(current_forward, Up);
current_right.Normalize();
last_mouse = cur_mouse;
break;
// Key presses
case sf::Event::KeyPressed:
switch (evt.Key.Code) {
case sf::Key::Escape:
window.Close();
break;
default:
break;
}
default:
break;
}
}
}
示例7: handleEvents
void handleEvents()
{
sf::Event Event;
while (App->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App->Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App->Close();
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
board->newGame(true);
// This is for grading your code. DO NOT REMOVE
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Equal)
{
unsigned char *dest;
unsigned int w = App->GetWidth();
unsigned int h = App->GetHeight();
glPixelStorei(GL_PACK_ALIGNMENT, 1);
dest = (unsigned char *) malloc( sizeof(unsigned char)*w*h*3);
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, dest);
FILE *file;
file = fopen("_program1.ppm", "wb");
fprintf(file, "P6\n%i %i\n%i\n", w, h, 255);
for(int i=h-1; i>=0; i--)
fwrite(&dest[i*w*3], sizeof(unsigned char), w*3, file);
fclose(file);
free(dest);
}
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::N){
board->newGame();
}
//handle mouse pressed
if(Event.Type == sf::Event::MouseButtonPressed)
{
if(Event.MouseButton.Button == sf::Mouse::Right) board->cancelPickup();
if(Event.MouseButton.Button == sf::Mouse::Left) {
int x = Event.MouseButton.X;
int y = Event.MouseButton.Y;
y = RESOLUTION - y;
board->display(true);
glFlush();
glFinish();
float clickColor[4];
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, clickColor);
GLuint clickId = 0;
clickId = clickId | ((unsigned int)(clickColor[0] * 255.0f) << 0);
clickId = clickId | ((unsigned int)(clickColor[1] * 255.0f) << 8);
clickId = clickId | ((unsigned int)(clickColor[2] * 255.0f) << 16);
clickId = clickId | ((unsigned int)(clickColor[3] * 255.0f) << 24);
unsigned int objectId = clickId;
//printf("Selected: %02X %02X %02X %02X\n", (objectId >> 24) & 0xFF, (objectId >> 16) & 0xFF, (objectId >> 8) & 0xFF, objectId & 0xFF );
if(!board->piecePlace(objectId)){
board->piecePickUp(objectId);
}
}
}
}
}
示例8: handleEvents
void handleEvents()
{
const sf::Input& Input = App->GetInput();
bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
sf::Event Event;
while (App->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App->Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App->Close();
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W)) {
tiltX-=cos(cameraTheta*M_PI/180)*TILTSPEED;
tiltZ-=sin(cameraTheta*M_PI/180)*TILTSPEED;
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S)) {
tiltX+=cos(cameraTheta*M_PI/180)*TILTSPEED;
tiltZ+=sin(cameraTheta*M_PI/180)*TILTSPEED;
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A)) {
tiltX-=sin(cameraTheta*M_PI/180)*TILTSPEED;
tiltZ+=cos(cameraTheta*M_PI/180)*TILTSPEED;
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::D)) {
tiltX+=sin(cameraTheta*M_PI/180)*TILTSPEED;
tiltZ-=cos(cameraTheta*M_PI/180)*TILTSPEED;
}
if(tiltX*tiltX+tiltZ*tiltZ>MAXTILT*MAXTILT) {
double size = sqrt(tiltX*tiltX+tiltZ*tiltZ);
tiltX*=MAXTILT/size;
tiltZ*=MAXTILT/size;
}
if (cameraLookMode && Event.Type == sf::Event::MouseMoved)
{
int deltaX = Event.MouseMove.X - lastPos[0];
int deltaY = Event.MouseMove.Y - lastPos[1];
/*glPushMatrix();
glLoadIdentity();
glRotated(deltaY, 1, 0, 0);
glRotated(deltaX, 0, 1, 0);
glMultMatrixd(rotationMatrix);
glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble*) &rotationMatrix);
glPopMatrix();*/
cameraTheta += deltaX*CAMERASPEED;
//cameraPhi -= deltaY*CAMERASPEED;
if (cameraPhi > 180)
cameraPhi = 180;
if (cameraPhi < 0.01)
cameraPhi = 0.01;
lastPos[0] = Event.MouseMove.X;
lastPos[1] = Event.MouseMove.Y;
}
if (Event.Type == sf::Event::MouseButtonPressed
&& Event.MouseButton.Button == sf::Mouse::Left)
{
lastPos[0] = Event.MouseButton.X;
lastPos[1] = Event.MouseButton.Y;
cameraLookMode = !cameraLookMode;
}
}
ball.accelerate(tiltX*0.0001,0.0001,0.0001*tiltZ);
ball.testCollision(level[0]);
}
示例9: handleInput
void handleInput() {
//////////////////////////////////////////////////////////////////////////
// TODO: ADD YOUR INPUT HANDLING HERE.
//////////////////////////////////////////////////////////////////////////
// Event loop, for processing user input, etc. For more info, see:
// http://www.sfml-dev.org/tutorials/1.6/window-events.php
sf::Event evt;
while (window.GetEvent(evt)) {
switch (evt.Type) {
case sf::Event::KeyPressed:
switch(evt.Key.Code)
{
case sf::Key::A:
left = true;
break;
case sf::Key::W:
forward = true;
break;
case sf::Key::S:
backward = true;
break;
case sf::Key::D:
right = true;
break;
case sf::Key::Up:
lightUp = true;
break;
case sf::Key::Left:
lightLeft = true;
break;
case sf::Key::Down:
lightDown = true;
break;
case sf::Key::Right:
lightRight = true;
break;
case sf::Key::T:
test = !test;
break;
default:
break;
}
break;
case sf::Event::KeyReleased:
switch(evt.Key.Code)
{
case sf::Key::A:
left = false;
break;
case sf::Key::W:
forward = false;
break;
case sf::Key::S:
backward = false;
break;
case sf::Key::D:
right = false;
break;
case sf::Key::Up:
lightUp = false;
break;
case sf::Key::Left:
lightLeft = false;
break;
case sf::Key::Down:
lightDown = false;
break;
case sf::Key::Right:
lightRight = false;
break;
default:
break;
}
break;
case sf::Event::MouseMoved:
static float rotation_sensitivity = 0.01;
static float prev_mouse_x = evt.MouseMove.X;
static float prev_mouse_y = evt.MouseMove.Y;
yaw -= rotation_sensitivity * (prev_mouse_x - evt.MouseMove.X);
pitch += rotation_sensitivity * (prev_mouse_y - evt.MouseMove.Y);
if (pitch < -M_PI / 2.0f) pitch = -M_PI / 2.0f;
if (pitch > M_PI / 2.0f) pitch = M_PI / 2.0f;
prev_mouse_x = evt.MouseMove.X;
prev_mouse_y = evt.MouseMove.Y;
break;
case sf::Event::Closed:
// Close the window. This will cause the game loop to exit,
// because the IsOpened() function will no longer return true.
window.Close();
break;
case sf::Event::Resized:
// If the window is resized, then we need to change the perspective
// transformation and viewport
glViewport(0, 0, evt.Size.Width, evt.Size.Height);
break;
default:
break;
//.........这里部分代码省略.........