Crystal Space
Welcome, Guest. Please login or register.
December 19, 2014, 04:08:27 pm

Login with username, password and session length
Search:     Advanced search
9032 Posts in 2046 Topics by 9292 Members
Latest Member: Agaqkopa
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  General Crystal Space Discussion
| | |-+  Orientation vector
« previous next »
Pages: [1] Print
Author Topic: Orientation vector  (Read 4752 times)
koocake
Jr. Member
**
Posts: 54


View Profile
« on: April 28, 2006, 11:46:59 pm »

Hi there,

I want to know how I can get the vector which points in the direction that an object is pointing, so that
I can apply a force in that direction.

I have tried :
car->GetTransform()*CS_VEC_FORWARD;

and
car->GetOrientation()*CS_VEC_FORWARD;

and
car->GetTransform().Other2This(CS_VEC_FORWARD);

but none of these seem to work, the force seems to be applied along the world axes, not in the direction that the car faces!

can you help?

regards, Kate Mallichan
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #1 on: April 30, 2006, 09:30:17 pm »

Hi there,

I want to know how I can get the vector which points in the direction that an object is pointing, so that
I can apply a force in that direction.

I have tried :
car->GetTransform()*CS_VEC_FORWARD;

and
car->GetOrientation()*CS_VEC_FORWARD;

and
car->GetTransform().Other2This(CS_VEC_FORWARD);

but none of these seem to work, the force seems to be applied along the world axes, not in the direction that the car faces!

can you help?

regards, Kate Mallichan

I need to see a bit more code. How exactly are you using that vector?

Greetings,
Logged
koocake
Jr. Member
**
Posts: 54


View Profile
« Reply #2 on: May 01, 2006, 01:12:34 pm »

I am applying the force as follows:

car->AddForce(vector*force);

I have also tried car->AddRelForce(vector*force);

but the car either moves in funny directions, or towards the axes.

regards, Kate
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: May 01, 2006, 03:26:55 pm »

The functions AddForce() is in world space and AddRelForce() is in local space. So AddRelForce() should work. What do you mean by 'funny' directions? Also perhaps show me the exact code you're using.

Greetings,
Logged
koocake
Jr. Member
**
Posts: 54


View Profile
« Reply #4 on: May 01, 2006, 03:40:48 pm »

I am using the following code:

    car->AddRelForce(CS_VEC_FORWARD*acceleration_force);
    car->Update();

The problem is that the force seems to be applied along the nearest world axis, so that the car veers towards the axes
when it is supposed to be moving forwards in the direction is is pointing. I think I may have to do something with car->GetOrientation() but I am not sure what. I would appreciate any help you can give as this is becoming an urgent situation with a project deadline coming up!

thankyou for your help,

Kate Mallichan
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #5 on: May 01, 2006, 08:14:21 pm »

How is the force vector calculated? I don't have sufficient information to really know what is going on here.

Greetings,
Logged
koocake
Jr. Member
**
Posts: 54


View Profile
« Reply #6 on: May 01, 2006, 08:25:52 pm »

the force is simply an int value, not a vector. is this where i am going wrong?
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #7 on: May 01, 2006, 09:01:13 pm »

the force is simply an int value, not a vector. is this where i am going wrong?

Hmm... Perhaps you should at least make it a float. An int sounds a bit weird. Otherwise I have no clue without seeing more code.

Greetings,
Logged
Lak Moore
Guest


Email
« Reply #8 on: May 17, 2006, 07:41:53 pm »

Is this what you are after?

Code:

    csVector3 currPos;
    float yRot;
    iSector* sector;
   
    csRef<iPcLinearMovement> lm = celQueryPropertyClassEntity<iPcLinearMovement> (entity);

    lm->GetLastPosition(current, yRot, sector);
    csVector3 delta(0);

    theta = yRot + PI;
    cosTH = cos(theta);
    sinTH = sin(theta);
    //rotate delta by yRot
    delta.x = cosTH + sinTH;
    delta.z = -sinTH + cosTH;
    delta = delta.Unit() * FORCE   //FORCE is your force and it can be an int if you want

Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.182 seconds with 16 queries.