void Stage::processContinuousInput(){ if(keyStates[GLFW_KEY_A]) { cpVect curVel = cpBodyGetVelocity(userControlObject->body); if(curVel.x >= -1000.0) cpBodySetForce(userControlObject->body, cpv(-100000.0, 0.0)); } if(keyStates[GLFW_KEY_D]) { cpVect curVel = cpBodyGetVelocity(userControlObject->body); if(curVel.x <= 1000.0) cpBodySetForce(userControlObject->body, cpv(100000.0, 0.0)); } if(!keyStates[GLFW_KEY_A] && !keyStates[GLFW_KEY_D]) { cpVect curVel = cpBodyGetVelocity(userControlObject->body); if(curVel.x != 0) { curVel.x /= 1.1; if(curVel.x > -100 || curVel.x < 100) curVel.x = 0; cpBodySetVelocity(userControlObject->body, curVel); } } if(keyStates[GLFW_KEY_SPACE]){ cpVect curVel = cpBodyGetVelocity(userControlObject->body); // if(curVel.y < 0.5 && curVel.y > -0.5){ // cpBodySetVelocity(userControlObject->body, cpvadd(curVel, cpv(0.0, 1150.0))); // soundMap.find("Jump")->second->play(); // } if(userControlObject->canJump){ cpBodySetVelocity(userControlObject->body, cpvadd(curVel, cpv(0.0, 1150.0))); soundMap.find("Jump")->second->play(); } } if(keyStates[GLFW_KEY_E]){ firstPerson = !firstPerson; camera = Camera(); keyStates[GLFW_KEY_E] = 0; } }
ETERM *body_copy(ETERM *fromp, ETERM *argp) { // get the args ETERM *space_refp = erl_element(1, argp); ETERM *idp = erl_element(2, argp); ETERM *from_idp = erl_element(3, argp); erlmunk_space *s; int space_id = ERL_REF_NUMBER(space_refp); HASH_FIND_INT(erlmunk_spaces, &space_id, s); int body_id = ERL_INT_VALUE(idp); erlmunk_body *b; HASH_FIND_INT(s->bodies, &body_id, b); if (b == NULL) return NULL; int from_body_id = ERL_INT_VALUE(from_idp); erlmunk_body *from_b; HASH_FIND_INT(s->bodies, &from_body_id, from_b); // DEBUGF(("copying location from body #%d(%p) to #%d(%p)", // from_body_id, from_b, body_id, b)); // copy position and angle from the from body cpBodySetPosition(b->body, cpBodyGetPosition(from_b->body)); cpBodySetAngle(b->body, cpBodyGetAngle(from_b->body)); cpBodySetVelocity(b->body, cpBodyGetVelocity(from_b->body)); return NULL; }
RVector RCPBody::velocity() const { if (mBody) { cpVect p = cpBodyGetVelocity(mBody); mVelocity = RVector(p.x, p.y); } return mVelocity; }
void RigidBody2D::CopyBodyData(cpBody* body) { cpBodySetAngle(m_handle, cpBodyGetAngle(body)); cpBodySetAngularVelocity(m_handle, cpBodyGetAngularVelocity(body)); cpBodySetCenterOfGravity(m_handle, cpBodyGetCenterOfGravity(body)); cpBodySetForce(m_handle, cpBodyGetForce(body)); cpBodySetPosition(m_handle, cpBodyGetPosition(body)); cpBodySetTorque(m_handle, cpBodyGetTorque(body)); cpBodySetVelocity(m_handle, cpBodyGetVelocity(body)); }
void RigidBody2D::CopyBodyData(cpBody* from, cpBody* to) { cpBodySetAngle(to, cpBodyGetAngle(from)); cpBodySetAngularVelocity(to, cpBodyGetAngularVelocity(from)); cpBodySetCenterOfGravity(to, cpBodyGetCenterOfGravity(from)); cpBodySetForce(to, cpBodyGetForce(from)); cpBodySetPosition(to, cpBodyGetPosition(from)); cpBodySetTorque(to, cpBodyGetTorque(from)); cpBodySetVelocity(to, cpBodyGetVelocity(from)); }
bool Player::render(float time){ cpVect pos= cpBodyGetPosition(playerBody); cpVect vel = cpBodyGetVelocity(playerBody); playerX=pos.x; playerY=pos.y; printf("%4.2f %4.2f\n", playerX, playerY);//512->10*3 glSprite(playerX,playerY,GL2D_CENTER,&spr[0],false,0,0.01953125*3,0.01953125*3); return true; }
int update_brain(Ship* s) { float* inputs = new float[NINPUTS]; float noseang = cpBodyGetAngle(s->body) + s->nose_angle; cpVect rpos = cpBodyGetPosition(s->target->body) - cpBodyGetPosition(s->body); inputs[0] = cpvlength(rpos); inputs[1] = restrictangle(cpvtoangle(rpos)-noseang); cpVect rvel = cpBodyGetVelocity(s->target->body) - cpBodyGetVelocity(s->body); inputs[2] = (rpos.x * rvel.x + rpos.y * rvel.y)/inputs[0]; inputs[3] = (rpos.x * rvel.y - rpos.y * rvel.x)/(inputs[0]*inputs[0]) - cpBodyGetAngularVelocity(s->body); inputs[4] = restrictangle(cpBodyGetAngle(s->target->body) + s->target->nose_angle - noseang); inputs[5] = cpBodyGetAngularVelocity(s->target->body); s->brain->update(inputs); delete inputs; return 0; }
void weapon_collide(Entity *ent, cpArbiter *arb) { cpBody *body = entity_body(ent); cpBody *other = physics_arbiter_get_other(body, arb); Entity *other_ent = cpBodyGetUserData(other); //only damage players if (!entity_valid(other_ent) || entity_type(other_ent) != &PlayerEntity) { return; } //only damage enemies if (entity_owner(ent) != connection_get_user_id() || entity_owner(other_ent) == connection_get_user_id()) { return; } float speed = cpvlength(cpBodyGetVelocity(body)); if (speed < WEAPON_HURT_THRESHOLD) { return; } player_hurt(entity_owner(other_ent), WEAPON_DAMAGE * speed, entity_owner(ent)); }
Vec2 PhysicsBody::getVelocity() { return PhysicsHelper::cpv2point(cpBodyGetVelocity(_cpBody)); }
Vector2f RigidBody2D::GetVelocity() const { cpVect vel = cpBodyGetVelocity(m_handle); return Vector2f(static_cast<float>(vel.x), static_cast<float>(vel.y)); }