Jump to content

Recommended Posts

Posted

I have been following the tutorials with no problem so far but on this raycasting tutorial I just cant see where I am going wrong. I have followed the tutorial exactly and its not quite working. Here is the code I have and after the code I'll explain whats going on.

#include "App.h"
using namespace Leadwerks;
App::App() : window(NULL), context(NULL), world(NULL), camera(NULL) {}
App::~App() { delete world; delete window; }
Model* box1;
Model* box2;
Model* box3;
Vec3 leftPoint;
Vec3 rightPoint;
PickInfo pickInfo;
bool App::Start()
{
//Create a window
window = Leadwerks::Window::Create("Raycasting", 100, 100, 1024, 768, Window::Titlebar);

//Create a context
context = Context::Create(window);

//Create a world
world = World::Create();

//Create a camera
camera = Camera::Create();
camera->Move(0,1,-5);
//Light
Light* light = DirectionalLight::Create();
light->SetRotation(45, 45, 45);
//Create Boxes
box1 = Model::Box();
box1->SetColor(1.0, 0.0, 0.0);
box1->SetPosition(-2, 2, 0);
box2 = Model::Box();
box2->SetColor(0.0, 1.0, 0.0);
box2->SetPosition(0, 2, 0);
box3 = Model::Box();
box3->SetColor(0.0, 0.0, 1.0);
box3->SetPosition(2, 2, 0);

//set points
leftPoint = Vec3(-4, -2, 0);
rightPoint = Vec3(4, -2, 0);
return true;
}
bool App::Loop()
{
//Close the window to end the program
if (window->Closed() || window->KeyHit(Key::Escape)) return false;
//Box movement
float move1 = (window->KeyDown(Key::Q) - window->KeyDown(Key::A)) * Time::GetSpeed() * 0.05;
float move2 = (window->KeyDown(Key::W) - window->KeyDown(Key::S)) * Time::GetSpeed() * 0.05;
float move3 = (window->KeyDown(Key::E) - window->KeyDown(Key:)) * Time::GetSpeed() * 0.05;
box1->Translate(0, move1, 0);
box2->Translate(0, move2, 0);
box3->Translate(0, move3, 0);
//Pick info
bool visible = true;
if (world->P(leftPoint, rightPoint, pickInfo, 0.0));
{
visible = false;
}
Leadwerks::Time::Update();
world->Update();
world->Render();
//Draw Line
Vec3 p1 = camera->Project(leftPoint);
Vec3 p2 = camera->Project(rightPoint);
context->DrawLine(p1.x, p1.y, p2.x, p2.y);
if (visible)
context->SetColor(0, 1, 0);
else
context->SetColor(1, 0, 0);
//Draw text
context->SetBlendMode(Blend::Alpha);
context->DrawText("Q-A to move Red Box", 0, 0);
context->DrawText("W-S to move Greed Box", 0, 15);
context->DrawText("E-D to move Blue Box", 0, 30);
context->DrawText("Visible " + String(visible), 0, 45);
context->SetBlendMode(Blend::Solid);
context->Sync(false);

return true;
}

 

So I have all the boxes on the screen, the text in the top right, and the line where the pick should be. the problem is that the line

if (world->Pick(leftPoint, rightPoint, pickInfo, 0.0));

is always returning true which makes visible false no matter what. I have no idea why this is happening. Any help would be greatly appreciated. I also added some screenshots to help.

 

HAHA!! I am sorry. Making that post helped me pin point the issue tongue.png Just stupid syntax thing. I added a semicolon after the if statement which I kept glancing over. Problem solved!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...