Jump to content

Linepick point2


ParaToxic
 Share

Recommended Posts

Hello,i try to make a bullet class with Raycasting.I made a point1 at the player position and point2 like:

point2=Vec3(0,0,30);
point2=TFormVector(point2,cam,NULL);

LinePick(&pick,point1,point2);

 

this,but when i check the values of point2,its wrong.

How can i solve this problem?

 

Thank you

Link to comment
Share on other sites

So i have a little example.Maybe somebody can told me why it is wrong.

 

#include "engine.h"
int main(int argc, char** argv)
{
Initialize();

Graphics(800,600);

TCamera cam=CreateCamera();
PositionEntity(cam,Vec3(0,2,-10));
Collisions(1,2,true);

TModel scene=LoadModel("scene.gmf");

EntityType(scene,2);

TLight light=CreatePointLight();
PositionEntity(light,Vec3(0,5,0));

TBuffer buffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

TController player=CreateController();
SetBodyMass(player,6);
EntityType(player,1);



TVec3 point1=Vec3(0,0,0);
TVec3 point2=Vec3(0,0,0);
TVec3 a=Vec3(0,0,0);
TVec3 b=Vec3(0,0,0);
TPick pick;


float move=0.0;
float strafe=0.0;
TVec3 camrotation=Vec3(0);
float mx=0;
float my=0;
HideMouse();
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

while(!KeyHit(KEY_ESCAPE)) {

mx=Curve(MouseX()-GraphicsWidth()/2,mx,6);
my=Curve(MouseY()-GraphicsHeight()/2,my,6);
MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);
camrotation.X=camrotation.X+my/10.0;
camrotation.Y=camrotation.Y-mx/10.0;
RotateEntity(cam,camrotation);

move=KeyDown(KEY_W)-KeyDown(KEY_S);
strafe=KeyDown(KEY_D)-KeyDown(KEY_A);

UpdateController(player,camrotation.Y,move,strafe);

UpdateWorld();

TVec3 playerpos=EntityPosition(player);
TVec3 camerapos=EntityPosition(cam);
camerapos.Y=Curve(playerpos.Y+1.75,camerapos.Y,2.0);
camerapos=Vec3(playerpos.X,camerapos.Y,playerpos.Z);
PositionEntity(cam,camerapos);


point1=EntityPosition(cam);
point2=Vec3(0,0,4);
point2=TFormVector(point2,cam,0);

if(LinePick(&pick,point1,point2,0,0))
{
        a=CameraUnproject(cam,point1);
        b=CameraUnproject(cam,Vec3(pick.X,pick.Y,pick.Z));
}


SetBuffer(buffer);
RenderWorld();
SetBuffer(BackBuffer());
RenderLights(buffer);

DrawLine(a.X,a.Y,b.X,a.Y);
Flip();
}
return Terminate();
}

 

Thank you for advanced

Link to comment
Share on other sites

As far as I know you don't need to be transforming that vector into camera space. It is technically already in camera space.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...