GLvoid Orange::update(GLdouble delta_t){ GLdouble currentTime = glutGet(GLUT_ELAPSED_TIME); GLdouble delta_x = cos(_orange_angle*M_PI/180)*_orange_vel*delta_t/1000; GLdouble delta_y = sin(_orange_angle*M_PI/180)*_orange_vel*delta_t/1000; /* I SEE ORANGES FALLING FROM THE SKY */ if (getPositionZ()>ORANGE_SIZE) { setPosition(getPositionX(), getPositionY(), getPositionZ() -1); } else { setPosition(getPositionX() + delta_x, getPositionY() + delta_y, getPositionZ()); } /* AND NOW FALLING FROM THE TABLE :( */ if (fabs(getPositionX()) >(TABLE_SIZE/2+ORANGE_SIZE*0.5) || fabs(getPositionY()) >(TABLE_SIZE/2+ORANGE_SIZE*0.5)) { setPosition(getPositionX() + delta_x, getPositionY() + delta_y, getPositionZ()-1); } if (_alive && (fabs(getPositionX()) >(TABLE_SIZE/2 + ORANGE_SIZE*0.5) || fabs(getPositionY()) >(TABLE_SIZE/2 + ORANGE_SIZE*0.5)) && getPositionZ()<-100) { _alive = false; glutTimerFunc(3000, main_wakeupOrange, _id); } _rotate += _orange_vel*(delta_t/1000)*360/(2.*M_PI*ORANGE_SIZE); _last_time_division = (GLint)currentTime/10000; }
float SceneObjectImplementation::getWorldPositionZ() { if (parent.get() == NULL) return getPositionZ(); ManagedReference<SceneObject*> root = cast<SceneObject*>(getRootParentUnsafe()); if (root == NULL || !root->isBuildingObject()) return getPositionZ(); return root->getPositionZ() + getPositionZ(); }
void SceneObjectImplementation::updateVehiclePosition(bool sendPackets) { ManagedReference<SceneObject*> parent = getParent().get(); if (parent == NULL || (!parent->isVehicleObject() && !parent->isMount())) return; /* Vector3 position = getPosition(); parent->setPosition(getPositionX(), getPositionZ(), getPositionY()); Quaternion dir = direction; EXECUTE_TASK_4(parent, position, dir, sendPackets, { Locker locker(parent_p); parent_p->setDirection(dir_p.getW(), dir_p.getX(), dir_p.getY(), dir_p.getZ()); parent_p->setPosition(position_p.getX(), position_p.getZ(), position_p.getY()); parent_p->incrementMovementCounter(); parent_p->updateZone(false, sendPackets_p); } ); */ Locker locker(parent); parent->setDirection(direction.getW(), direction.getX(), direction.getY(), direction.getZ()); parent->setPosition(getPositionX(), getPositionZ(), getPositionY()); parent->incrementMovementCounter(); parent->updateZone(false, sendPackets); }
void Obstacle::render() { glPushMatrix(); glTranslatef(getPositionX()-SIZE/2,getPositionY()-SIZE/2,getPositionZ()-SIZE/2); glColor4f(1, 0, 0, 1); glBegin(GL_QUADS); // Front Face glVertex3f(Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); // Back Face glVertex3f(Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); // Top Face glVertex3f(Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); // Bottom Face glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); // Left face glVertex3f(Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); glVertex3f(Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); // Right face glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,-Obstacle::SIZE); glVertex3f(-Obstacle::SIZE,-Obstacle::SIZE,Obstacle::SIZE); glEnd(); glPopMatrix(); }
void PlantObjectImplementation::changeSize(int size) { String plantTemplate = ""; switch (size) { case 0: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_dead.iff"; break; case 1: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_1.iff"; break; case 2: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_2.iff"; break; case 3: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_3.iff"; break; } ManagedReference<ZoneServer*> zoneServer = getZoneServer(); if (zoneServer == NULL) return; ManagedReference<SceneObject*> parent = getParent(); if (parent == NULL || !parent->isCellObject()) return; ManagedReference<SceneObject*> obj = zoneServer->createObject(plantTemplate.hashCode(), getPersistenceLevel()); if (obj == NULL) return; Locker clocker(obj, _this.getReferenceUnsafeStaticCast()); obj->initializePosition(getPositionX(), getPositionZ(), getPositionY()); obj->setDirection(Math::deg2rad(getDirectionAngle())); ManagedReference<PlantObject*> newPlant = cast<PlantObject*>( obj.get()); if (newPlant == NULL) return; newPlant->setWaterLevel(waterLevel); newPlant->setNutrientLevel(nutrientLevel); newPlant->setWaterQuality(waterQuality); newPlant->setNutrientQuality(nutrientQuality); newPlant->setPlantHealth(health); newPlant->initializePlant(size); parent->transferObject(obj, -1); clocker.release(); destroyObjectFromWorld(true); destroyObjectFromDatabase(); }
void WaypointObjectImplementation::insertToMessage(BaseMessage* msg) { msg->writeInt(cellID); // cellID msg->writeFloat(getPositionX()); msg->writeFloat(getPositionZ()); //Z msg->writeFloat(getPositionY()); msg->writeLong(unknown); //? msg->writeInt(planetCRC); customName.toBinaryStream(msg); msg->writeLong(getObjectID()); msg->writeByte(color); msg->writeByte(active); }
Vector3 SceneObjectImplementation::getWorldPosition() { if (parent.get() == NULL) return getPosition(); ManagedReference<SceneObject*> root = getRootParent().castTo<SceneObject*>(); if (root == NULL || !root->isBuildingObject()) return getPosition(); float length = Math::sqrt(getPositionX() * getPositionX() + getPositionY() * getPositionY()); float angle = root->getDirection()->getRadians() + atan2(getPositionX(), getPositionY()); float posX = root->getPositionX() + (sin(angle) * length); float posY = root->getPositionY() + (cos(angle) * length); float posZ = root->getPositionZ() + getPositionZ(); Vector3 position(posX, posY, posZ); return position; }
Vec3 MotionStreak::getPosition3D() const { return Vec3(_positionR.x, _positionR.y, getPositionZ()); }
GLvoid Orange::draw(){ GLfloat ambient_orange[]= {0.49f,0.34f,0.11f,1.0f}; GLfloat diffuse_orange[]= {0.41f,0.3f,0.21f,1.0f}; GLfloat specular_orange[]= {0.7f,0.04f,0.04f,1.0f}; GLfloat shine_orange= 10.0f; GLfloat amb_leaf[]={0.0f,0.05f,0.0f,1.0f}; GLfloat diff_leaf[]={0.4f,0.41f,0.0f,1.0f}; GLfloat spec_leaf[]={0.04f,0.7f,0.04f,1.0f}; GLfloat shine_leaf=10.0f; GLfloat amb_stick[]={0.329412f,0.223529f,0.027451f,1.0f}; GLfloat diff_stick[]={0.32f,0.21f,0.113725f,1.0f}; GLfloat spec_stick[]={0.0f,0.0f,0.0f,1.0f}; GLfloat shine_stick=128.0f; if (_alive){ GLboolean solidOrWire = getSolidOrWire();//Solid or Wire objects flag glPushMatrix(); glTranslatef(getPositionX(), getPositionY(), getPositionZ()); glRotatef(_rotate, (-1)*sin(_orange_angle*M_PI / 180), cos(_orange_angle*M_PI / 180), 0); //------------orange glColor3f(0.992, 0.6039, 0); glPushMatrix(); material(ambient_orange, diffuse_orange, specular_orange, shine_orange); if (solidOrWire){ // radius 5 glutSolidSphere(ORANGE_SIZE, 16, 16); } else{ glutWireSphere(ORANGE_SIZE, 16, 16); } glPopMatrix(); //----------stick glColor3f(65. / 255, 73.0 / 255, 47. / 255); glPushMatrix(); material(amb_stick, diff_stick, spec_stick, shine_stick); glTranslatef(0, 0, ORANGE_SIZE); glRotatef(15, 0, 1, 0); glScalef(1, 1, 3.5); //3.5 or 7 if (solidOrWire){ glutSolidCube(ORANGE_SIZE / 7.); } else{ glutWireCube(ORANGE_SIZE / 7.); } glPopMatrix(); //----------folha glColor3f(96. / 255, 147. / 255, 71. / 255); glPushMatrix(); material(amb_leaf, diff_leaf, spec_leaf, shine_leaf); glTranslatef(ORANGE_SIZE*0.35, 0, ORANGE_SIZE*1.); glRotatef(40, 0, 1, 1); glScalef(1.4, 1, 0.1); if (solidOrWire){ glutSolidCube(ORANGE_SIZE / 3.); } else{ glutWireCube(ORANGE_SIZE / 3.); } glPopMatrix(); glPopMatrix(); if (_shadow && getPositionZ() > 0) { //----Sombra glColor3f(0.4, 0.4, 0.4); glPushMatrix(); glTranslatef(getPositionX(), getPositionY(), 1); glRotatef(90, 0, 1, 0); glutSolidSphere((1 - getPositionZ() / 360)*ORANGE_SIZE, 2, 16); glPopMatrix(); } } }