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.

DarkBASIC Professional Discussion / Rotating A Square On Its X or Y Axis

Author
Message
Dark Java Dude 64
Community Leader
15
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 16th Jan 2011 06:34 Edited at: 17th Jan 2011 21:38
hey guys, i posted something in the 3d chat section related to this, but i havent been getting replies as fast as i expected Either way, how would you make a 2d square look like it's flipping over? What math would you use to get the four coordinates that lines connect to make a square flip over? I want something that is 2d that uses math to replicate this:



print "Thanks!!"

The only reason people get lost in thought is because it's unfamiliar territory.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Jan 2011 08:03 Edited at: 16th Jan 2011 08:12
Do you mean in 2D or 3D?

In 3D you can just create a plain object like this:



Malevolence: The Sword of Ahkranox
The infinite RPG
http://www.msoa-game.com
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Jan 2011 08:11 Edited at: 16th Jan 2011 08:15
Alternatively, if you are drawing a square in 2D and you want to rotate it, you will need to use trigonometry to map the 4 corners of the square to co-ordinates on the edge of a circle in the memory space, like so:



With this, you will know the Theta angle and hypotenuse length of each of the triangles that lead to each of the square corners. You can then use the LINE command to draw lines connecting the 4 corners to simulate the square.

After that, it's simply a matter of increasing or decreasing the theta angles for each triangle to turn the square left or right.


However, it'd be much easier to just use sprites and use the ROTATE SPRITE command...

Malevolence: The Sword of Ahkranox
The infinite RPG
http://www.msoa-game.com
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jan 2011 17:07
Or

xrotate object objNum, object angle x(objNum)+angleStep#

and

yrotate object objNum, object angle y(objNum)+angleStep#
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 16th Jan 2011 17:49 Edited at: 16th Jan 2011 18:01
Yep, Green Gandalf has hit it on the head. Simple matter of rotating whatever object you have along the appropriate axis. As long as the pivot point is in the center of course, which it generally is, unless you have made in a 3D app and have changed it for some reason.

Edit - I noticed your marble game says it may not reach completion, that is a pity. Is this problem related? I have been having a bad couple of weeks with my marble game also, due to physics related problems. Just about sorted the problem this morning at around 3am or so lol. it can be disheartening programming sometimes. I have had to work quite hard over the last few weeks trying different things and eventually dumping a lot of old code and rewriting it never good, but it was needed, and actually only took me about an hour in the end to rewrite the troublesome section. So worth the trouble. Once I am happy with the engine again I will add back in the couple of things that are still missing (just a few graphics I need to put back in).

If this is your first game, a marble madness style game may be a little hard for a beginner. I would not have tried one myself if I wasn't using it as a learning experinece for dark physics. Trying to fake physics manually would not be the easiest job in the world, apart from standard gravity which is fairly simple in comparison.

Hope you get round your current problem and continue.

http://s6.bitefight.org/c.php?uid=103081
Dark Java Dude 64
Community Leader
15
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 16th Jan 2011 18:54 Edited at: 16th Jan 2011 18:59
The first reply was kinda what i wanted, i should have said i wanted a 2d square In other words, how would i make the square look like flipping it over? Perspective would be involved, if that makes it more clear


@Dvader

Yah, it is kinda sad... See what happened is i thought a couple weeks ago i wanted to learn C++ after MC was finished, but all the sudden, i couldn't stop looking at the cpp tutorials. Then, all of the sudden, i realized that MC didnt look fun to dev anymore, at all. I havent even looked at the code in a couple weeks Weeell that's a sad excuse eh? Buuuuut that's what happened.... If you'd be willing to continue deving it id be glad to let you... This would be my first 3d game, i made a pretty sweet 2d game a while back in a beginner's language called Phrogram, it's a very nice language, just lacking 3d stuff and distribution features. Wow i just realized ive been programming for over a year



DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 17th Jan 2011 14:29
I see, you left your project for awhile, then on returning decided you didn't fancy it. I'm sure most people have done that before, it is easy to lose interest if you put too big a gap between programming sessions.

As to the flipping question, still not sure what you mean apart from using the rotate command, whether using a plain cube or anything really.

http://s6.bitefight.org/c.php?uid=103081
Dark Java Dude 64
Community Leader
15
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 17th Jan 2011 18:45 Edited at: 17th Jan 2011 18:50
Yeh, that's what happened, lol... Well ive always wondered: to get something done are you supposed to work hard on it until it's done or take breaks and work on other projects? The latter is what i originally thought, but it seems like the former is the way to go.

I think im getting the thing figured out by myself, but i dont mean anything 3d. I mean just lines, all 2d. kinda like if you flipped a piece of paper over Thanks for trying to help though!

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 17th Jan 2011 21:31
Ohhh. In 2D! That could get a little more complicated. Off the top of my head possibly scale the sprite on the y axis for horizontal, or x for vertical. Then change the sprite image between the flip point for the other side. Theres probably a better way, but apart from creating an animation, I couldn't say.

http://s6.bitefight.org/c.php?uid=103081
Dark Java Dude 64
Community Leader
15
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 17th Jan 2011 21:37
I see

The only reason people get lost in thought is because it's unfamiliar territory.

Login to post a reply

Server time is: 2026-07-18 02:09:10
Your offset time is: 2026-07-18 02:09:10