我想在OpenGL中製作遊戲並想移動相機。我已經通過使用此代碼完成:刪除過多的代碼
t.calculations(&t1, 5.54, 1.54, 10, 10, 1);
t.calculations(&t2, 5.54, 1.54, 10, 10, 1);
t.calculations(&t3, 5.54, 1.54, 10, 10, 1);
t.calculations(&t4, 5.54, 1.54, 10, 10, 1);
t.calculations(&t5, 5.54, 1.54, 10, 10, 1);
t.calculations(&t6, 5.54, 1.54, 10, 10, 1);
t.calculations(&t7, 5.54, 1.54, 10, 10, 1);
t.calculations(&t8, 5.54, 1.54, 10, 10, 1);
t.calculations(&t9, 5.54, 1.54, 10, 10, 1);
t.calculations(&t10, 5.54, 1.54, 10, 10 ,1);
t.calculations(&t11, 5.54, 1.54, 10, 10, 1);
t.calculations(&t12, 5.54, 1.54, 10, 10, 1);
t.calculations(&t13, 5.54, 1.54, 10, 10, 1);
t.calculations(&t14, 5.54, 1.54, 10, 10, 1);
t.calculations(&t15, 5.54, 1.54, 10, 10, 1);
t.calculations(&t16, 5.54, 1.54, 10, 10, 1);
t.calculations(&t17, 5.54, 1.54, 10, 10, 1);
t.calculations(&t18, 5.54, 1.54, 10, 10, 1);
但正如您所看到的,這看起來像是代碼的重複過多。我試圖用下面的方法代替上面的方法:
for (int i = 1; i < 19; i++) {
t.calculations(&t+i, 5.54, 1.54, 10, 10, 1);
}
但它不工作。任何人都可以告訴我一個替代方案嗎
你有18不同的變量名'T1 .. t18'?那麼什麼是't'?任何爲什麼'tN'不是數組/矢量? – delnan
我不知道如何在這種情況下使用數組:/和不太熟悉向量或... – Rizwan606