Quote: "And this is the lines I have problem with and the error messages:"
C does not have "strings" like AppGameKit does, instead it uses arrays of characters. However in C++ this is "fixed" by making a class called "string."
I have just taken a few minutes and converted the 3D example to C++. I did this using the method shown in Lee's video of taking the BASIC code and converting it line by line (which I usually wouldn't do). As I said above things like global variables should be avoided in C++ and in C++ there are better ways to do things. However to not confuse anyone I have kept it the way Lee is teaching in his videos.
You can see how I handled the C-String to std::string situation in the loadworld() function:
// Includes
#include "template.h"
#include <string>
// Namespace
using namespace AGK;
app App;
float startx = 0.0f, starty = 0.0f, angx = 0.0f, angy = 0.0f;
void loadworld(void);
void app::Begin(void)
{
//Init app
agk::SetSyncRate(60, 0);
agk::SetClearColor(128, 64, 0);
agk::SetCameraRange(1, 15, 1000);
agk::SetScissor(0, 0, 0, 0);
//Loading status
unsigned int customimg = agk::LoadImage("media/custom.png");
agk::CreateText(1, "Loading Metro Theatre Scene");
agk::SetTextFontImage(1, customimg);
agk::SetTextAlignment(1, 1);
agk::SetTextPosition(1, 50, 45);
agk::SetTextSize(1, 10);
agk::CreateText(2, "Artwork by Mark Blosser");
agk::SetTextFontImage(2, customimg);
agk::SetTextAlignment(2, 1);
agk::SetTextPosition(2, 50, 60);
agk::SetTextSize(1, 8);
agk::Sync();
loadworld();
//rem Setup camera
float plrx = 1850, plrz = -3650, plra = 0, eyeheight = 553;
agk::SetCameraPosition(1, plrx, eyeheight, plrz);
agk::SetCameraRotation(1, 0, plra, 0);
agk::CreatePointLight(1, plrx, eyeheight, plrz, 600, 255, 255, 255);
agk::SetPointLightMode(1, 1);
agk::CreateObjectSphere(99, 10, 10, 10);
agk::SetObjectLightMode(99, 0);
agk::SetSunActive(0);
agk::SetAmbientColor(50, 50, 50);
//rem Start loop
agk::DeleteText(1);
agk::DeleteText(2);
agk::SetRawJoystickDeadZone(0.1f);
agk::AddVirtualButton(1, 94.7f, 93.1f, 9.77f);
agk::AddVirtualButton(2, 94.7f, 79.4f, 9.77f);
}
void app::Loop (void)
{
//rem Old position
float oldx = agk::GetCameraX(1);
float oldy = agk::GetCameraY(1) - 45.0;
float oldz = agk::GetCameraZ(1);
//rem Move camera
if (agk::GetRawKeyState(87)) agk::MoveCameraLocalZ(1, 4);
if (agk::GetRawKeyState(83)) agk::MoveCameraLocalZ(1, -4);
if (agk::GetRawKeyState(65)) agk::MoveCameraLocalX(1, -4);
if (agk::GetRawKeyState(68)) agk::MoveCameraLocalX(1, 4);
if (agk::GetVirtualButtonState(1)) agk::MoveCameraLocalZ(1, -4);
if (agk::GetVirtualButtonState(2)) agk::MoveCameraLocalZ(1, 4);
if (agk::GetPointerPressed())
{
startx = agk::GetPointerX();
starty = agk::GetPointerY();
angx = agk::GetCameraAngleX(1);
angy = agk::GetCameraAngleY(1);
}
if (agk::GetPointerState())
{
float fDiffX = (agk::GetPointerX() - startx) / 1.0;
float fDiffY = (agk::GetPointerY() - starty) / 1.0;
float newX = angx + fDiffY;
if (newX > 89) newX = 89;
if (newX < -89) newX = -89;
agk::SetCameraRotation(1, newX, angy + fDiffX, 0);
}
if (agk::GetRawJoystickExists(1))
{
agk::MoveCameraLocalZ(1, -agk::GetRawJoystickY(1) *4);
agk::MoveCameraLocalX(1, agk::GetRawJoystickX(1) *4);
agk::RotateCameraGlobalY(1, agk::GetRawJoystickRX(1) *4);
agk::RotateCameraLocalX(1, agk::GetRawJoystickRY(1) *4);
}
//rem Gravity on camera
agk::SetCameraPosition(1, agk::GetCameraX(1), agk::GetCameraY(1) - 4, agk::GetCameraZ(1));
//rem New position
float newx = agk::GetCameraX(1);
float newy = agk::GetCameraY(1) - 45;
float newz = agk::GetCameraZ(1);
//rem Adjust Y to match floor
if (agk::ObjectSphereSlide(0, oldx, oldy, oldz, newx, newy, newz, 19.0) > 0)
{
newx = agk::GetObjectRayCastSlideX(0);
newy = agk::GetObjectRayCastSlideY(0);
newz = agk::GetObjectRayCastSlideZ(0);
agk::SetCameraPosition(1, newx, newy + 45.0, newz);
}
float posx = agk::Sin(agk::Timer() * 40) * 250 + 2000;
agk::SetPointLightPosition(1, posx, 565, -3600);
agk::SetObjectPosition(99, posx, 565, -3600);
//rem Framerate prompt
agk::Print("W A S D or joystick to move, click and drag to rotate");
float fps = agk::ScreenFPS();
char *cStr = agk::Str(fps);
std::string fpsStr = cStr;
delete[] cStr;
agk::Print(("FPS: " + fpsStr).c_str());
agk::Sync();
}
void app::End (void)
{
}
void loadworld(void)
{
//variables
std::string tex;
int objmax;
std::string mesh;
std::string texname;
std::string lmStr;
int teximg;
// Load lightmaps
int lm[10];
lm[0] = agk::LoadImage("/media/0.png");
lm[1] = agk::LoadImage("/media/1.png");
for (int t = 0; t <= 1; t++)
{
agk::SetImageWrapU(lm[t], 1);
agk::SetImageWrapV(lm[t], 1);
}
// Load all OBJ making up world(created in FPS Creator)
objmax = 50;
for (int obj = 1; obj <= objmax; obj++)
{
//Convert to character array
char *cStr = agk::Str(obj);
std::string objNum = cStr; //Convert character array to string
delete[] cStr; //Delete character array
mesh = "media/mesh" + objNum + ".obj";
agk::LoadObject(obj, mesh.c_str(), 0);
if (obj >= 1 && obj <= 7)
{
tex = "media/mesh" + objNum + "-1.jpg";
}
else
{
tex = "media/mesh" + objNum + "-0.jpg";
}
texname = tex.substr(0, tex.length() - 4);
lmStr = texname[texname.length() - 1];
if (lmStr == "-") { lmStr = "0"; }
teximg = agk::LoadImage(tex.c_str());
agk::SetImageWrapU(teximg, 1);
agk::SetImageWrapV(teximg, 1);
agk::SetObjectImage(obj, teximg, 0);
agk::SetObjectLightMap(obj, lm[atoi(lmStr.c_str())]);
// Progress status
float perc = (float)obj;
perc = perc / objmax;
perc = perc * 100;
cStr = agk::Str((int)perc);
objNum = cStr;
agk::SetTextString(1, ("Metro Theatre - " + objNum + "%").c_str());
delete[] cStr;
agk::Sync();
}
return;
}
Quote: "The agk staff is easy, most of the things works exactly the same as in Tier 1, the problem I have is mostly C++ related."
If you (or others) want I can make a Tier 2 C++ help thread for anyone trying to jump from Tier 1 to Tier 2 to ask C++ related questions (that might not need their own thread).
Wilf wrote: "I'm wondering how much faster Tier 2 is than Tier 1"
DavidAGK wrote: "I'm also keen to hear what the performance difference is between T1 and T2. Anyone able to offer some comparison? Is it 10% faster in T2 or 50% or double the speed? That would be the main reason I'd get into C++"
C++ is likely quite a bit faster than you might think. Here's a good article that shows the speed differences between languages, while AppGameKit isn't one of the languages tested it is still gives you a good idea of how much faster native code (C++) usually is than an interpreted language (like AGK).
Here's an image from the article look at GCC:C and compare it to anything that has its time in black (like Perl, Python, R, Lua, etc):
I'll write a benchmark for AppGameKit vs C++ and post the results here sometime soon.
Sean