Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / A few errors with my cube-creating code.

Author
Message
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Nov 2010 01:25 Edited at: 16th Nov 2010 01:26
Well this program is trying to create a cube where the mouse is, but I want it to not create it if there is another cube right where that one is, and right now there is a few problems:
1) When a cube is created it is not created right where the mouse is
2) I don't know how to center the mouse in the middle of the screen
3) I was trying to use "<>" to say if it is not equal too, and that doesn't work



Always program as if the person maintaining your program is a psychopath that knows where you live
_Pauli_
AGK Developer
14
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 16th Nov 2010 02:43 Edited at: 16th Nov 2010 02:43
1) You have to position the cube with 3D world coordinates, but you are using dbMouseX() and dbMouseY(), which just return the 2D mouse coordinates on the screen.

2) You can try:

This will position the mouse cursor at the center of the screen.

3) The C++ expression for not equal is !=. Example:


Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 16th Nov 2010 02:43
That's not going to work, you need to use the PickScreen commands in order to get the 3d coordinates of the mouse, the Mouse coordinates just give you the screen coordinates basically. you can use this function I use in pretty much every program, it's not perfect but it works.

CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Nov 2010 02:54 Edited at: 16th Nov 2010 02:59
I tried this (Im leaving the no creating a cube where another one is out of it) but I get a undeclared variable error and the mouse does not stay at the center of the screen.
mm3dX=xHit;
mm3dZ=zHit;
mm3dY=yHit;.



EDIT: tried this and it runs, but it's really glitchy


Always program as if the person maintaining your program is a psychopath that knows where you live
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 16th Nov 2010 04:11 Edited at: 16th Nov 2010 04:14
Try this, there are some modifications you have to make in order to get it to work, and you wanna position the cube at mm3dx not mousex
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 16th Nov 2010 07:21 Edited at: 16th Nov 2010 07:22
I had to do this to get rid of 3 errors, and I still have one in this line:



my code:


Always program as if the person maintaining your program is a psychopath that knows where you live
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 16th Nov 2010 07:39
Sorry its not working as easy as I think it should. For one, put the function at the top of the program and it should work

#include "DarkGDK.h"
#include "DarkPhysics.h"
#include "DarkAI.h"
#include "DarkLights.h"
#include "ShaderData.h"

#pragma comment ( lib, "DarkPhysics.lib" )
#pragma comment ( lib, "DarkAI.lib" )
#pragma comment ( lib, "DarkLights.lib" )
#pragma comment ( lib, "ShaderData.lib" )
float mm3dX ;
float mm3dY ;
float mm3dZ ;
void mouseConvert()
{

double pickVector =0;
float xHit =0;
float zHit=0;
float yHit=0;
dbPickScreen ( dbMouseX(), dbMouseY(),dbCameraPositionY() ) ;
xHit = dbGetPickVectorX() + dbCameraPositionX();
zHit = dbGetPickVectorZ() + dbCameraPositionZ();
yHit = dbGetPickVectorY() + dbCameraPositionY();
mm3dX=xHit;
mm3dZ=zHit;
mm3dY=yHit;
}


void DarkGDK ( void ) {


dbSyncOn();
dbSyncRate(60);
int x = 1;


//Loop
while( LoopGDK ( ) ) {
mouseConvert();
int mousex = dbMouseX();
int mousez = dbMouseZ();
int mousey = dbMouseY();
if (dbKeyState(57) == 1)
dbPositionMouse( dbScreenWidth() / 2, dbScreenHeight() / 2 );
{
dbMakeObjectCube(x,20);
dbPositionObject(mm3dX,mm3dY,mm3dZ,0);
}
dbPositionCamera(0,mousex,mousey,mousez-100);
dbText(0,0,dbStr(int(x)));


dbSync();
}
}
Red Eye
15
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 17th Nov 2010 15:25
Hey,

As far as I know, you need to get the 3d vectors of your mouse position, and then create a cube there, you could check if there would be collision there where the last cube is placed, then it wouldnt create there the cube. But it would in another place where collision is 0.

Greets,

Red Eye

Login to post a reply

Server time is: 2024-06-30 10:47:12
Your offset time is: 2024-06-30 10:47:12