Crystal Space
Welcome, Guest. Please login or register.
October 22, 2014, 09:37:42 am

Login with username, password and session length
Search:     Advanced search
9010 Posts in 2044 Topics by 8789 Members
Latest Member: Craigowens
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Rotate and scale
« previous next »
Pages: [1] Print
Author Topic: Rotate and scale  (Read 4044 times)
RS
Newbie
*
Posts: 12


View Profile
« on: August 17, 2005, 08:54:00 pm »

Hello!

I have some problem with CrystalSpace coding...

I have 2 balls (B1 and B2), located at position P1 and P2.
I have a mesh, created with             
<box>
     <min x="-0.02" y="-0.3" z="-0.02" />
     <max x="0.02" y="0" z="0.02" />
</box>

and named Rod.

I would like to put the Rod between the two balls, then rotateit into the right position (between the two balls) and maybe scale it.

Right now I put the Rod into the right position with:

csVector3 P1 = B1->GetMovable()->GetPosition();
csVector3 P2 = B2->GetMovable()->GetPosition();

Rod->GetMovable()->SetPosition(P1);   /* or P1 + ((P2 - P1) / 2 ) or something */

and it is working properly, but i dont know how can i rotate the Rod into the right angle.

Tried:

Rod->GetMovable()->GetTransform().LookAt(...);
Transform(...);

but this is too mystic for me, maybe my math skills not high enough. wink

Anyway, is here anybody, who would be so kind to help  me and answer ?
(maybe with a code snippet ? B-) )

Thank You
--
RS

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


View Profile
« Reply #1 on: August 17, 2005, 09:00:13 pm »

I can only answer your question if you tell me exactly where you want your object to look.

Greetings,
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #2 on: August 17, 2005, 09:10:08 pm »

How can i say... I would like the box longest axis will be parallel with the line defined by P1 and P2... somehow between P1 and P2, u know. B-)

                 P1
                /
              /  Rod
            /
          /
     P2

Sorry about my english.
--
RS
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #3 on: August 17, 2005, 09:19:57 pm »

Try this code. That will make the rod orient towards P2:

Code:
csVector3 P1 = ...;
csVector3 P2 = ...;
Rod->GetMovable()->SetPosition(P1);   /* or P1 + ((P2 - P1) / 2 ) or something */
Rod->GetMovable()->GetTransform().LookAt(P2-Rod->GetMovable ()->GetPosition (), csVector3 (0, 1, 0));
Rod->GetMovable()->UpdateMove();

Greetings,
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #4 on: August 17, 2005, 09:32:08 pm »


I tried it (as i tried it before), but is doesnt worked.

The result:
http://ratskin.nomaam.hu/CS/Screenshot.png

The Rod is followed the P2 (this is a dynamic movement), but not the right angle.

(The other rod in the bottom of the window doesnt matter.)

I really dont understand it...

Thanks
--
RS
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #5 on: August 17, 2005, 09:35:41 pm »


I tried it (as i tried it before), but is doesnt worked.

The result:
http://ratskin.nomaam.hu/CS/Screenshot.png

The Rod is followed the P2 (this is a dynamic movement), but not the right angle.

(The other rod in the bottom of the window doesnt matter.)

I really dont understand it...

Thanks
--
RS

Can I see the full code that does the movement and following?

Greetings,
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #6 on: August 17, 2005, 09:37:21 pm »


I tried it (as i tried it before), but is doesnt worked.

The result:
http://ratskin.nomaam.hu/CS/Screenshot.png

The Rod is followed the P2 (this is a dynamic movement), but not the right angle.

(The other rod in the bottom of the window doesnt matter.)

I really dont understand it...

Thanks
--
RS

Can you repost that screenshot as a jpg? It loads too slow.

Greetings,
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #7 on: August 17, 2005, 09:44:28 pm »

The current code (sorry about the differing names, P1 == Konyok   P2 == Csuklo  Rod == Alkar):

void Simple::moveKonyok(int x,y,z) {
      csVector3 mWPos = Konyok->GetMovable()->GetPosition();
      mWPos.x = x / COORD_DIV_VALUE;
      mWPos.y = y / COORD_DIV_VALUE;
      mWPos.z = z / COORD_DIV_VALUE;
      Konyok->GetMovable()->SetPosition(mWPos);
      Konyok->GetMovable()->UpdateMove();
}
void Simple::moveCsuklo(int x, int y, int z) {
      csVector3 mWPos = Csuklo->GetMovable()->GetPosition();
      mWPos.x = x / COORD_DIV_VALUE;
      mWPos.y = y / COORD_DIV_VALUE;
      mWPos.z = z / COORD_DIV_VALUE;
      Csuklo->GetMovable()->SetPosition(mWPos);
      Csuklo->GetMovable()->UpdateMove();
}

void Simple::moveAlkar() {
      csVector3 kp = Konyok->GetMovable()->GetPosition();
      csVector3 csp = Csuklo->GetMovable()->GetPosition();
//      csVector3 akp = kp + ((csp - kp) / 2) ;

      Alkar->GetMovable()->SetPosition(kp);
      Alkar->GetMovable()->GetTransform().LookAt(csp- Alkar->GetMovable ()->GetPosition (), csVector3 (0, 1, 0));
      Alkar->GetMovable()->UpdateMove();
}
...
ifkbd->GetKeyState(CSKEY_PAD3)) {

  MoveKonyok(kX,kY,kZ);
  MoveCsuklo(csX,csY,csZ);
  moveAlkar();

}


Regards
--
RS
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #8 on: August 17, 2005, 09:47:38 pm »



The smaller shot:

http://ratskin.nomaam.hu/CS/Screenshot.jpg

Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #9 on: August 17, 2005, 10:23:13 pm »


New picture, maybe better.
http://ratskin.nomaam.hu/CS/Screenshot-1.jpg

As far as i see it is 90 degres difference, but i really dont understand this situation.

--
RS
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #10 on: August 17, 2005, 11:34:47 pm »


Ok, the rotate problem solved.

If i use
<box>
    <min x="-0.00" y="-0.0" z="-0.0" />
    <max x="0.02" y="0.02" z="0.5" />
</box>

instead of
<box>
     <min x="-0.02" y="-0.3" z="-0.02" />
     <max x="0.02" y="0" z="0.02" />
</box>

for Rod definition then everything is working properly.

Last question:
How can i scale the Rod (or Alkar) length ?

Thanks
--
RS
Logged
jorrit
Administrator
Hero Member
*****
Posts: 1706


View Profile
« Reply #11 on: August 18, 2005, 07:14:52 am »


Ok, the rotate problem solved.

If i use
<box>
    <min x="-0.00" y="-0.0" z="-0.0" />
    <max x="0.02" y="0.02" z="0.5" />
</box>

instead of
<box>
     <min x="-0.02" y="-0.3" z="-0.02" />
     <max x="0.02" y="0" z="0.02" />
</box>

for Rod definition then everything is working properly.

Last question:
How can i scale the Rod (or Alkar) length ?

Thanks
--
RS

What exactly do you want to do? Do you want to scale it all the time with different dimensions or just once? In the last case you should scale the model itself using HardTransform (or <hardmove> in the model file). The first case is unfortunatelly not supported in CS. At least not easily.

Greetings,
Logged
RS
Newbie
*
Posts: 12


View Profile
« Reply #12 on: August 18, 2005, 10:07:46 am »


First case... B-/

Thank you very much for your time and Crystal Space too! B-)
--
RS
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 7.216 seconds with 15 queries.