void AlignOnRasterVisitor::visitDObject(DObject *object) { IResizable *resizable = m_sceneInspector->resizable(object, m_diagram); if (resizable) resizable->alignItemSizeToRaster(IResizable::SideRightOrBottom, IResizable::SideRightOrBottom, 2 * RASTER_WIDTH, 2 * RASTER_HEIGHT); IMoveable *moveable = m_sceneInspector->moveable(object, m_diagram); if (moveable) moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT); }
int main() { Fish* fish = Fish_new(); // 创建鱼对象 Dog* dog = Dog_new(); // 创建狗对象 Car* car = Car_new(); // 创建车子对象 Animal* animals[2] = { 0 }; // 初始化动物容器(这里是Animal指针数组) IMoveable* moveObjs[3] = { 0 }; // 初始化可移动物体容器(这里是IMoveable指针数组) int i = 0; // i和j是循环变量 int j = 0; // 初始化鱼对象的昵称为:小鲤鱼,年龄为:1岁 fish->init(fish, "Small carp", 1); // 将fish指针转型为Animal类型指针,并赋值给animals数组的第一个成员 animals[0] = SUPER_PTR(fish, Animal); // 初始化狗对象的昵称为:牧羊犬,年龄为:2岁 dog->init(dog, "sheepdog", 2); // 将dog指针转型为Animal类型指针,并赋值给animals数组的第二个成员 animals[1] = SUPER_PTR(dog, Animal); // 将fish指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第一个成员 moveObjs[0] = SUPER_PTR(fish, IMoveable); // 将dog指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第二个成员 moveObjs[1] = SUPER_PTR(dog, IMoveable); // 将car指针转型为IMoveable接口类型指针,并赋值给moveOjbs数组的第三个成员 moveObjs[2] = SUPER_PTR(car, IMoveable); // 循环打印动物容器内的动物信息 for(i=0; i<2; i++) { Animal* animal = animals[i]; animal->eat(animal); animal->breathe(animal); animal->sayHello(animal); } // 循环打印可移动物体容器内的可移动物体移动方式的信息 for(j=0; j<3; j++) { IMoveable* moveObj = moveObjs[j]; moveObj->move(moveObj); } lw_oopc_delete(fish); lw_oopc_delete(dog); lw_oopc_delete(car); return 0; }
void test_IMoveable(IEntity * E) { IMoveable *tmp; if ((tmp = cast_entity<IEntity, IMoveable>(E))) { std::cout << "Entity is an IMOVEABLE - has speed : " << tmp->getSpeed(); std::cout << ". It has direction : " << "x = " << tmp->getDirection().x_ << ", y = " << tmp->getDirection().y_ << std::endl; } }
void GameplayEngine::refreshEntitiesPositions() { for (std::deque<IEntity *>::iterator it = this->entities_.begin() ; it != this->entities_.end() ; ++it) { IEntity * fetch = *it; IMoveable * m = 0; if ((m = cast_entity<IEntity, IMoveable>(fetch))) { Point pos = m->getPosition(); m->setPosition(pos.x_ - 20, pos.y_); } } }
void RenderablePlayerMovingObject::render() { if (!this->dead) { IMoveable* move = this->getMoveable(); move->setPosition(this->position); if (this->heading != Vector4() && this->heading != Vector(0.0f, 0.0f, -1.0f)) { // reset rotation move->setRotation(0, 0, 0); // rotate the z vector to face the new heading move->rotate( Vector4::cross(this->heading, Vector(0.0f, 0.0f, -1.0f)), Vector4::angle(this->heading, Vector(0.0f, 0.0f, -1.0f)) ); // calculate where Y is now pointing Vector4 newY = move->getRotation() * Vector(0.0f, 1.0f, 0.0f); if (newY != up) { move->rotate( Vector4::cross(up, newY), Vector4::angle(up, newY) ); } } RenderableObject::render(); } }
void AlignOnRasterVisitor::visitDAnnotation(DAnnotation *annotation) { IMoveable *moveable = m_sceneInspector->moveable(annotation, m_diagram); if (moveable) moveable->alignItemPositionToRaster(RASTER_WIDTH, RASTER_HEIGHT); }