[英]Making a multiple versions of a Object
I'm a student instructed to make a doodle jump replica with ogre3d.我是一名学生,被指示使用 ogre3d 制作涂鸦跳跃复制品。 I have a function which should make a panel on screen with a designated shape and location so now I wish to make a for loop that will make multiple (up to 10) and a random value that'll set each of them somewhere different on x,y,z.
我有一个函数,它应该在屏幕上制作一个具有指定形状和位置的面板,所以现在我希望制作一个 for 循环,该循环将生成多个(最多 10 个)和一个随机值,该值将每个值设置在 x 上的不同位置,y,z。
void PlatformManager::CreatePanelDoodle( float x, float y, float z){
Plane plane3(Vector3::UNIT_Y, 0);
MeshManager::getSingleton().createPlane(
"Paddle2", RGN_DEFAULT,
plane3,
20, 5, 20, 20,
true,
1, 5, 5,
Vector3::UNIT_Z);
Entity* groundEntity3 = scnMgr->createEntity("Paddle2");
SceneNode* Paddlenode2 = scnMgr->getRootSceneNode()->createChildSceneNode();
Paddlenode2->setPosition(Ogre::Vector3( x, y, z));
Paddlenode2->attachObject(groundEntity3);
groundEntity3->setCastShadows(false);
}
and this is for attempting to make multiple objects in random space这是为了尝试在随机空间中制作多个对象
point plat[20];
float pX;
float pY;
for (int i = 0; i < 10; i++)
{
plat[i].x = rand() % 50;
plat[i].y = rand() % 30;
float pX = plat[i].x;
float pY = plat[i].y;
}
for (int i = 0; i < 10; i++)
{
PlatformManager Panels = new PlatformManager->CreatePanelDoodle(pX, 0, pY);
}
The problem is with the error in the for loop creation "No suitable constructor exists to convert void to "platform manager"问题在于 for 循环创建中的错误“不存在合适的构造函数将 void 转换为“平台管理器”
I've tried simply adding the constructor into the for loop, and not using the loop at all.我试过简单地将构造函数添加到 for 循环中,而根本不使用循环。 Whats going wrong?
怎么了?
There are some problems in your second code snippet:您的第二个代码片段中存在一些问题:
float pX;
float pX;
and float pY;
float pY;
float pX = plat[i].x;
float pX = plat[i].x;
遮蔽变量float pX = plat[i].x;
and float pY = plat[i].y;
float pY = plat[i].y;
new
operator on a void functionnew
运算符应用于 void 函数You can solve the problems with您可以通过以下方式解决问题
// Remove this block, you don't use the variables
/*
point plat[20]; // You don't use this array
float pX; // You use it uninitialized
float pY; // You use it uninitialized
for (int i = 0; i < 10; i++) {
plat[i].x = rand() % 50;
plat[i].y = rand() % 30;
float pX = plat[i].x; // You don't use this variable
float pY = plat[i].y; // You don't use this variable
}
*/
for (int i = 0; i < 10; ++i) {
PlatformManager->CreatePanelDoodle(static_cast<float>(rand() % 50), 0, static_cast<float>(rand() % 30));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.